Skip to content

Commit 1fea9a0

Browse files
committed
test: add test for overwriting 0-size file when overwrite=False
1 parent a3030c9 commit 1fea9a0

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

tests/archive_file/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ def params_location():
1818
def params_location_multiple_pages(params_location):
1919
# rowLimit should be less than the total number of rows.
2020
return params_location | {"rowLimit": 2}
21+
22+
23+
@pytest.fixture
24+
def params_location_single_file(params_location):
25+
# Returned archivefile name should be BPR-Folger-59_20191126T000000.000Z.txt
26+
return params_location | {"dateFrom": "2019-11-26", "dateTo": "2019-11-27"}

tests/archive_file/test_archivefile_direct_download.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import os
2+
3+
14
def test_valid_params_one_page(requester, params_location, util):
25
data = requester.getArchivefile(params_location)
36
result = requester.downloadDirectArchivefile(params_location)
@@ -16,3 +19,24 @@ def test_valid_params_multiple_pages(requester, params_location_multiple_pages,
1619
)
1720

1821
assert result["stats"]["fileCount"] == params_location_multiple_pages["rowLimit"]
22+
23+
24+
def test_valid_params_overwrite_zero_file_size(
25+
requester, params_location_single_file, util
26+
):
27+
filename = "BPR-Folger-59_20191126T000000.000Z.txt"
28+
29+
file_path = requester.outPath / filename
30+
31+
# Touch an empty file
32+
with open(file_path, "w"):
33+
pass
34+
35+
# Case when downloading failed, leaving an empty file behind
36+
assert os.path.getsize(file_path) == 0
37+
38+
requester.downloadDirectArchivefile(params_location_single_file, overwrite=False)
39+
40+
assert (
41+
os.path.getsize(file_path) != 0
42+
), "0-size file should be overwritten even if overwrite is False"

tests/archive_file/test_archivefile_download.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import pytest
24
import requests
35

@@ -25,3 +27,22 @@ def test_valid_params(requester, util):
2527
requester.downloadArchivefile(filename, overwrite=True)
2628

2729
assert util.get_download_files_num(requester) == 1
30+
31+
32+
def test_valid_params_overwrite_zero_file_size(requester):
33+
filename = "BPR-Folger-59_20191123T000000.000Z.txt"
34+
35+
file_path = requester.outPath / filename
36+
37+
# Touch an empty file
38+
with open(file_path, "w"):
39+
pass
40+
41+
# Case when downloading failed, leaving an empty file behind
42+
assert os.path.getsize(file_path) == 0
43+
44+
requester.downloadArchivefile(filename, overwrite=False)
45+
46+
assert (
47+
os.path.getsize(file_path) != 0
48+
), "0-size file should be overwritten even if overwrite is False"

0 commit comments

Comments
 (0)