Skip to content

Commit

Permalink
Add a test for Daphne-Root-Path handling for websockets.
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro R. Sedeño <[email protected]>
Signed-off-by: Alejandro R Sedeño <[email protected]>
  • Loading branch information
asedeno committed Nov 19, 2022
1 parent ef946d5 commit ba9bc82
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,30 @@ def test_raw_path(self):
self.assertEqual(scope["path"], "/foo/bar")
self.assertEqual(scope["raw_path"], b"/foo%2Fbar")

@given(daphne_path=http_strategies.http_path())
@settings(max_examples=5, deadline=2000)
def test_root_path(self, *, daphne_path):
"""
Tests root_path handling.
"""
headers = [("Daphne-Root-Path", parse.quote(daphne_path))]
with DaphneTestingInstance() as test_app:
test_app.add_send_messages([{"type": "websocket.accept"}])
self.websocket_handshake(
test_app,
path="/",
headers=headers,
)
# Validate the scope and messages we got
scope, _ = test_app.get_received()

# Daphne-Root-Path is not included in the returned 'headers' section.
self.assertNotIn(
"daphne-root-path", (header[0].lower() for header in scope["headers"])
)
# And what we're looking for, root_path being set.
self.assertEqual(scope["root_path"], daphne_path)

def test_text_frames(self):
"""
Tests we can send and receive text frames.
Expand Down

0 comments on commit ba9bc82

Please sign in to comment.