From a97e554f8f4bd2443d6a9d68c60351a8f86c10bc Mon Sep 17 00:00:00 2001 From: Channel Cat Date: Sat, 19 Nov 2016 17:48:28 -0800 Subject: [PATCH 1/5] Added shared request data --- sanic/request.py | 2 +- tests/test_request_data.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/test_request_data.py diff --git a/sanic/request.py b/sanic/request.py index c2ab7260..ff6e8b51 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -26,7 +26,7 @@ class RequestParameters(dict): return self.super.get(name, default) -class Request: +class Request(dict): """ Properties of an HTTP request such as URL, headers, etc. """ diff --git a/tests/test_request_data.py b/tests/test_request_data.py new file mode 100644 index 00000000..161a7836 --- /dev/null +++ b/tests/test_request_data.py @@ -0,0 +1,24 @@ +from sanic import Sanic +from sanic.response import json +from sanic.utils import sanic_endpoint_test +from ujson import loads + + +def test_storage(): + app = Sanic('test_text') + + @app.middleware('request') + def store(request): + request['a'] = 'test' + request['b'] = 'zest' + del request['b'] + + @app.route('/') + def handler(request): + return json({ 'a': request.get('a'), 'b': request.get('b') }) + + request, response = sanic_endpoint_test(app) + + response_json = loads(response.text) + assert response_json['a'] == 'test' + assert response_json.get('b') is None \ No newline at end of file From 3ce6434532fcf7994a50f0d780320cb3b1e6e586 Mon Sep 17 00:00:00 2001 From: Channel Cat Date: Sat, 19 Nov 2016 18:04:35 -0800 Subject: [PATCH 2/5] Fix flake8 --- sanic/cookies.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sanic/cookies.py b/sanic/cookies.py index 622a5a08..b7669e76 100644 --- a/sanic/cookies.py +++ b/sanic/cookies.py @@ -30,6 +30,7 @@ def _quote(str): else: return '"' + str.translate(_Translator) + '"' + _is_legal_key = re.compile('[%s]+' % re.escape(_LegalChars)).fullmatch # ------------------------------------------------------------ # From 01681599ff63384e8f87680df641c178b3c2484f Mon Sep 17 00:00:00 2001 From: Channel Cat Date: Sat, 19 Nov 2016 18:13:02 -0800 Subject: [PATCH 3/5] Fixed new test error with aiohttp --- tests/test_requests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_requests.py b/tests/test_requests.py index 290c9b99..0098797d 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -56,7 +56,7 @@ def test_query_string(): async def handler(request): return text('OK') - request, response = sanic_endpoint_test(app, params=[("test1", 1), ("test2", "false"), ("test2", "true")]) + request, response = sanic_endpoint_test(app, params={"test1":1, "test2":"false"}) assert request.args.get('test1') == '1' assert request.args.get('test2') == 'false' From 922c96e3c1ca28572b631b63145f717774f5efd2 Mon Sep 17 00:00:00 2001 From: Channel Cat Date: Sat, 19 Nov 2016 18:26:03 -0800 Subject: [PATCH 4/5] Updated test terminology --- tests/test_request_data.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_request_data.py b/tests/test_request_data.py index 161a7836..fca67ba9 100644 --- a/tests/test_request_data.py +++ b/tests/test_request_data.py @@ -9,16 +9,16 @@ def test_storage(): @app.middleware('request') def store(request): - request['a'] = 'test' - request['b'] = 'zest' - del request['b'] + request['user'] = 'sanic' + request['sidekick'] = 'tails' + del request['sidekick'] @app.route('/') def handler(request): - return json({ 'a': request.get('a'), 'b': request.get('b') }) + return json({ 'user': request.get('user'), 'sidekick': request.get('sidekick') }) request, response = sanic_endpoint_test(app) response_json = loads(response.text) - assert response_json['a'] == 'test' - assert response_json.get('b') is None \ No newline at end of file + assert response_json['user'] == 'sanic' + assert response_json.get('sidekick') is None \ No newline at end of file From aa0f15fbb2de8bd644eaff869e6ee94880d19802 Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Wed, 23 Nov 2016 11:03:00 -0600 Subject: [PATCH 5/5] Adding a new line --- tests/test_request_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_request_data.py b/tests/test_request_data.py index fca67ba9..098878e7 100644 --- a/tests/test_request_data.py +++ b/tests/test_request_data.py @@ -21,4 +21,4 @@ def test_storage(): response_json = loads(response.text) assert response_json['user'] == 'sanic' - assert response_json.get('sidekick') is None \ No newline at end of file + assert response_json.get('sidekick') is None