コード例 #1
0
    def test_from_data_uri_to_bytes_content_and_extension(
        self, dummy_content_and_data_uri
    ):
        content, dummy_data_uri = dummy_content_and_data_uri
        data_uri = DataURI(dummy_data_uri)

        content_file, extension = data_uri.to_content_bytes_and_extension()

        assert extension == ".pdf"
        assert type(content_file) == bytes
        assert content_file == content
コード例 #2
0
    def test_make_data_uri_from_file(self, asset_path_filename):
        data_uri_from_file = DataURI.from_file(asset_path_filename)

        assert type(data_uri_from_file) == DataURI
        assert data_uri_from_file.mimetype == "image/svg+xml"
        assert data_uri_from_file.is_base64
        assert type(data_uri_from_file.data) == bytes
コード例 #3
0
    def test_from_string_to_data_uri_non_b64(self, dummy_content_and_data_uri_non_b64):
        content, dummy_data_uri = dummy_content_and_data_uri_non_b64
        data_uri = DataURI(dummy_data_uri)

        assert type(data_uri) == DataURI
        assert data_uri.mimetype == "text/plain"
        assert not data_uri.is_base64
        assert type(data_uri.data) == str
        assert data_uri.data == content
コード例 #4
0
    def test_from_string_to_data_uri(self, dummy_content_and_data_uri):
        content, dummy_data_uri = dummy_content_and_data_uri
        data_uri = DataURI(dummy_data_uri)

        assert type(data_uri) == DataURI
        assert data_uri.mimetype == "application/pdf"
        assert data_uri.is_base64
        assert type(data_uri.data) == bytes
        assert data_uri.data == content
コード例 #5
0
    def test_make_data_uri_from_response(self, dummy_response_object):
        content_response = b"{'key_1': 'value', 'key_2': 'another'}"
        response = dummy_response_object("application/json", content_response)

        data_uri_from_file = DataURI.from_response(response)

        assert type(data_uri_from_file) == DataURI
        assert data_uri_from_file.mimetype == "application/json"
        assert data_uri_from_file.is_base64
        assert type(data_uri_from_file.data) == bytes
        assert data_uri_from_file.data == content_response
コード例 #6
0
    def test_from_mimetype_and_data_to_data_uri(self):
        mimetype = "image/png"
        data = b"some png data"

        data_uri = DataURI.make(mimetype, data)

        assert type(data_uri) == DataURI
        assert data_uri.mimetype == mimetype
        assert data_uri.is_base64
        assert type(data_uri.data) == bytes
        assert data_uri.data == data
コード例 #7
0
    def test_make_data_uri_from_stream(self, dummy_stream_object):
        content_file = b"content of a file"
        stream = dummy_stream_object("test.txt", content_file)

        data_uri_from_file = DataURI.from_stream(stream)

        assert type(data_uri_from_file) == DataURI
        assert data_uri_from_file.mimetype == "text/plain"
        assert data_uri_from_file.is_base64
        assert type(data_uri_from_file.data) == bytes
        assert data_uri_from_file.data == content_file
        assert data_uri_from_file == "data:text/plain;base64,Y29udGVudCBvZiBhIGZpbGU="
コード例 #8
0
    def test_from_bytes_not_valid_uri(self):
        data_uri_bytes = b"data:application/pdf;base64,c29tZSBieXRlcyBvZiBhIFBERg=="

        with pytest.raises(DataURIValueError):
            DataURI(data_uri_bytes)
コード例 #9
0
    def test_not_valid_uri_format(self):
        data_uri = "some plain data not uri format"

        with pytest.raises(DataURIValueError):
            DataURI(data_uri)
コード例 #10
0
    def test_make_data_uri_from_response_unknown(self, dummy_response_object):
        content_response = b"{'key_1': 'value', 'key_2': 'another'}"
        response = dummy_response_object("not valid content", content_response)

        with pytest.raises(ValueError):
            DataURI.from_response(response)