Expose scope parameter in request object (#2432)
Co-authored-by: Adam Hopkins <adam@amhopkins.com>
This commit is contained in:
@@ -191,3 +191,29 @@ def test_bad_url_parse():
|
||||
Mock(),
|
||||
Mock(),
|
||||
)
|
||||
|
||||
|
||||
def test_request_scope_raises_exception_when_no_asgi():
|
||||
app = Sanic("no_asgi")
|
||||
|
||||
@app.get("/")
|
||||
async def get(request):
|
||||
return request.scope
|
||||
|
||||
request, response = app.test_client.get("/")
|
||||
assert response.status == 500
|
||||
with pytest.raises(NotImplementedError):
|
||||
_ = request.scope
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_request_scope_is_not_none_when_running_in_asgi(app):
|
||||
@app.get("/")
|
||||
async def get(request):
|
||||
return response.empty()
|
||||
|
||||
request, _ = await app.asgi_client.get("/")
|
||||
|
||||
assert request.scope is not None
|
||||
assert request.scope["method"].lower() == "get"
|
||||
assert request.scope["path"].lower() == "/"
|
||||
|
||||
@@ -1051,7 +1051,6 @@ async def test_post_form_urlencoded_keep_blanks_asgi(app):
|
||||
assert request.form.get("test") == "" # For request.parsed_form
|
||||
|
||||
|
||||
|
||||
def test_post_form_urlencoded_drop_blanks(app):
|
||||
@app.route("/", methods=["POST"])
|
||||
async def handler(request):
|
||||
@@ -1066,6 +1065,7 @@ def test_post_form_urlencoded_drop_blanks(app):
|
||||
|
||||
assert "test" not in request.form.keys()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_post_form_urlencoded_drop_blanks_asgi(app):
|
||||
@app.route("/", methods=["POST"])
|
||||
|
||||
Reference in New Issue
Block a user