Commit a0de331f authored by narugo1992's avatar narugo1992
Browse files

dev(narugo): add unittest for blob url export and invalid case

parent 8c26c2a5
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -7,6 +7,24 @@ from test.testings import get_testfile

@pytest.mark.unittest
class TestDataBlob:
    @pytest.mark.parametrize(*tmatrix({
        'filename': [
            'mostima_post.jpg',
            'soldiers.jpg',
            'nian.png',
        ],
        ('format', 'mimetype'): [
            ('jpg', 'image/jpeg'),
            ('jpeg', 'image/jpeg'),
            ('png', 'image/png'),
            ('webp', 'image/webp'),
        ]
    }, mode='matrix'))
    def test_to_blob_url_format_check(self, filename, format, mimetype):
        original_image = load_image(get_testfile(filename), mode='RGB', force_background='white')
        blob_url = to_blob_url(original_image, format=format)
        assert blob_url.startswith(f'data:{mimetype};base64,')

    @pytest.mark.parametrize(*tmatrix({
        'filename': [
            'mostima_post.jpg',
@@ -15,6 +33,7 @@ class TestDataBlob:
        ],
        'format': [
            'jpg',
            'jpeg',
            'png',
            'webp',
        ]
@@ -27,6 +46,10 @@ class TestDataBlob:
            throw_exception=False,
        ) < 1.5e-2

    def test_load_image_from_blob_url_invalid_encode_method(self):
        with pytest.raises(ValueError):
            load_image_from_blob_url('data:image/webp;xxxxxx,abcde12345')

    @pytest.mark.parametrize(['blob_url', 'expected_result'], [
        ("data:image/png;base64,ABC", True),
        ("DATA:IMAGE/JPEG,", True),