Skip to content

Commit

Permalink
fix(lint): codestyle corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksnell committed May 6, 2022
1 parent d422925 commit ac6a52e
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions tests/test_router.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import re
from unittest.mock import patch, MagicMock
from unittest.mock import MagicMock, patch

import pytest

from banquet.handler import BanquetHandler
from banquet.router import BanquetRouter


@pytest.fixture
def simple_open_api_spec():
return {
Expand All @@ -17,6 +19,7 @@ def simple_open_api_spec():
}
}


@pytest.fixture
def dynamic_open_api_spec():
return {
Expand All @@ -28,49 +31,47 @@ def dynamic_open_api_spec():
}
}


@pytest.fixture
def function_dir():
return "functions/"
return "functions/"


@pytest.fixture
def routes():
return {
"GET": {
"/example": {
"handler": "get-handler"
}
},
"POST": {
re.compile("^/example/(?P<id>.+?)$"): {
"handler": "post-handler"
}
},
"GET": {"/example": {"handler": "get-handler"}},
"POST": {re.compile("^/example/(?P<id>.+?)$"): {"handler": "post-handler"}},
}


@patch("banquet.router.BanquetHandler", MagicMock({}))
class TestRouter:

def test_router_setup_from_openapi(self, simple_open_api_spec, function_dir):
router = BanquetRouter(simple_open_api_spec, function_dir)
assert len(router.routes["GET"].values()) == 1
assert len(router.routes["POST"].values()) == 1
assert len(router.routes["DELETE"].values()) == 1

def test_router_setup_from_openapi_dynamic_urls(self, dynamic_open_api_spec, function_dir):

def test_router_setup_from_openapi_dynamic_urls(
self, dynamic_open_api_spec, function_dir
):
router = BanquetRouter(dynamic_open_api_spec, function_dir)
assert len(router.routes["GET"].values()) == 1
url_pattern = list(router.routes["GET"].keys())[0]
assert isinstance(url_pattern, re.Pattern) == True

def test_router_resolves_exact_paths(self, routes, simple_open_api_spec, function_dir):
def test_router_resolves_exact_paths(
self, routes, simple_open_api_spec, function_dir
):
router = BanquetRouter(simple_open_api_spec, function_dir)
conf, params = router.resolver(routes["GET"], "/example")
assert conf["handler"] == "get-handler"
assert params is None

def test_router_resolves_dynamic_paths(self, routes, simple_open_api_spec, function_dir):

def test_router_resolves_dynamic_paths(
self, routes, simple_open_api_spec, function_dir
):
router = BanquetRouter(simple_open_api_spec, function_dir)
conf, params = router.resolver(routes["POST"], "/example/test_id")
assert conf["handler"] == "post-handler"
Expand Down

0 comments on commit ac6a52e

Please sign in to comment.