From 7cce5c1369a290dfbe837b675ded77ebf93c53c4 Mon Sep 17 00:00:00 2001 From: Iurii Pliner Date: Tue, 29 Oct 2024 10:32:20 +0000 Subject: [PATCH] Add some join tests --- tests/test_request.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/test_request.py diff --git a/tests/test_request.py b/tests/test_request.py new file mode 100644 index 0000000..33b82bb --- /dev/null +++ b/tests/test_request.py @@ -0,0 +1,29 @@ +import pytest +import yarl + + +@pytest.mark.parametrize( + "base, relative, actual", + ( + ("http://service.com", "hello", "http://service.com/hello"), + ("http://service.com/", "hello", "http://service.com/hello"), + ("http://service.com", "api/hello", "http://service.com/api/hello"), + ("http://service.com/", "api/hello", "http://service.com/api/hello"), + ("http://service.com", "hello", "http://service.com/hello"), + ("http://service.com/", "hello", "http://service.com/hello"), + ("http://service.com", "api/hello", "http://service.com/api/hello"), + ("http://service.com/", "api/hello", "http://service.com/api/hello"), + ("https://service.com", "hello", "https://service.com/hello"), + ("https://service.com/", "hello", "https://service.com/hello"), + ("https://service.com", "api/hello", "https://service.com/api/hello"), + ("https://service.com/", "api/hello", "https://service.com/api/hello"), + ("https://service.com:12345", "hello", "https://service.com:12345/hello"), + ("https://service.com:12345/", "hello", "https://service.com:12345/hello"), + ("https://service.com:12345", "api/hello", "https://service.com:12345/api/hello"), + ("https://service.com:12345/", "api/hello", "https://service.com:12345/api/hello"), + ), +) +async def test_absolute(base: str, relative: str, actual) -> None: + expected = yarl.URL(base).join(yarl.URL(relative)) + assert expected == yarl.URL(actual) + assert expected.raw_path.startswith("/")