Skip to content

Commit 5e95a27

Browse files
committed
Passing tests on real
1 parent a762378 commit 5e95a27

File tree

2 files changed

+50
-66
lines changed

2 files changed

+50
-66
lines changed

tests/mock_vws/test_add_target.py

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ class TestTargetName:
204204
"""
205205

206206
_MAX_CHAR_VALUE = 65535
207+
_MAX_NAME_LENGTH = 64
207208

208209
@pytest.mark.parametrize(
209210
'name',
@@ -213,7 +214,7 @@ class TestTargetName:
213214
# This is because targets with the max character value in their
214215
# names get stuck in the processing stage.
215216
chr(_MAX_CHAR_VALUE - 2),
216-
'a' * 64,
217+
'a' * _MAX_NAME_LENGTH,
217218
],
218219
ids=['Short name', 'Max char value', 'Long name'],
219220
)
@@ -244,21 +245,37 @@ def test_name_valid(
244245
assert_success(response=response)
245246

246247
@pytest.mark.parametrize(
247-
'name',
248-
[1, '', 'a' * 65, None],
249-
ids=['Wrong Type', 'Empty', 'Too Long', 'None'],
248+
'name,status_code',
249+
[
250+
(1, codes.BAD_REQUEST),
251+
('', codes.BAD_REQUEST),
252+
('a' * (_MAX_NAME_LENGTH + 1), codes.BAD_REQUEST),
253+
(None, codes.BAD_REQUEST),
254+
(chr(_MAX_CHAR_VALUE + 1), codes.INTERNAL_SERVER_ERROR),
255+
(
256+
chr(_MAX_CHAR_VALUE + 1) *
257+
(_MAX_NAME_LENGTH + 1), codes.BAD_REQUEST,
258+
),
259+
],
260+
ids=[
261+
'Wrong Type',
262+
'Empty',
263+
'Too Long',
264+
'None',
265+
'Bad char',
266+
'Bad char too long',
267+
],
250268
)
251269
def test_name_invalid(
252270
self,
253271
name: str,
254272
png_rgb: io.BytesIO,
255273
vuforia_database_keys: VuforiaDatabaseKeys,
274+
status_code: int,
256275
) -> None:
257276
"""
258-
A target's name must be a string of length 0 < N < 65.
259-
260-
We test characters out of range in another test as that gives a
261-
different error.
277+
A target's name must be a string of length 0 < N < 65, with characters
278+
in a particular range.
262279
"""
263280
image_data = png_rgb.read()
264281
image_data_encoded = base64.b64encode(image_data).decode('ascii')
@@ -276,33 +293,7 @@ def test_name_invalid(
276293

277294
assert_vws_failure(
278295
response=response,
279-
status_code=codes.BAD_REQUEST,
280-
result_code=ResultCodes.FAIL,
281-
)
282-
283-
def test_character_out_of_range(
284-
self,
285-
png_rgb: io.BytesIO,
286-
vuforia_database_keys: VuforiaDatabaseKeys,
287-
) -> None:
288-
name = chr(self._MAX_CHAR_VALUE + 1)
289-
image_data = png_rgb.read()
290-
image_data_encoded = base64.b64encode(image_data).decode('ascii')
291-
292-
data = {
293-
'name': name,
294-
'width': 1,
295-
'image': image_data_encoded,
296-
}
297-
298-
response = add_target_to_vws(
299-
vuforia_database_keys=vuforia_database_keys,
300-
data=data,
301-
)
302-
303-
assert_vws_failure(
304-
response=response,
305-
status_code=codes.INTERNAL_SERVER_ERROR,
296+
status_code=status_code,
306297
result_code=ResultCodes.FAIL,
307298
)
308299

tests/mock_vws/test_update_target.py

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ class TestTargetName:
479479
"""
480480

481481
_MAX_CHAR_VALUE = 65535
482+
_MAX_NAME_LENGTH = 64
482483

483484
@pytest.mark.parametrize(
484485
'name',
@@ -488,7 +489,7 @@ class TestTargetName:
488489
# This is because targets with the max character value in their
489490
# names get stuck in the processing stage.
490491
chr(_MAX_CHAR_VALUE - 2),
491-
'a' * 64,
492+
'a' * _MAX_NAME_LENGTH,
492493
],
493494
ids=['Short name', 'Max char value', 'Long name'],
494495
)
@@ -529,15 +530,33 @@ def test_name_valid(
529530
assert response.json()['target_record']['name'] == name
530531

531532
@pytest.mark.parametrize(
532-
'name',
533-
[1, '', 'a' * 65, None],
534-
ids=['Wrong Type', 'Empty', 'Too Long', 'None'],
533+
'name,status_code',
534+
[
535+
(1, codes.BAD_REQUEST),
536+
('', codes.BAD_REQUEST),
537+
('a' * (_MAX_NAME_LENGTH + 1), codes.BAD_REQUEST),
538+
(None, codes.BAD_REQUEST),
539+
(chr(_MAX_CHAR_VALUE + 1), codes.INTERNAL_SERVER_ERROR),
540+
(
541+
chr(_MAX_CHAR_VALUE + 1) *
542+
(_MAX_NAME_LENGTH + 1), codes.BAD_REQUEST,
543+
),
544+
],
545+
ids=[
546+
'Wrong Type',
547+
'Empty',
548+
'Too Long',
549+
'None',
550+
'Bad char',
551+
'Bad char too long',
552+
],
535553
)
536554
def test_name_invalid(
537555
self,
538556
name: str,
539557
target_id: str,
540558
vuforia_database_keys: VuforiaDatabaseKeys,
559+
status_code: int,
541560
) -> None:
542561
"""
543562
A target's name must be a string of length 0 < N < 65.
@@ -555,33 +574,7 @@ def test_name_invalid(
555574

556575
assert_vws_failure(
557576
response=response,
558-
status_code=codes.BAD_REQUEST,
559-
result_code=ResultCodes.FAIL,
560-
)
561-
562-
def test_character_out_of_range(
563-
self,
564-
png_rgb: io.BytesIO,
565-
vuforia_database_keys: VuforiaDatabaseKeys,
566-
) -> None:
567-
name = chr(self._MAX_CHAR_VALUE + 1)
568-
image_data = png_rgb.read()
569-
image_data_encoded = base64.b64encode(image_data).decode('ascii')
570-
571-
data = {
572-
'name': name,
573-
'width': 1,
574-
'image': image_data_encoded,
575-
}
576-
577-
response = add_target_to_vws(
578-
vuforia_database_keys=vuforia_database_keys,
579-
data=data,
580-
)
581-
582-
assert_vws_failure(
583-
response=response,
584-
status_code=codes.INTERNAL_SERVER_ERROR,
577+
status_code=status_code,
585578
result_code=ResultCodes.FAIL,
586579
)
587580

0 commit comments

Comments
 (0)