|
15 | 15 | from tests.mock_vws.utils import ( |
16 | 16 | add_target_to_vws, |
17 | 17 | delete_target, |
| 18 | + make_image_file, |
18 | 19 | wait_for_target_processed, |
19 | 20 | ) |
20 | 21 | from tests.mock_vws.utils.assertions import ( |
@@ -468,63 +469,34 @@ def test_corrupted( |
468 | 469 |
|
469 | 470 | assert_success(response=response) |
470 | 471 |
|
471 | | - def test_jpeg_too_large( |
| 472 | + def test_image_too_large( |
472 | 473 | self, |
473 | 474 | vuforia_database_keys: VuforiaDatabaseKeys, |
474 | | - png_large: io.BytesIO, |
475 | 475 | ) -> None: |
476 | 476 | """ |
477 | | - foobar todo update docstring |
478 | 477 | An `ImageTooLarge` result is returned if the image is above a certain |
479 | 478 | threshold. |
480 | | -
|
481 | | - This threshold is documented as being 2 MB but it is actually |
482 | | - slightly larger. See the `png_large` fixture for more details. |
483 | 479 | """ |
484 | | - original_data = png_large.getvalue() |
485 | | - longer_data = original_data.replace(b'IEND', b'\x00' + b'IEND') |
486 | | - too_large_file = io.BytesIO(longer_data) |
487 | | - |
488 | | - image_data = too_large_file.read() |
489 | | - image_data_encoded = base64.b64encode(image_data).decode('ascii') |
490 | | - |
491 | | - data = { |
492 | | - 'name': 'example_name', |
493 | | - 'width': 1, |
494 | | - 'image': image_data_encoded, |
495 | | - } |
496 | | - |
497 | | - response = add_target_to_vws( |
498 | | - vuforia_database_keys=vuforia_database_keys, |
499 | | - data=data, |
| 480 | + max_bytes = 2 * 1024 * 1024 |
| 481 | + width = height = 835 |
| 482 | + png_not_too_large = make_image_file( |
| 483 | + file_format='PNG', |
| 484 | + color_space='RGB', |
| 485 | + width=width, |
| 486 | + height=height, |
500 | 487 | ) |
501 | 488 |
|
502 | | - assert_vws_failure( |
503 | | - response=response, |
504 | | - status_code=codes.UNPROCESSABLE_ENTITY, |
505 | | - result_code=ResultCodes.IMAGE_TOO_LARGE, |
506 | | - ) |
507 | | - |
508 | | - def test_png_too_large( |
509 | | - self, |
510 | | - vuforia_database_keys: VuforiaDatabaseKeys, |
511 | | - png_large: io.BytesIO, |
512 | | - ) -> None: |
513 | | - """ |
514 | | - foobar todo update docstring |
515 | | - An `ImageTooLarge` result is returned if the image is above a certain |
516 | | - threshold. |
517 | | -
|
518 | | - This threshold is documented as being 2 MB but it is actually |
519 | | - slightly larger. See the `png_large` fixture for more details. |
520 | | - """ |
521 | | - original_data = png_large.getvalue() |
522 | | - longer_data = original_data.replace(b'IEND', b'\x00' + b'IEND') |
523 | | - too_large_file = io.BytesIO(longer_data) |
524 | | - |
525 | | - image_data = too_large_file.read() |
| 489 | + image_data = png_not_too_large.read() |
526 | 490 | image_data_encoded = base64.b64encode(image_data).decode('ascii') |
527 | 491 |
|
| 492 | + image_content_size = len(image_data) |
| 493 | + # We check that the image we created is just slightly smaller than the |
| 494 | + # maximum file size. |
| 495 | + # |
| 496 | + # This is just because of the implementation details of ``image_file``. |
| 497 | + assert image_content_size < max_bytes |
| 498 | + assert (image_content_size * 1.05) > max_bytes |
| 499 | + |
528 | 500 | data = { |
529 | 501 | 'name': 'example_name', |
530 | 502 | 'width': 1, |
|
0 commit comments