]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
Add tests to `test_datastructure` (#2505)
authorScirlat Danut <danut.scirlat@gmail.com>
Sun, 24 Mar 2024 17:19:36 +0000 (19:19 +0200)
committerGitHub <noreply@github.com>
Sun, 24 Mar 2024 17:19:36 +0000 (17:19 +0000)
* Add tests to test_datastructure

* Update tests

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
tests/test_datastructures.py

index b7d6725d45a40d5441d50751d7720b570ffbc6d8..a6bca6ef6d6b86de9c5b95322c5d2b4b6b588c01 100644 (file)
@@ -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")])