test_yarl.py 1.1 KB

1234567891011121314151617181920212223242526272829
  1. import pytest
  2. from yarl import URL
  3. def test_yarl_urls():
  4. expected_1 = "https://dify.ai/api"
  5. assert str(URL("https://dify.ai") / "api") == expected_1
  6. assert str(URL("https://dify.ai/") / "api") == expected_1
  7. expected_2 = "http://dify.ai:12345/api"
  8. assert str(URL("http://dify.ai:12345") / "api") == expected_2
  9. assert str(URL("http://dify.ai:12345/") / "api") == expected_2
  10. expected_3 = "https://dify.ai/api/v1"
  11. assert str(URL("https://dify.ai") / "api" / "v1") == expected_3
  12. assert str(URL("https://dify.ai") / "api/v1") == expected_3
  13. assert str(URL("https://dify.ai/") / "api/v1") == expected_3
  14. assert str(URL("https://dify.ai/api") / "v1") == expected_3
  15. assert str(URL("https://dify.ai/api/") / "v1") == expected_3
  16. expected_4 = "api"
  17. assert str(URL("") / "api") == expected_4
  18. expected_5 = "/api"
  19. assert str(URL("/") / "api") == expected_5
  20. with pytest.raises(ValueError) as e1:
  21. str(URL("https://dify.ai") / "/api")
  22. assert str(e1.value) == "Appending path '/api' starting from slash is forbidden"