-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Expand file tree
/
Copy pathtest_auth_exceptions.py
More file actions
94 lines (72 loc) · 2.9 KB
/
Copy pathtest_auth_exceptions.py
File metadata and controls
94 lines (72 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""Tests for langflow.services.auth.exceptions module."""
from langflow.services.auth.exceptions import (
AuthenticationError,
InactiveUserError,
InsufficientPermissionsError,
InvalidCredentialsError,
InvalidTokenError,
MissingCredentialsError,
TokenExpiredError,
)
class TestAuthenticationError:
def test_message(self):
exc = AuthenticationError("test error")
assert exc.message == "test error"
assert str(exc) == "test error"
def test_error_code(self):
exc = AuthenticationError("test", error_code="my_code")
assert exc.error_code == "my_code"
def test_no_error_code(self):
exc = AuthenticationError("test")
assert exc.error_code is None
class TestInvalidCredentialsError:
def test_default_message(self):
exc = InvalidCredentialsError()
assert exc.message == "Invalid credentials provided"
assert exc.error_code == "invalid_credentials"
def test_custom_message(self):
exc = InvalidCredentialsError("Wrong password")
assert exc.message == "Wrong password"
assert exc.error_code == "invalid_credentials"
def test_is_authentication_error(self):
assert issubclass(InvalidCredentialsError, AuthenticationError)
class TestMissingCredentialsError:
def test_default_message(self):
exc = MissingCredentialsError()
assert exc.message == "No credentials provided"
assert exc.error_code == "missing_credentials"
def test_custom_message(self):
exc = MissingCredentialsError("Token required")
assert exc.message == "Token required"
class TestInactiveUserError:
def test_default_message(self):
exc = InactiveUserError()
assert exc.message == "User account is inactive"
assert exc.error_code == "inactive_user"
class TestInsufficientPermissionsError:
def test_default_message(self):
exc = InsufficientPermissionsError()
assert exc.message == "Insufficient permissions"
assert exc.error_code == "insufficient_permissions"
class TestTokenExpiredError:
def test_default_message(self):
exc = TokenExpiredError()
assert exc.message == "Authentication token has expired"
assert exc.error_code == "token_expired"
class TestInvalidTokenError:
def test_default_message(self):
exc = InvalidTokenError()
assert exc.message == "Invalid authentication token"
assert exc.error_code == "invalid_token"
class TestExceptionHierarchy:
def test_all_subclass_authentication_error(self):
subclasses = [
InvalidCredentialsError,
MissingCredentialsError,
InactiveUserError,
InsufficientPermissionsError,
TokenExpiredError,
InvalidTokenError,
]
for cls in subclasses:
assert issubclass(cls, AuthenticationError), f"{cls.__name__} should be a subclass"