Merge pull request #163 from channelcat/request-data-vars
Access Request like a dictionary Closes #129 #132
This commit is contained in:
commit
fc19f2ea34
|
@ -32,7 +32,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['user'] = 'sanic'
|
||||||
|
request['sidekick'] = 'tails'
|
||||||
|
del request['sidekick']
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def handler(request):
|
||||||
|
return json({ 'user': request.get('user'), 'sidekick': request.get('sidekick') })
|
||||||
|
|
||||||
|
request, response = sanic_endpoint_test(app)
|
||||||
|
|
||||||
|
response_json = loads(response.text)
|
||||||
|
assert response_json['user'] == 'sanic'
|
||||||
|
assert response_json.get('sidekick') is None
|
Loading…
Reference in New Issue
Block a user