Skip to content

Commit cd05134

Browse files
committed
Factor out constant and update tests
1 parent 02b3aa0 commit cd05134

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

changehc/delphi_changehc/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
NA = "NA"
1010
HRR = "hrr"
1111
FIPS = "fips"
12+
13+
EXPECTED_FILES_PER_DROP = 7

changehc/delphi_changehc/download_ftp_files.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# third party
99
import paramiko
1010

11+
from .constants import EXPECTED_FILES_PER_DROP
1112

1213
def print_callback(filename, bytes_so_far, bytes_total):
1314
"""Log file transfer progress."""
@@ -32,8 +33,8 @@ def get_files_from_dir(sftp, filedate, out_path):
3233
not path.exists(path.join(out_path, filename)):
3334
filepaths_to_download[filename] = path.join(out_path, filename)
3435

35-
# make sure we don't download more than 7 files per day
36-
assert len(filepaths_to_download) <= 7, "more files dropped than expected"
36+
# make sure we don't download too many files per day
37+
assert len(filepaths_to_download) <= EXPECTED_FILES_PER_DROP, "more files dropped than expected"
3738

3839
# download!
3940
for infile, outfile in filepaths_to_download.items():

changehc/tests/test_download_ftp_files.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
# first party
88
from delphi_changehc.download_ftp_files import *
9+
from delphi_changehc.constants import EXPECTED_FILES_PER_DROP
910

1011
class TestDownloadFTPFiles:
1112

@@ -51,22 +52,18 @@ def test_get_files(self, mock_path):
5152
get_files_from_dir(one_new_one_old, "00005566", "")
5253
assert one_new_one_old.num_gets == 1
5354

54-
# When seven new files are present, AssertionError
55-
new_file1 = self.FileAttr(dt.timestamp(dt.now()), "00001122_foo1")
56-
new_file2 = self.FileAttr(dt.timestamp(dt.now()), "00001122_foo2")
57-
new_file3 = self.FileAttr(dt.timestamp(dt.now()), "00001122_foo3")
58-
new_file4 = self.FileAttr(dt.timestamp(dt.now()), "00001122_foo4")
59-
new_file5 = self.FileAttr(dt.timestamp(dt.now()), "00001122_foo5")
60-
new_file6 = self.FileAttr(dt.timestamp(dt.now()), "00001122_foo6")
61-
new_file7 = self.FileAttr(dt.timestamp(dt.now()), "00001122_foo7")
62-
seven_new = self.MockSFTP([new_file1, new_file2, new_file3, new_file4,
63-
new_file5, new_file6, new_file7])
55+
# When too many new files are present, AssertionError
56+
file_batch = [
57+
self.FileAttr(dt.timestamp(dt.now()), f"00001122_foo{i}")
58+
for i in range(EXPECTED_FILES_PER_DROP + 1)
59+
]
60+
too_many_new = self.MockSFTP(file_batch)
6461
with pytest.raises(AssertionError):
65-
get_files_from_dir(seven_new, "00001122", "")
62+
get_files_from_dir(too_many_new, "00001122", "")
6663

6764
# When the file already exists, no files are downloaded
6865
mock_path.exists.return_value = True
69-
one_exists = self.MockSFTP([new_file1])
66+
one_exists = self.MockSFTP([file_batch[0]])
7067
get_files_from_dir(one_new, "00001122", "")
7168
assert one_exists.num_gets == 0
7269

0 commit comments

Comments
 (0)