test_yarl.py 941 B

1234567891011121314151617181920212223
  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. with pytest.raises(ValueError) as e1:
  17. str(URL('https://dify.ai') / '/api')
  18. assert str(e1.value) == "Appending path '/api' starting from slash is forbidden"