Skip to content

Commit 8cf065c

Browse files
committed
Start of consolidating tests for exceptions
1 parent bbdab24 commit 8cf065c

3 files changed

Lines changed: 44 additions & 41 deletions

File tree

tests/test_add_target.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,26 +107,6 @@ def test_given(
107107
application_metadata=b'a',
108108
)
109109

110-
def test_too_large(
111-
self,
112-
client: VWS,
113-
high_quality_image: io.BytesIO,
114-
) -> None:
115-
"""
116-
A ``MetadataTooLarge`` exception is raised if the metadata given is too
117-
large.
118-
"""
119-
with pytest.raises(MetadataTooLarge) as exc:
120-
client.add_target(
121-
name='x',
122-
width=1,
123-
image=high_quality_image,
124-
application_metadata=b'a' * 1024 * 1024,
125-
)
126-
127-
assert exc.value.response.status_code == codes.UNPROCESSABLE_ENTITY
128-
129-
130110
class TestActiveFlag:
131111
"""
132112
Tests for the ``active_flag`` parameter to ``add_target``.

tests/test_delete_target.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,6 @@ class TestDelete:
1616
Test for deleting a target.
1717
"""
1818

19-
def test_target_processing(
20-
self,
21-
client: VWS,
22-
high_quality_image: io.BytesIO,
23-
) -> None:
24-
"""
25-
A ``TargetStatusProcessing`` exception is raised if trying to delete a
26-
target which is processing.
27-
"""
28-
target_id = client.add_target(
29-
name='x',
30-
width=1,
31-
image=high_quality_image,
32-
)
33-
34-
with pytest.raises(TargetStatusProcessing) as exc:
35-
client.delete_target(target_id=target_id)
36-
37-
assert exc.value.response.status_code == codes.FORBIDDEN
38-
3919
def test_delete_target(
4020
self,
4121
client: VWS,

tests/test_exceptions.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
Fail,
1717
ImageTooLarge,
1818
TargetNameExist,
19+
TargetStatusProcessing,
20+
MetadataTooLarge,
1921
ProjectInactive,
2022
UnknownTarget,
2123
)
@@ -146,9 +148,50 @@ def test_project_inactive(client: VWS, high_quality_image: io.BytesIO) -> None:
146148
server_secret_key=mock.server_secret_key,
147149
)
148150

149-
with pytest.raises(ProjectInactive):
151+
with pytest.raises(ProjectInactive) as exc:
150152
client.add_target(
151153
name='x',
152154
width=1,
153155
image=high_quality_image,
154156
)
157+
158+
assert exc.value.response.status_code == codes.FORBIDDEN
159+
160+
161+
def test_target_status_processing(
162+
client: VWS,
163+
high_quality_image: io.BytesIO,
164+
) -> None:
165+
"""
166+
A ``TargetStatusProcessing`` exception is raised if trying to delete a
167+
target which is processing.
168+
"""
169+
target_id = client.add_target(
170+
name='x',
171+
width=1,
172+
image=high_quality_image,
173+
)
174+
175+
with pytest.raises(TargetStatusProcessing) as exc:
176+
client.delete_target(target_id=target_id)
177+
178+
assert exc.value.response.status_code == codes.FORBIDDEN
179+
180+
181+
def test_metadata_too_large(
182+
client: VWS,
183+
high_quality_image: io.BytesIO,
184+
) -> None:
185+
"""
186+
A ``MetadataTooLarge`` exception is raised if the metadata given is too
187+
large.
188+
"""
189+
with pytest.raises(MetadataTooLarge) as exc:
190+
client.add_target(
191+
name='x',
192+
width=1,
193+
image=high_quality_image,
194+
application_metadata=b'a' * 1024 * 1024,
195+
)
196+
197+
assert exc.value.response.status_code == codes.UNPROCESSABLE_ENTITY

0 commit comments

Comments
 (0)