Expose scope parameter in request object (#2432)

Co-authored-by: Adam Hopkins <adam@amhopkins.com>
This commit is contained in:
Michael Azimov
2022-04-26 17:25:29 +03:00
committed by GitHub
parent 78b6723149
commit 5d683c6ea4
4 changed files with 47 additions and 1 deletions

View File

@@ -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() == "/"

View File

@@ -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"])