Skip to content

Commit 1a3b26d

Browse files
authored
fix: cover explicit blob media type (#232)
## Summary - add regression coverage that `cwms-cli blob upload --media-type ...` uses the supplied media type - ensure upload does not fall back to file-extension media guessing when an explicit media type is provided Resolves #49 ## Validation - `poetry run pytest tests/commands/test_blob_upload.py -q` - `poetry run pytest -q` - `poetry check`
1 parent a5b596c commit 1a3b26d

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

tests/commands/test_blob_upload.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,57 @@ class FakeHTTPError(Exception):
9797
assert calls == ["A", "B"]
9898

9999

100+
def test_upload_cmd_uses_supplied_media_type_without_guessing(
101+
tmp_path, monkeypatch: pytest.MonkeyPatch
102+
):
103+
input_file = tmp_path / "hello.unknown"
104+
input_file.write_text("hello", encoding="utf-8")
105+
stored = []
106+
107+
class FakeCwms:
108+
@staticmethod
109+
def init_session(api_root, api_key):
110+
return None
111+
112+
@staticmethod
113+
def store_blobs(blob, fail_if_exists):
114+
stored.append((blob, fail_if_exists))
115+
116+
monkeypatch.setitem(sys.modules, "cwms", FakeCwms)
117+
118+
class FakeHTTPError(Exception):
119+
pass
120+
121+
monkeypatch.setitem(
122+
sys.modules, "requests", types.SimpleNamespace(HTTPError=FakeHTTPError)
123+
)
124+
monkeypatch.setattr(
125+
"cwmscli.commands.blob.get_media_type",
126+
lambda path: (_ for _ in ()).throw(
127+
AssertionError("media type should not be guessed")
128+
),
129+
)
130+
131+
upload_cmd(
132+
input_file=str(input_file),
133+
input_dir=None,
134+
file_regex=".*",
135+
recursive=False,
136+
blob_id="HELLO.TXT",
137+
blob_id_prefix="",
138+
description="Test File!",
139+
media_type="plain/text",
140+
overwrite=False,
141+
dry_run=False,
142+
office="SWT",
143+
api_root="https://example.test/",
144+
api_key="x",
145+
)
146+
147+
assert len(stored) == 1
148+
assert stored[0][0]["media-type-id"] == "plain/text"
149+
150+
100151
def test_find_blob_id_collisions_detects_same_stem_and_path_collisions():
101152
matches = [
102153
("C:/tmp/a.txt", "a.txt"),

0 commit comments

Comments
 (0)