Skip to content

Commit a899a84

Browse files
committed
TST: add test to break download by adding wrong content
1 parent c577dce commit a899a84

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

dandi/tests/test_download.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ def test_download_000027_assets_only(url: str, tmp_path: Path) -> None:
122122
@mark.skipif_no_network
123123
@pytest.mark.parametrize("resizer", [lambda sz: 0, lambda sz: sz // 2, lambda sz: sz])
124124
@pytest.mark.parametrize("version", ["0.210831.2033", DRAFT])
125+
@pytest.mark.parametrize("break_download", [False, True])
125126
def test_download_000027_resume(
126-
tmp_path: Path, resizer: Callable[[int], int], version: str
127+
tmp_path: Path, resizer: Callable[[int], int], version: str, break_download: bool
127128
) -> None:
128129
url = f"https://dandiarchive.org/dandiset/000027/{version}"
129130
digester = Digester()
@@ -137,15 +138,25 @@ def test_download_000027_resume(
137138
nwb.rename(dlfile)
138139
size = dlfile.stat().st_size
139140
os.truncate(dlfile, resizer(size))
141+
if break_download:
142+
bad_load = b"bad"
143+
if resizer(size) == size: # no truncation
144+
os.truncate(dlfile, size - len(bad_load))
145+
with open(dlfile, "ab") as f:
146+
f.write(bad_load)
140147
with (dldir / "checksum").open("w") as fp:
141148
json.dump(digests, fp)
149+
142150
download(url, tmp_path, get_metadata=False)
143151
assert list_paths(dsdir, dirs=True) == [
144152
dsdir / "sub-RAT123",
145153
dsdir / "sub-RAT123" / "sub-RAT123.nwb",
146154
]
147155
assert nwb.stat().st_size == size
148-
assert digester(str(nwb)) == digests
156+
if break_download:
157+
assert digester(str(nwb)) != digests
158+
else:
159+
assert digester(str(nwb)) == digests
149160

150161

151162
def test_download_newest_version(text_dandiset: SampleDandiset, tmp_path: Path) -> None:

0 commit comments

Comments
 (0)