|
10 | 10 | from requests import codes |
11 | 11 |
|
12 | 12 | from vws import VWS |
13 | | -from vws.exceptions import ImageTooLarge, UnknownTarget |
| 13 | +from vws.exceptions import ( |
| 14 | + ImageTooLarge, |
| 15 | + MetadataTooLarge, |
| 16 | + TargetStatusProcessing, |
| 17 | + UnknownTarget, |
| 18 | +) |
14 | 19 |
|
15 | 20 |
|
16 | 21 | def _make_image_file( |
@@ -81,3 +86,42 @@ def test_request_quota_reached() -> None: |
81 | 86 | See https://github.com/adamtheturtle/vws-python/issues/822 for writing |
82 | 87 | this test. |
83 | 88 | """ |
| 89 | + |
| 90 | + |
| 91 | +def test_target_status_processing( |
| 92 | + client: VWS, |
| 93 | + high_quality_image: io.BytesIO, |
| 94 | +) -> None: |
| 95 | + """ |
| 96 | + A ``TargetStatusProcessing`` exception is raised if trying to delete a |
| 97 | + target which is processing. |
| 98 | + """ |
| 99 | + target_id = client.add_target( |
| 100 | + name='x', |
| 101 | + width=1, |
| 102 | + image=high_quality_image, |
| 103 | + ) |
| 104 | + |
| 105 | + with pytest.raises(TargetStatusProcessing) as exc: |
| 106 | + client.delete_target(target_id=target_id) |
| 107 | + |
| 108 | + assert exc.value.response.status_code == codes.FORBIDDEN |
| 109 | + |
| 110 | + |
| 111 | +def test_metadata_too_large( |
| 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 |
0 commit comments