Skip to content

Commit 35cc4ff

Browse files
committed
Use a more appropriate fixture where possible
1 parent 624e83d commit 35cc4ff

File tree

9 files changed

+66
-79
lines changed

9 files changed

+66
-79
lines changed

tests/mock_vws/fixtures/images.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,6 @@ def image_file_success_state_low_rating() -> io.BytesIO:
2424
)
2525

2626

27-
@pytest.fixture
28-
def png_rgb() -> io.BytesIO:
29-
"""
30-
Return a 1x1 PNG file in the RGB color space.
31-
"""
32-
return make_image_file(
33-
file_format='PNG',
34-
color_space='RGB',
35-
width=1,
36-
height=1,
37-
)
38-
39-
4027
@pytest.fixture
4128
def corrupted_image_file() -> io.BytesIO:
4229
"""

tests/mock_vws/fixtures/prepared_requests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
@pytest.fixture()
3131
def _add_target(
3232
vuforia_database_keys: VuforiaDatabaseKeys,
33-
png_rgb: io.BytesIO,
33+
image_file_failed_state: io.BytesIO,
3434
) -> Endpoint:
3535
"""
3636
Return details of the endpoint for adding a target.
3737
"""
38-
image_data = png_rgb.read()
38+
image_data = image_file_failed_state.read()
3939
image_data_encoded = base64.b64encode(image_data).decode('ascii')
4040
date = rfc_1123_date()
4141
data: Dict[str, Any] = {

tests/mock_vws/test_add_target.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ class TestContentTypes:
7070
def test_content_types(
7171
self,
7272
vuforia_database_keys: VuforiaDatabaseKeys,
73-
png_rgb: io.BytesIO,
73+
image_file_failed_state: io.BytesIO,
7474
content_type: str,
7575
) -> None:
7676
"""
7777
Any `Content-Type` header is allowed.
7878
"""
79-
image_data = png_rgb.read()
79+
image_data = image_file_failed_state.read()
8080
image_data_encoded = base64.b64encode(image_data).decode('ascii')
8181

8282
data = {
@@ -104,13 +104,13 @@ class TestMissingData:
104104
def test_missing_data(
105105
self,
106106
vuforia_database_keys: VuforiaDatabaseKeys,
107-
png_rgb: io.BytesIO,
107+
image_file_failed_state: io.BytesIO,
108108
data_to_remove: str,
109109
) -> None:
110110
"""
111111
`name`, `width` and `image` are all required.
112112
"""
113-
image_data = png_rgb.read()
113+
image_data = image_file_failed_state.read()
114114
image_data_encoded = base64.b64encode(image_data).decode('ascii')
115115

116116
data = {
@@ -146,13 +146,13 @@ class TestWidth:
146146
def test_width_invalid(
147147
self,
148148
vuforia_database_keys: VuforiaDatabaseKeys,
149-
png_rgb: io.BytesIO,
149+
image_file_failed_state: io.BytesIO,
150150
width: Any,
151151
) -> None:
152152
"""
153153
The width must be a number greater than zero.
154154
"""
155-
image_data = png_rgb.read()
155+
image_data = image_file_failed_state.read()
156156
image_data_encoded = base64.b64encode(image_data).decode('ascii')
157157

158158
data = {
@@ -175,12 +175,12 @@ def test_width_invalid(
175175
def test_width_valid(
176176
self,
177177
vuforia_database_keys: VuforiaDatabaseKeys,
178-
png_rgb: io.BytesIO,
178+
image_file_failed_state: io.BytesIO,
179179
) -> None:
180180
"""
181181
Positive numbers are valid widths.
182182
"""
183-
image_data = png_rgb.read()
183+
image_data = image_file_failed_state.read()
184184
image_data_encoded = base64.b64encode(image_data).decode('ascii')
185185

186186
data = {
@@ -222,13 +222,13 @@ class TestTargetName:
222222
def test_name_valid(
223223
self,
224224
name: str,
225-
png_rgb: io.BytesIO,
225+
image_file_failed_state: io.BytesIO,
226226
vuforia_database_keys: VuforiaDatabaseKeys,
227227
) -> None:
228228
"""
229229
Names between 1 and 64 characters in length are valid.
230230
"""
231-
image_data = png_rgb.read()
231+
image_data = image_file_failed_state.read()
232232
image_data_encoded = base64.b64encode(image_data).decode('ascii')
233233

234234
data = {
@@ -270,15 +270,15 @@ def test_name_valid(
270270
def test_name_invalid(
271271
self,
272272
name: str,
273-
png_rgb: io.BytesIO,
273+
image_file_failed_state: io.BytesIO,
274274
vuforia_database_keys: VuforiaDatabaseKeys,
275275
status_code: int,
276276
) -> None:
277277
"""
278278
A target's name must be a string of length 0 < N < 65, with characters
279279
in a particular range.
280280
"""
281-
image_data = png_rgb.read()
281+
image_data = image_file_failed_state.read()
282282
image_data_encoded = base64.b64encode(image_data).decode('ascii')
283283

284284
data = {
@@ -300,13 +300,13 @@ def test_name_invalid(
300300

301301
def test_existing_target_name(
302302
self,
303-
png_rgb: io.BytesIO,
303+
image_file_failed_state: io.BytesIO,
304304
vuforia_database_keys: VuforiaDatabaseKeys,
305305
) -> None:
306306
"""
307307
Only one target can have a given name.
308308
"""
309-
image_data = png_rgb.read()
309+
image_data = image_file_failed_state.read()
310310
image_data_encoded = base64.b64encode(image_data).decode('ascii')
311311

312312
data = {
@@ -333,13 +333,13 @@ def test_existing_target_name(
333333

334334
def test_deleted_existing_target_name(
335335
self,
336-
png_rgb: io.BytesIO,
336+
image_file_failed_state: io.BytesIO,
337337
vuforia_database_keys: VuforiaDatabaseKeys,
338338
) -> None:
339339
"""
340340
A target can be added with the name of a deleted target.
341341
"""
342-
image_data = png_rgb.read()
342+
image_data = image_file_failed_state.read()
343343
image_data_encoded = base64.b64encode(image_data).decode('ascii')
344344

345345
data = {
@@ -635,13 +635,13 @@ class TestActiveFlag:
635635
def test_valid(
636636
self,
637637
active_flag: Union[bool, None],
638-
png_rgb: io.BytesIO,
638+
image_file_failed_state: io.BytesIO,
639639
vuforia_database_keys: VuforiaDatabaseKeys,
640640
) -> None:
641641
"""
642642
Boolean values and NULL are valid active flags.
643643
"""
644-
image_data = png_rgb.read()
644+
image_data = image_file_failed_state.read()
645645
image_data_encoded = base64.b64encode(image_data).decode('ascii')
646646
content_type = 'application/json'
647647

@@ -662,14 +662,14 @@ def test_valid(
662662

663663
def test_invalid(
664664
self,
665-
png_rgb: io.BytesIO,
665+
image_file_failed_state: io.BytesIO,
666666
vuforia_database_keys: VuforiaDatabaseKeys,
667667
) -> None:
668668
"""
669669
Values which are not Boolean values or NULL are not valid active flags.
670670
"""
671671
active_flag = 'string'
672-
image_data = png_rgb.read()
672+
image_data = image_file_failed_state.read()
673673
image_data_encoded = base64.b64encode(image_data).decode('ascii')
674674
content_type = 'application/json'
675675

@@ -702,12 +702,12 @@ class TestUnexpectedData:
702702
def test_invalid_extra_data(
703703
self,
704704
vuforia_database_keys: VuforiaDatabaseKeys,
705-
png_rgb: io.BytesIO,
705+
image_file_failed_state: io.BytesIO,
706706
) -> None:
707707
"""
708708
A `BAD_REQUEST` response is returned when unexpected data is given.
709709
"""
710-
image_data = png_rgb.read()
710+
image_data = image_file_failed_state.read()
711711
image_data_encoded = base64.b64encode(image_data).decode('ascii')
712712

713713
data = {
@@ -748,13 +748,13 @@ class TestApplicationMetadata:
748748
def test_base64_encoded(
749749
self,
750750
vuforia_database_keys: VuforiaDatabaseKeys,
751-
png_rgb: io.BytesIO,
751+
image_file_failed_state: io.BytesIO,
752752
metadata: bytes,
753753
) -> None:
754754
"""
755755
A base64 encoded string is valid application metadata.
756756
"""
757-
image_data = png_rgb.read()
757+
image_data = image_file_failed_state.read()
758758
image_data_encoded = base64.b64encode(image_data).decode('ascii')
759759
metadata_encoded = base64.b64encode(metadata).decode('ascii')
760760

@@ -775,12 +775,12 @@ def test_base64_encoded(
775775
def test_null(
776776
self,
777777
vuforia_database_keys: VuforiaDatabaseKeys,
778-
png_rgb: io.BytesIO,
778+
image_file_failed_state: io.BytesIO,
779779
) -> None:
780780
"""
781781
NULL is valid application metadata.
782782
"""
783-
image_data = png_rgb.read()
783+
image_data = image_file_failed_state.read()
784784
image_data_encoded = base64.b64encode(image_data).decode('ascii')
785785

786786
data = {
@@ -800,13 +800,13 @@ def test_null(
800800
def test_invalid_type(
801801
self,
802802
vuforia_database_keys: VuforiaDatabaseKeys,
803-
png_rgb: io.BytesIO,
803+
image_file_failed_state: io.BytesIO,
804804
) -> None:
805805
"""
806806
Values which are not a string or NULL are not valid application
807807
metadata.
808808
"""
809-
image_data = png_rgb.read()
809+
image_data = image_file_failed_state.read()
810810
image_data_encoded = base64.b64encode(image_data).decode('ascii')
811811

812812
data = {
@@ -836,12 +836,12 @@ def test_invalid_type(
836836
def test_not_base64_encoded(
837837
self,
838838
vuforia_database_keys: VuforiaDatabaseKeys,
839-
png_rgb: io.BytesIO,
839+
image_file_failed_state: io.BytesIO,
840840
) -> None:
841841
"""
842842
A string which is not base64 encoded is not valid application metadata.
843843
"""
844-
image_data = png_rgb.read()
844+
image_data = image_file_failed_state.read()
845845
image_data_encoded = base64.b64encode(image_data).decode('ascii')
846846

847847
not_base64_encoded = b'a'
@@ -870,13 +870,13 @@ def test_not_base64_encoded(
870870
def test_metadata_too_large(
871871
self,
872872
vuforia_database_keys: VuforiaDatabaseKeys,
873-
png_rgb: io.BytesIO,
873+
image_file_failed_state: io.BytesIO,
874874
) -> None:
875875
"""
876876
A base64 encoded string of greater than 1024 * 1024 bytes is too large
877877
for application metadata.
878878
"""
879-
image_data = png_rgb.read()
879+
image_data = image_file_failed_state.read()
880880
image_data_encoded = base64.b64encode(image_data).decode('ascii')
881881
metadata = b'a' * (self._MAX_METADATA_BYTES + 1)
882882
metadata_encoded = base64.b64encode(metadata).decode('ascii')
@@ -909,12 +909,12 @@ class TestInactiveProject:
909909
def test_inactive_project(
910910
self,
911911
inactive_database_keys: VuforiaDatabaseKeys,
912-
png_rgb: io.BytesIO,
912+
image_file_failed_state: io.BytesIO,
913913
) -> None:
914914
"""
915915
If the project is inactive, a FORBIDDEN response is returned.
916916
"""
917-
image_data = png_rgb.read()
917+
image_data = image_file_failed_state.read()
918918
image_data_encoded = base64.b64encode(image_data).decode('ascii')
919919

920920
data = {

tests/mock_vws/test_database_summary.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ def test_active_images(
156156
def test_failed_images(
157157
self,
158158
vuforia_database_keys: VuforiaDatabaseKeys,
159-
png_rgb: io.BytesIO,
159+
image_file_failed_state: io.BytesIO,
160160
) -> None:
161161
"""
162162
The number of images with a 'failed' status is returned.
163163
"""
164-
image_data = png_rgb.read()
164+
image_data = image_file_failed_state.read()
165165
image_data_encoded = base64.b64encode(image_data).decode('ascii')
166166

167167
data = {
@@ -232,12 +232,12 @@ def test_inactive_images(
232232
def test_inactive_failed(
233233
self,
234234
vuforia_database_keys: VuforiaDatabaseKeys,
235-
png_rgb: io.BytesIO,
235+
image_file_failed_state: io.BytesIO,
236236
) -> None:
237237
"""
238238
An image with a 'failed' status does not show as inactive.
239239
"""
240-
image_data = png_rgb.read()
240+
image_data = image_file_failed_state.read()
241241
image_data_encoded = base64.b64encode(image_data).decode('ascii')
242242

243243
data = {
@@ -270,12 +270,12 @@ def test_inactive_failed(
270270
def test_deleted(
271271
self,
272272
vuforia_database_keys: VuforiaDatabaseKeys,
273-
png_rgb: io.BytesIO,
273+
image_file_failed_state: io.BytesIO,
274274
) -> None:
275275
"""
276276
Deleted targets are not shown in the summary.
277277
"""
278-
image_data = png_rgb.read()
278+
image_data = image_file_failed_state.read()
279279
image_data_encoded = base64.b64encode(image_data).decode('ascii')
280280

281281
data = {

0 commit comments

Comments
 (0)