From 8ba1b5fc35ce0d023fa68d8e9c693f5dbcf7c9c3 Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Tue, 28 Mar 2017 22:33:55 -0500 Subject: [PATCH 1/8] Add docker support for local unit testing Addresses consistency across different OS's by making it very similar to the base Travis image. --- Dockerfile | 6 ++++++ Makefile | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 Dockerfile create mode 100644 Makefile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..ee8ca2be --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.6 + +ADD . /app +WORKDIR /app + +RUN pip install tox diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..ad64412f --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +test: + find . -name "*.pyc" -delete + docker build -t sanic/test-image . + docker run -t sanic/test-image tox From 75a4df0f32e60e103404758901b1f8965cdacf79 Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Tue, 28 Mar 2017 22:34:34 -0500 Subject: [PATCH 2/8] Simplify this, it had a lot of fluff --- requirements-dev.txt | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 1f11a90c..65dd0d7d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,18 +1,10 @@ -aiocache aiofiles aiohttp beautifulsoup4 -bottle coverage -falcon -gunicorn httptools -kyoukai +flake8 pytest -recommonmark -sphinx -sphinx_rtd_theme -tornado tox ujson uvloop From 1ef69adc6f8967ac8b227d4c6ad9bd0270220bb0 Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Tue, 28 Mar 2017 22:34:44 -0500 Subject: [PATCH 3/8] Simplify this as well, it replicated effort --- tox.ini | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tox.ini b/tox.ini index 33e4298f..0e6dc7c6 100644 --- a/tox.ini +++ b/tox.ini @@ -10,12 +10,7 @@ python = [testenv] deps = - aiofiles - aiohttp - websockets - pytest - beautifulsoup4 - coverage + -rrequirements-dev.txt commands = pytest tests {posargs} From dcc19d17d4a43b0b7c6d4472dfea52146bd2dbb9 Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Tue, 28 Mar 2017 22:38:35 -0500 Subject: [PATCH 4/8] Lock to aiohttp 1.3.5 for now --- requirements-dev.txt | 2 +- tests/test_redirect.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 65dd0d7d..28014eb6 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,5 @@ aiofiles -aiohttp +aiohttp==1.3.5 beautifulsoup4 coverage httptools diff --git a/tests/test_redirect.py b/tests/test_redirect.py index 25efe1f3..421ee1cf 100644 --- a/tests/test_redirect.py +++ b/tests/test_redirect.py @@ -88,4 +88,4 @@ def test_chained_redirect(redirect_app): assert request.url.endswith('/1') assert response.status == 200 assert response.text == 'OK' - assert response.url.path.endswith('/3') + assert response.url.endswith('/3') From 3a8cfb1f45b68eb7ff8f9fbef3ec0fdf8226baed Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Tue, 28 Mar 2017 22:38:45 -0500 Subject: [PATCH 5/8] Make these tests not so far apart --- tests/test_payload_too_large.py | 52 ++++++++++++++++----------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/tests/test_payload_too_large.py b/tests/test_payload_too_large.py index a1a58d3d..70ec56ce 100644 --- a/tests/test_payload_too_large.py +++ b/tests/test_payload_too_large.py @@ -2,48 +2,46 @@ from sanic import Sanic from sanic.response import text from sanic.exceptions import PayloadTooLarge -data_received_app = Sanic('data_received') -data_received_app.config.REQUEST_MAX_SIZE = 1 -data_received_default_app = Sanic('data_received_default') -data_received_default_app.config.REQUEST_MAX_SIZE = 1 -on_header_default_app = Sanic('on_header') -on_header_default_app.config.REQUEST_MAX_SIZE = 500 - - -@data_received_app.route('/1') -async def handler1(request): - return text('OK') - - -@data_received_app.exception(PayloadTooLarge) -def handler_exception(request, exception): - return text('Payload Too Large from error_handler.', 413) - def test_payload_too_large_from_error_handler(): + data_received_app = Sanic('data_received') + data_received_app.config.REQUEST_MAX_SIZE = 1 + + @data_received_app.route('/1') + async def handler1(request): + return text('OK') + + @data_received_app.exception(PayloadTooLarge) + def handler_exception(request, exception): + return text('Payload Too Large from error_handler.', 413) + response = data_received_app.test_client.get('/1', gather_request=False) assert response.status == 413 assert response.text == 'Payload Too Large from error_handler.' -@data_received_default_app.route('/1') -async def handler2(request): - return text('OK') - - def test_payload_too_large_at_data_received_default(): + data_received_default_app = Sanic('data_received_default') + data_received_default_app.config.REQUEST_MAX_SIZE = 1 + + @data_received_default_app.route('/1') + async def handler2(request): + return text('OK') + response = data_received_default_app.test_client.get( '/1', gather_request=False) assert response.status == 413 assert response.text == 'Error: Payload Too Large' -@on_header_default_app.route('/1') -async def handler3(request): - return text('OK') - - def test_payload_too_large_at_on_header_default(): + on_header_default_app = Sanic('on_header') + on_header_default_app.config.REQUEST_MAX_SIZE = 500 + + @on_header_default_app.post('/1') + async def handler3(request): + return text('OK') + data = 'a' * 1000 response = on_header_default_app.test_client.post( '/1', gather_request=False, data=data) From 04a0774ee598445db681a4a7db2fca200be65897 Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Tue, 28 Mar 2017 22:44:01 -0500 Subject: [PATCH 6/8] Fix line length --- sanic/response.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sanic/response.py b/sanic/response.py index 38cd68db..6afcb061 100644 --- a/sanic/response.py +++ b/sanic/response.py @@ -132,8 +132,8 @@ class StreamingHTTPResponse(BaseHTTPResponse): async def stream( self, version="1.1", keep_alive=False, keep_alive_timeout=None): - """Streams headers, runs the `streaming_fn` callback that writes content - to the response body, then finalizes the response body. + """Streams headers, runs the `streaming_fn` callback that writes + content to the response body, then finalizes the response body. """ headers = self.get_headers( version, keep_alive=keep_alive, From f0a55b5cbb5542ba3ec769be28e7fb02aaf2a359 Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Tue, 28 Mar 2017 22:47:52 -0500 Subject: [PATCH 7/8] Fix line length again... --- sanic/response.py | 6 +++++- tests/test_redirect.py | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sanic/response.py b/sanic/response.py index 6afcb061..3da9ac5e 100644 --- a/sanic/response.py +++ b/sanic/response.py @@ -331,7 +331,11 @@ def stream( :param headers: Custom Headers. """ return StreamingHTTPResponse( - streaming_fn, headers=headers, content_type=content_type, status=status) + streaming_fn, + headers=headers, + content_type=content_type, + status=status + ) def redirect(to, headers=None, status=302, diff --git a/tests/test_redirect.py b/tests/test_redirect.py index 421ee1cf..f5b734e3 100644 --- a/tests/test_redirect.py +++ b/tests/test_redirect.py @@ -88,4 +88,7 @@ def test_chained_redirect(redirect_app): assert request.url.endswith('/1') assert response.status == 200 assert response.text == 'OK' - assert response.url.endswith('/3') + try: + assert response.url.endswith('/3') + except AttributeError: + assert response.url.path.endswith('/3') From 18405b39080ff80c1b854075f57a218b66b963cf Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Tue, 28 Mar 2017 22:57:58 -0500 Subject: [PATCH 8/8] There was a line missing here? --- sanic/config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sanic/config.py b/sanic/config.py index 9fb09cbf..99d39a9c 100644 --- a/sanic/config.py +++ b/sanic/config.py @@ -3,6 +3,7 @@ import types SANIC_PREFIX = 'SANIC_' + class Config(dict): def __init__(self, defaults=None, load_env=True): super().__init__(defaults or {})