You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3 KiB

  1. """Connection test module."""
  2. import pytest
  3. from keycloak.connection import ConnectionManager
  4. from keycloak.exceptions import KeycloakConnectionError
  5. def test_connection_proxy():
  6. """Test proxies of connection manager."""
  7. cm = ConnectionManager(
  8. base_url="http://test.test", proxies={"http://test.test": "localhost:8080"}
  9. )
  10. assert cm._s.proxies == {"http://test.test": "localhost:8080"}
  11. def test_headers():
  12. """Test headers manipulation."""
  13. cm = ConnectionManager(base_url="http://test.test", headers={"H": "A"})
  14. assert cm.param_headers(key="H") == "A"
  15. assert cm.param_headers(key="A") is None
  16. cm.clean_headers()
  17. assert cm.headers == dict()
  18. cm.add_param_headers(key="H", value="B")
  19. assert cm.exist_param_headers(key="H")
  20. assert not cm.exist_param_headers(key="B")
  21. cm.del_param_headers(key="H")
  22. assert not cm.exist_param_headers(key="H")
  23. def test_bad_connection():
  24. """Test bad connection."""
  25. cm = ConnectionManager(base_url="http://not.real.domain")
  26. with pytest.raises(KeycloakConnectionError):
  27. cm.raw_get(path="bad")
  28. with pytest.raises(KeycloakConnectionError):
  29. cm.raw_delete(path="bad")
  30. with pytest.raises(KeycloakConnectionError):
  31. cm.raw_post(path="bad", data={})
  32. with pytest.raises(KeycloakConnectionError):
  33. cm.raw_put(path="bad", data={})