diff --git a/.travis.yml b/.travis.yml index 1331ca5..250650f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,3 +10,4 @@ install: # command to run the dependencies script: - "pytest" + - "black responder tests setup.py --check" diff --git a/responder/api.py b/responder/api.py index e21a0bf..ac34de2 100644 --- a/responder/api.py +++ b/responder/api.py @@ -251,9 +251,7 @@ class API: cont = True except Exception: self.background( - self.default_response, - websocket=route.uses_websocket, - error=True + self.default_response, websocket=route.uses_websocket, error=True ) raise @@ -658,6 +656,6 @@ class API: spawn() def run(self, **kwargs): - if 'debug' not in kwargs: - kwargs.update({'debug': self.debug}) + if "debug" not in kwargs: + kwargs.update({"debug": self.debug}) self.serve(**kwargs) diff --git a/responder/cli.py b/responder/cli.py index bb4cdbe..8c5548b 100644 --- a/responder/cli.py +++ b/responder/cli.py @@ -40,4 +40,4 @@ def cli(): prop = "api" app = __import__(module) - getattr(app, prop).run() \ No newline at end of file + getattr(app, prop).run() diff --git a/responder/routes.py b/responder/routes.py index eb77071..490c2f5 100644 --- a/responder/routes.py +++ b/responder/routes.py @@ -55,7 +55,7 @@ class Route: def _weight(self): params = set(self._param_pattern.findall(self.route)) params_count = len(params) - w = len(self.route.rsplit('}', 1)[-1].strip('/')) + w = len(self.route.rsplit("}", 1)[-1].strip("/")) return params_count != 0, w == 0, -params_count @property diff --git a/responder/statics.py b/responder/statics.py index ff5c461..c10acfa 100644 --- a/responder/statics.py +++ b/responder/statics.py @@ -4,11 +4,11 @@ DEFAULT_SESSION_COOKIE = "Responder-Session" DEFAULT_SECRET_KEY = "NOTASECRET" DEFAULT_CORS_PARAMS = { - "allow_origins": (), - "allow_methods": ("GET",), - "allow_headers": (), - "allow_credentials": False, - "allow_origin_regex": None, - "expose_headers": (), - "max_age": 600, + "allow_origins": (), + "allow_methods": ("GET",), + "allow_headers": (), + "allow_credentials": False, + "allow_origin_regex": None, + "expose_headers": (), + "max_age": 600, } diff --git a/tests/conftest.py b/tests/conftest.py index c7aabf9..547a388 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -18,10 +18,7 @@ def current_dir(): @pytest.fixture def api(): - return responder.API( - debug=False, - allowed_hosts=[";"] - ) + return responder.API(debug=False, allowed_hosts=[";"]) @pytest.fixture @@ -49,6 +46,7 @@ def flask(): return app + @pytest.fixture def schema(): class Query(graphene.ObjectType): diff --git a/tests/test_responder.py b/tests/test_responder.py index 46c4e4e..2c479f7 100644 --- a/tests/test_responder.py +++ b/tests/test_responder.py @@ -479,8 +479,9 @@ def test_500(api): def view(req, resp): raise ValueError - dumb_client = responder.api.TestClient(api, base_url="http://;", - raise_server_exceptions=False) + dumb_client = responder.api.TestClient( + api, base_url="http://;", raise_server_exceptions=False + ) r = dumb_client.get(api.url_for(view)) assert not r.ok assert r.status_code == responder.status_codes.HTTP_500 diff --git a/tests/test_routes.py b/tests/test_routes.py index e1b79f4..02230d1 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -89,25 +89,41 @@ def test_does_match_with_route(route, match, expected): [ pytest.param("/{greetings}", (True, True, -1), id="with one param"), pytest.param( - "/{greetings}.{name}", (True, True, -2), id="with 2 params and dot in the middle" + "/{greetings}.{name}", + (True, True, -2), + id="with 2 params and dot in the middle", ), - pytest.param("/{greetings}/{name}", (True, True, -2), id="with 2 params and subpath"), pytest.param( - "/{greetings}/{name}/{hello}", (True, True, -3), id="with 3 params and subpath" + "/{greetings}/{name}", (True, True, -2), id="with 2 params and subpath" + ), + pytest.param( + "/{greetings}/{name}/{hello}", + (True, True, -3), + id="with 3 params and subpath", ), pytest.param( "/{greetings}_{name}", (True, True, -2), id="with 2 params and underscore" ), pytest.param("/{greetings}/test", (True, False, -1), id="with one param"), pytest.param( - "/{greetings}.{name}/test", (True, False, -2), id="with 2 params and dot in the middle" - ), - pytest.param("/{greetings}/{name}/test", (True, False, -2), id="with 2 params and subpath"), - pytest.param( - "/{greetings}/{name}/{hello}/test", (True, False, -3), id="with 3 params and subpath" + "/{greetings}.{name}/test", + (True, False, -2), + id="with 2 params and dot in the middle", ), pytest.param( - "/{greetings}_{name}/test", (True, False, -2), id="with 2 params and underscore" + "/{greetings}/{name}/test", + (True, False, -2), + id="with 2 params and subpath", + ), + pytest.param( + "/{greetings}/{name}/{hello}/test", + (True, False, -3), + id="with 3 params and subpath", + ), + pytest.param( + "/{greetings}_{name}/test", + (True, False, -2), + id="with 2 params and underscore", ), pytest.param("/hello", (False, False, 0), id="without params"), ],