2024-05-10 18:14:48 +08:00
|
|
|
import pytest
|
|
|
|
from yarl import URL
|
|
|
|
|
|
|
|
|
|
|
|
def test_yarl_urls():
|
2024-08-23 23:52:25 +08:00
|
|
|
expected_1 = "https://dify.ai/api"
|
|
|
|
assert str(URL("https://dify.ai") / "api") == expected_1
|
|
|
|
assert str(URL("https://dify.ai/") / "api") == expected_1
|
2024-05-10 18:14:48 +08:00
|
|
|
|
2024-08-23 23:52:25 +08:00
|
|
|
expected_2 = "http://dify.ai:12345/api"
|
|
|
|
assert str(URL("http://dify.ai:12345") / "api") == expected_2
|
|
|
|
assert str(URL("http://dify.ai:12345/") / "api") == expected_2
|
2024-05-10 18:14:48 +08:00
|
|
|
|
2024-08-23 23:52:25 +08:00
|
|
|
expected_3 = "https://dify.ai/api/v1"
|
|
|
|
assert str(URL("https://dify.ai") / "api" / "v1") == expected_3
|
|
|
|
assert str(URL("https://dify.ai") / "api/v1") == expected_3
|
|
|
|
assert str(URL("https://dify.ai/") / "api/v1") == expected_3
|
|
|
|
assert str(URL("https://dify.ai/api") / "v1") == expected_3
|
|
|
|
assert str(URL("https://dify.ai/api/") / "v1") == expected_3
|
2024-05-10 18:14:48 +08:00
|
|
|
|
|
|
|
with pytest.raises(ValueError) as e1:
|
2024-08-23 23:52:25 +08:00
|
|
|
str(URL("https://dify.ai") / "/api")
|
2024-05-10 18:14:48 +08:00
|
|
|
assert str(e1.value) == "Appending path '/api' starting from slash is forbidden"
|