Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "raw_path" to TestClient request scope #805

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions starlette/testclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def send(
scope = {
"type": "websocket",
"path": unquote(path),
"raw_path": path,
trimailov marked this conversation as resolved.
Show resolved Hide resolved
"root_path": self.root_path,
"scheme": scheme,
"query_string": query.encode(),
Expand All @@ -150,6 +151,7 @@ def send(
"http_version": "1.1",
"method": request.method,
"path": unquote(path),
"raw_path": path,
"root_path": self.root_path,
"scheme": scheme,
"query_string": query.encode(),
Expand Down
15 changes: 14 additions & 1 deletion tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from starlette.requests import ClientDisconnect, Request, State
from starlette.responses import JSONResponse, Response
from starlette.responses import JSONResponse, PlainTextResponse, Response
from starlette.testclient import TestClient


Expand Down Expand Up @@ -178,6 +178,19 @@ def test_request_scope_interface():
assert len(request) == 3


def test_request_raw_path():
async def app(scope, receive, send):
request = Request(scope, receive)
path = request.scope["path"]
raw_path = request.scope["raw_path"]
response = PlainTextResponse(f"{path}, {raw_path}")
await response(scope, receive, send)

client = TestClient(app)
response = client.get("/he%2Fllo")
assert response.text == "/he/llo, /he%2Fllo"


def test_request_without_setting_receive():
"""
If Request is instantiated without the receive channel, then .body()
Expand Down