forked from atlassian-api/atlassian-python-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_errors.py
More file actions
288 lines (224 loc) · 10 KB
/
Copy pathtest_errors.py
File metadata and controls
288 lines (224 loc) · 10 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# coding: utf-8
"""
Unit tests for atlassian.errors module
"""
from atlassian.errors import (
ApiError,
JsonRPCError,
ApiNotFoundError,
ApiPermissionError,
ApiValueError,
ApiConflictError,
ApiNotAcceptable,
JsonRPCRestrictionsError,
)
class TestApiError:
"""Test cases for ApiError class"""
def test_init_with_message(self):
"""Test initialization with message only"""
error = ApiError("Test error message")
assert str(error) == "Test error message"
assert error.reason is None
def test_init_with_reason(self):
"""Test initialization with reason"""
error = ApiError("Test error message", reason="Test reason")
assert str(error) == "Test error message"
assert error.reason == "Test reason"
def test_init_with_args(self):
"""Test initialization with multiple args"""
error = ApiError("Error", "arg1", "arg2", reason="Test reason")
assert str(error) == "('Error', 'arg1', 'arg2')"
assert error.reason == "Test reason"
def test_inheritance(self):
"""Test that ApiError inherits from Exception"""
error = ApiError("Test error")
assert isinstance(error, Exception)
class TestJsonRPCError:
"""Test cases for JsonRPCError class"""
def test_init_with_message(self):
"""Test initialization with message only"""
error = JsonRPCError("Test JSON-RPC error message")
assert str(error) == "Test JSON-RPC error message"
def test_init_with_args(self):
"""Test initialization with multiple args"""
error = JsonRPCError("Error", "arg1", "arg2")
assert str(error) == "('Error', 'arg1', 'arg2')"
def test_inheritance(self):
"""Test that JsonRPCError inherits from Exception"""
error = JsonRPCError("Test error")
assert isinstance(error, Exception)
class TestApiNotFoundError:
"""Test cases for ApiNotFoundError class"""
def test_init_with_message(self):
"""Test initialization with message only"""
error = ApiNotFoundError("Resource not found")
assert str(error) == "Resource not found"
assert error.reason is None
def test_init_with_reason(self):
"""Test initialization with reason"""
error = ApiNotFoundError("Resource not found", reason="404 Not Found")
assert str(error) == "Resource not found"
assert error.reason == "404 Not Found"
def test_inheritance(self):
"""Test that ApiNotFoundError inherits from ApiError"""
error = ApiNotFoundError("Test error")
assert isinstance(error, ApiError)
assert isinstance(error, Exception)
class TestApiPermissionError:
"""Test cases for ApiPermissionError class"""
def test_init_with_message(self):
"""Test initialization with message only"""
error = ApiPermissionError("Permission denied")
assert str(error) == "Permission denied"
assert error.reason is None
def test_init_with_reason(self):
"""Test initialization with reason"""
error = ApiPermissionError("Permission denied", reason="403 Forbidden")
assert str(error) == "Permission denied"
assert error.reason == "403 Forbidden"
def test_inheritance(self):
"""Test that ApiPermissionError inherits from ApiError"""
error = ApiPermissionError("Test error")
assert isinstance(error, ApiError)
assert isinstance(error, Exception)
class TestApiValueError:
"""Test cases for ApiValueError class"""
def test_init_with_message(self):
"""Test initialization with message only"""
error = ApiValueError("Invalid value")
assert str(error) == "Invalid value"
assert error.reason is None
def test_init_with_reason(self):
"""Test initialization with reason"""
error = ApiValueError("Invalid value", reason="400 Bad Request")
assert str(error) == "Invalid value"
assert error.reason == "400 Bad Request"
def test_inheritance(self):
"""Test that ApiValueError inherits from ApiError"""
error = ApiValueError("Test error")
assert isinstance(error, ApiError)
assert isinstance(error, Exception)
class TestApiConflictError:
"""Test cases for ApiConflictError class"""
def test_init_with_message(self):
"""Test initialization with message only"""
error = ApiConflictError("Resource conflict")
assert str(error) == "Resource conflict"
assert error.reason is None
def test_init_with_reason(self):
"""Test initialization with reason"""
error = ApiConflictError("Resource conflict", reason="409 Conflict")
assert str(error) == "Resource conflict"
assert error.reason == "409 Conflict"
def test_inheritance(self):
"""Test that ApiConflictError inherits from ApiError"""
error = ApiConflictError("Test error")
assert isinstance(error, ApiError)
assert isinstance(error, Exception)
class TestApiNotAcceptable:
"""Test cases for ApiNotAcceptable class"""
def test_init_with_message(self):
"""Test initialization with message only"""
error = ApiNotAcceptable("Not acceptable")
assert str(error) == "Not acceptable"
assert error.reason is None
def test_init_with_reason(self):
"""Test initialization with reason"""
error = ApiNotAcceptable("Not acceptable", reason="406 Not Acceptable")
assert str(error) == "Not acceptable"
assert error.reason == "406 Not Acceptable"
def test_inheritance(self):
"""Test that ApiNotAcceptable inherits from ApiError"""
error = ApiNotAcceptable("Test error")
assert isinstance(error, ApiError)
assert isinstance(error, Exception)
class TestJsonRPCRestrictionsError:
"""Test cases for JsonRPCRestrictionsError class"""
def test_init_with_message(self):
"""Test initialization with message only"""
error = JsonRPCRestrictionsError("RPC restrictions")
assert str(error) == "RPC restrictions"
def test_init_with_args(self):
"""Test initialization with multiple args"""
error = JsonRPCRestrictionsError("Error", "arg1", "arg2")
assert str(error) == "('Error', 'arg1', 'arg2')"
def test_inheritance(self):
"""Test that JsonRPCRestrictionsError inherits from JsonRPCError"""
error = JsonRPCRestrictionsError("Test error")
assert isinstance(error, JsonRPCError)
assert isinstance(error, Exception)
class TestErrorHierarchy:
"""Test cases for error class hierarchy"""
def test_error_inheritance_chain(self):
"""Test the complete inheritance chain of all error classes"""
# Test ApiError inheritance
api_error = ApiError("Test")
assert isinstance(api_error, Exception)
# Test JsonRPCError inheritance
jsonrpc_error = JsonRPCError("Test")
assert isinstance(jsonrpc_error, Exception)
# Test specific API error inheritance
not_found_error = ApiNotFoundError("Test")
assert isinstance(not_found_error, ApiError)
assert isinstance(not_found_error, Exception)
permission_error = ApiPermissionError("Test")
assert isinstance(permission_error, ApiError)
assert isinstance(permission_error, Exception)
value_error = ApiValueError("Test")
assert isinstance(value_error, ApiError)
assert isinstance(value_error, Exception)
conflict_error = ApiConflictError("Test")
assert isinstance(conflict_error, ApiError)
assert isinstance(conflict_error, Exception)
not_acceptable_error = ApiNotAcceptable("Test")
assert isinstance(not_acceptable_error, ApiError)
assert isinstance(not_acceptable_error, Exception)
# Test JsonRPC error inheritance
rpc_restrictions_error = JsonRPCRestrictionsError("Test")
assert isinstance(rpc_restrictions_error, JsonRPCError)
assert isinstance(rpc_restrictions_error, Exception)
def test_error_attributes(self):
"""Test that error attributes are properly set"""
# Test ApiError with reason
error = ApiError("Test message", reason="Test reason")
assert error.reason == "Test reason"
# Test that other errors can also have reason
not_found_error = ApiNotFoundError("Not found", reason="404")
assert not_found_error.reason == "404"
permission_error = ApiPermissionError("Forbidden", reason="403")
assert permission_error.reason == "403"
def test_error_string_representation(self):
"""Test string representation of errors"""
# Test basic error
error = ApiError("Test error message")
assert str(error) == "Test error message"
# Test error with reason
error_with_reason = ApiError("Test error", reason="Test reason")
assert str(error_with_reason) == "Test error"
# Test JSON-RPC error
jsonrpc_error = JsonRPCError("JSON-RPC error")
assert str(jsonrpc_error) == "JSON-RPC error"
def test_error_equality(self):
"""Test error equality and comparison"""
error1 = ApiError("Same message")
error2 = ApiError("Same message")
error3 = ApiError("Different message")
# Errors with same message should not be equal (different instances)
assert error1 != error2
assert error1 != error3
# Test that errors are not equal to non-error objects
assert error1 != "Same message"
assert error1 != 123
def test_error_hashability(self):
"""Test that errors can be used as dictionary keys or in sets"""
error1 = ApiError("Error 1")
error2 = ApiError("Error 2")
# Test dictionary usage
error_dict = {error1: "value1", error2: "value2"}
assert error_dict[error1] == "value1"
assert error_dict[error2] == "value2"
# Test set usage
error_set = {error1, error2}
assert error1 in error_set
assert error2 in error_set
assert len(error_set) == 2