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.

test_jwt_imports.py 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. """Test PyJWT import paths to catch changes in library structure."""
  2. import pytest
  3. class TestPyJWTImports:
  4. """Test PyJWT import paths used throughout the codebase."""
  5. def test_invalid_token_error_import(self):
  6. """Test that InvalidTokenError can be imported as used in login controller."""
  7. # This test verifies the import path used in controllers/web/login.py:2
  8. # If PyJWT changes this import path, this test will fail early
  9. try:
  10. from jwt import InvalidTokenError
  11. # Verify it's the correct exception class
  12. assert issubclass(InvalidTokenError, Exception)
  13. # Test that it can be instantiated
  14. error = InvalidTokenError("test error")
  15. assert str(error) == "test error"
  16. except ImportError as e:
  17. pytest.fail(f"Failed to import InvalidTokenError from jwt: {e}")
  18. def test_jwt_exceptions_import(self):
  19. """Test that jwt.exceptions imports work as expected."""
  20. # Alternative import path that might be used
  21. try:
  22. # Verify it's the same class as the direct import
  23. from jwt import InvalidTokenError
  24. from jwt.exceptions import InvalidTokenError as InvalidTokenErrorAlt
  25. assert InvalidTokenError is InvalidTokenErrorAlt
  26. except ImportError as e:
  27. pytest.fail(f"Failed to import InvalidTokenError from jwt.exceptions: {e}")
  28. def test_other_jwt_exceptions_available(self):
  29. """Test that other common JWT exceptions are available."""
  30. # Test other exceptions that might be used in the codebase
  31. try:
  32. from jwt import DecodeError, ExpiredSignatureError, InvalidSignatureError
  33. # Verify they are exception classes
  34. assert issubclass(DecodeError, Exception)
  35. assert issubclass(ExpiredSignatureError, Exception)
  36. assert issubclass(InvalidSignatureError, Exception)
  37. except ImportError as e:
  38. pytest.fail(f"Failed to import JWT exceptions: {e}")
  39. def test_jwt_main_functions_available(self):
  40. """Test that main JWT functions are available."""
  41. try:
  42. from jwt import decode, encode
  43. # Verify they are callable
  44. assert callable(decode)
  45. assert callable(encode)
  46. except ImportError as e:
  47. pytest.fail(f"Failed to import JWT main functions: {e}")