Exemple #1
0
def test_upload_image_to_s3_and_store_in_db_saves_filename_in_correct_format(mockdata, test_png_BytesIO, client):
    mocked_connection = Mock()
    mocked_resource = Mock()

    with patch('boto3.client', Mock(return_value=mocked_connection)):
        with patch('boto3.resource', Mock(return_value=mocked_resource)):
            upload = upload_image_to_s3_and_store_in_db(test_png_BytesIO, 1, 1)
            filename = upload.filepath.split('/')[-1]
            filename_parts = filename.split('.')
            assert len(filename_parts) == 2
Exemple #2
0
def test_upload_image_to_s3_and_store_in_db_does_not_throw_exception_for_recognized_format(mockdata, test_png_BytesIO, client):
    try:
        upload_image_to_s3_and_store_in_db(test_png_BytesIO, 1, 1)
    except ValueError:
        pytest.fail("Unexpected value error")
Exemple #3
0
def test_upload_image_to_s3_and_store_in_db_throws_exception_for_unrecognized_format(mockdata, client):
    with pytest.raises(ValueError):
        upload_image_to_s3_and_store_in_db(BytesIO(b'invalid-image'), 1, 1)
Exemple #4
0
def test_upload_image_to_s3_and_store_in_db_does_not_set_tagged(mockdata, test_png_BytesIO, client):
    upload = upload_image_to_s3_and_store_in_db(test_png_BytesIO, 1, 1)
    assert not upload.is_tagged
Exemple #5
0
def test_upload_existing_image_to_s3_and_store_in_db_returns_existing_image(mockdata, test_png_BytesIO, client):
    firstUpload = upload_image_to_s3_and_store_in_db(test_png_BytesIO, 1, 1)
    secondUpload = upload_image_to_s3_and_store_in_db(test_png_BytesIO, 1, 1)
    assert type(secondUpload) == Image
    assert firstUpload.id == secondUpload.id
Exemple #6
0
def test_upload_image_to_s3_and_store_in_db_increases_images_in_db(mockdata, test_png_BytesIO, client):
    original_image_count = Image.query.count()

    upload_image_to_s3_and_store_in_db(test_png_BytesIO, 1, 1)
    assert Image.query.count() == original_image_count + 1