|
9 | 9 | from typing import Any |
10 | 10 |
|
11 | 11 | import pytest |
12 | | -from common_library.errors_classes import ( |
13 | | - ForbiddenError, |
14 | | - NotFoundError, |
15 | | - OsparcErrorMixin, |
16 | | - make_resource_error, |
17 | | -) |
| 12 | +from common_library.errors_classes import OsparcErrorMixin |
18 | 13 |
|
19 | 14 |
|
20 | 15 | def test_get_full_class_name(): |
@@ -159,44 +154,3 @@ class MyError(OsparcErrorMixin, ValueError): |
159 | 154 | "message": "42 and 'missing=?'", |
160 | 155 | "value": 42, |
161 | 156 | } |
162 | | - |
163 | | - |
164 | | -def test_resource_error_factory(): |
165 | | - ProjectNotFoundError = make_resource_error("project", NotFoundError) |
166 | | - |
167 | | - error_1 = ProjectNotFoundError(resource_id="abc123") |
168 | | - assert "resource_id" in error_1.error_context() |
169 | | - assert error_1.resource_id in error_1.message # type: ignore |
170 | | - |
171 | | - |
172 | | -def test_resource_error_factory_auto_detect_resource_id(): |
173 | | - ProjectForbiddenError = make_resource_error("project", ForbiddenError) |
174 | | - error_2 = ProjectForbiddenError(project_id="abc123", other_id="foo") |
175 | | - assert ( |
176 | | - error_2.resource_id == error_2.project_id # type: ignore |
177 | | - ), "auto-detects project ids as resourceid" |
178 | | - assert error_2.other_id # type: ignore |
179 | | - assert error_2.code == "ForbiddenError.ProjectForbiddenError" |
180 | | - |
181 | | - assert error_2.error_context() == { |
182 | | - "project_id": "abc123", |
183 | | - "other_id": "foo", |
184 | | - "resource": "project", |
185 | | - "resource_id": "abc123", |
186 | | - "message": "Access to project is forbidden: id='abc123'", |
187 | | - "code": "ForbiddenError.ProjectForbiddenError", |
188 | | - } |
189 | | - |
190 | | - |
191 | | -def test_resource_error_factory_different_base_exception(): |
192 | | - |
193 | | - class MyBaseError(Exception): ... |
194 | | - |
195 | | - OtherProjectForbiddenError = make_resource_error( |
196 | | - "other_project", ForbiddenError, MyBaseError |
197 | | - ) |
198 | | - |
199 | | - assert issubclass(OtherProjectForbiddenError, MyBaseError) |
200 | | - |
201 | | - error_3 = OtherProjectForbiddenError(project_id="abc123") |
202 | | - assert error_3.code == "MyBaseError.ForbiddenError.OtherProjectForbiddenError" |
0 commit comments