Added shared request data
This commit is contained in:
parent
3a1ef6bef2
commit
a97e554f8f
|
@ -26,7 +26,7 @@ class RequestParameters(dict):
|
||||||
return self.super.get(name, default)
|
return self.super.get(name, default)
|
||||||
|
|
||||||
|
|
||||||
class Request:
|
class Request(dict):
|
||||||
"""
|
"""
|
||||||
Properties of an HTTP request such as URL, headers, etc.
|
Properties of an HTTP request such as URL, headers, etc.
|
||||||
"""
|
"""
|
||||||
|
|
24
tests/test_request_data.py
Normal file
24
tests/test_request_data.py
Normal file
|
@ -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
|
Loading…
Reference in New Issue
Block a user