-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
name: seed | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from typing import Optional, Tuple, cast | ||
import pytest | ||
from io import BytesIO | ||
|
||
from core_utilities.shared.file import FileContent, with_content_type | ||
|
||
|
||
def test_file_content_bytes() -> None: | ||
result = with_content_type(file=b"file content", content_type="text/plain") | ||
assert result == (None, b"file content", "text/plain") | ||
|
||
def test_file_content_str() -> None: | ||
result = with_content_type(file="file content", content_type="text/plain") | ||
assert result == (None, "file content", "text/plain") | ||
|
||
def test_file_content_io() -> None: | ||
file_like = BytesIO(b"file content") | ||
result = with_content_type(file=file_like, content_type="text/plain") | ||
filename, content, contentType = cast(Tuple[Optional[str], FileContent, Optional[str]], result) | ||
assert filename is None | ||
assert content == file_like | ||
assert contentType == "text/plain" | ||
|
||
def test_tuple_2() -> None: | ||
result = with_content_type(file=("example.txt", b"file content"), content_type="text/plain") | ||
assert result == ("example.txt", b"file content", "text/plain") | ||
|
||
def test_tuple_3() -> None: | ||
result = with_content_type(file=("example.txt", b"file content", "application/octet-stream"), content_type="text/plain") | ||
assert result == ("example.txt", b"file content", "text/plain") | ||
|
||
def test_tuple_4() -> None: | ||
result = with_content_type(file=("example.txt", b"file content", "application/octet-stream", {"X-Custom": "value"}), content_type="text/plain") | ||
assert result == ("example.txt", b"file content", "text/plain", {"X-Custom": "value"}) | ||
|
||
def test_none_filename() -> None: | ||
result = with_content_type(file=(None, b"file content"), content_type="text/plain") | ||
assert result == (None, b"file content", "text/plain") | ||
|
||
def test_invalid_tuple_length() -> None: | ||
with pytest.raises(ValueError): | ||
with_content_type( | ||
file=("example.txt", b"file content", "text/plain", {}, "extra"), # type: ignore | ||
content_type="application/json" | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.