From 44e640a732713475e3715835f394bb4029fb7948 Mon Sep 17 00:00:00 2001 From: Scirlat Danut Date: Sun, 24 Mar 2024 19:19:36 +0200 Subject: [PATCH] Add tests to `test_datastructure` (#2505) * Add tests to test_datastructure * Update tests --------- Co-authored-by: Scirlat Danut Co-authored-by: Marcelo Trylesinski --- tests/test_datastructures.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_datastructures.py b/tests/test_datastructures.py index b7d6725d4..a6bca6ef6 100644 --- a/tests/test_datastructures.py +++ b/tests/test_datastructures.py @@ -58,6 +58,9 @@ def test_url() -> None: url = URL("http://u:p@host:80") assert url.replace(port=88) == URL("http://u:p@host:88") + url = URL("http://host:80") + assert url.replace(username="u") == URL("http://u@host:80") + def test_url_query_params() -> None: u = URL("https://example.org/path/?page=3") @@ -70,6 +73,10 @@ def test_url_query_params() -> None: assert str(u) == "https://example.org/path/?order=name" u = u.remove_query_params("order") assert str(u) == "https://example.org/path/" + u = u.include_query_params(page=4, search="testing") + assert str(u) == "https://example.org/path/?page=4&search=testing" + u = u.remove_query_params(["page", "search"]) + assert str(u) == "https://example.org/path/" def test_hidden_password() -> None: @@ -138,6 +145,21 @@ def test_url_from_scope() -> None: assert u == "https://example.org/path/to/somewhere?abc=123" assert repr(u) == "URL('https://example.org/path/to/somewhere?abc=123')" + u = URL( + scope={ + "scheme": "http", + "path": "/some/path", + "query_string": b"query=string", + "headers": [ + (b"content-type", b"text/html"), + (b"host", b"example.com:8000"), + (b"accept", b"text/html"), + ], + } + ) + assert u == "http://example.com:8000/some/path?query=string" + assert repr(u) == "URL('http://example.com:8000/some/path?query=string')" + def test_headers() -> None: h = Headers(raw=[(b"a", b"123"), (b"a", b"456"), (b"b", b"789")])