fix: Blob.from_data mimetype is lost (#5395)

# Fix lost mimetype when using Blob.from_data method

The mimetype is lost due to a typo in the class attribue name

Fixes # - (no issue opened but I can open one if needed)

## Changes

* Fixed typo in name
* Added unit-tests to validate the output Blob


## Review
@eyurtsev
This commit is contained in:
Gael Grosch 2023-05-29 15:36:50 +02:00 committed by GitHub
parent f77f27163d
commit 8b7721ebbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -137,7 +137,7 @@ class Blob(BaseModel):
Returns:
Blob instance
"""
return cls(data=data, mime_type=mime_type, encoding=encoding, path=path)
return cls(data=data, mimetype=mime_type, encoding=encoding, path=path)
def __repr__(self) -> str:
"""Define the blob representation."""

View File

@ -70,6 +70,29 @@ def test_blob_from_str_path() -> None:
assert bytes_io.read() == content
def test_blob_from_str_data() -> None:
"""Test reading blob from a file path."""
content = b"Hello, World!"
blob = Blob.from_data(content)
assert blob.encoding == "utf-8" # Default encoding
assert blob.path is None
assert blob.mimetype is None
assert blob.source is None
assert blob.data == b"Hello, World!"
assert blob.as_bytes() == content
assert blob.as_string() == "Hello, World!"
with blob.as_bytes_io() as bytes_io:
assert bytes_io.read() == content
def test_blob_mimetype_from_str_data() -> None:
"""Test reading blob from a file path."""
content = b"Hello, World!"
mimetype = "text/html"
blob = Blob.from_data(content, mime_type=mimetype)
assert blob.mimetype == mimetype
@pytest.mark.parametrize(
"path, mime_type, guess_type, expected_mime_type",
[