Skip to content

Commit a1a377d

Browse files
committed
Expand test stub
1 parent 2839449 commit a1a377d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/mock_vws/test_query.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,57 @@ def test_jpeg(
11441144
We do not test exactly at this limit, but that may be beneficial in the
11451145
future.
11461146
"""
1147+
documented_max_bytes = 2 * 512
1148+
width = height = 835
1149+
png_not_too_large = make_image_file(
1150+
file_format='JPEG',
1151+
color_space='RGB',
1152+
width=width,
1153+
height=height,
1154+
)
1155+
1156+
image_content = png_not_too_large.getvalue()
1157+
body = {'image': ('image.jpeg', image_content, 'image/jpeg')}
1158+
1159+
image_content_size = len(image_content)
1160+
# We check that the image we created is just slightly smaller than the
1161+
# maximum file size.
1162+
#
1163+
# This is just because of the implementation details of ``image_file``.
1164+
assert image_content_size < documented_max_bytes
1165+
assert (image_content_size * 1.05) > documented_max_bytes
1166+
1167+
response = query(
1168+
vuforia_database_keys=vuforia_database_keys,
1169+
body=body,
1170+
)
1171+
1172+
assert_query_success(response=response)
1173+
assert response.json()['results'] == []
1174+
1175+
width = height = 836
1176+
png_not_too_large = make_image_file(
1177+
file_format='JPEG',
1178+
color_space='RGB',
1179+
width=width,
1180+
height=height,
1181+
)
1182+
1183+
image_content = png_not_too_large.getvalue()
1184+
body = {'image': ('image.jpeg', image_content, 'image/jpeg')}
1185+
image_content_size = len(image_content)
1186+
# We check that the image we created is just slightly larger than the
1187+
# maximum file size.
1188+
#
1189+
# This is just because of the implementation details of ``image_file``.
1190+
assert image_content_size > documented_max_bytes
1191+
assert (image_content_size * 0.95) < documented_max_bytes
1192+
1193+
with pytest.raises(requests.exceptions.ConnectionError):
1194+
query(
1195+
vuforia_database_keys=vuforia_database_keys,
1196+
body=body,
1197+
)
11471198

11481199

11491200
@pytest.mark.usefixtures('verify_mock_vuforia')

0 commit comments

Comments
 (0)