From 02b3aa05a049f70686dfc95e0d7160e9613f660d Mon Sep 17 00:00:00 2001 From: Katie Mazaitis Date: Thu, 6 Jan 2022 10:12:29 -0500 Subject: [PATCH 1/2] [chng] Update expected file count We now get an additional file for flu inpatient. --- changehc/delphi_changehc/download_ftp_files.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changehc/delphi_changehc/download_ftp_files.py b/changehc/delphi_changehc/download_ftp_files.py index 8a1cb1d67..46846102b 100644 --- a/changehc/delphi_changehc/download_ftp_files.py +++ b/changehc/delphi_changehc/download_ftp_files.py @@ -32,8 +32,8 @@ def get_files_from_dir(sftp, filedate, out_path): not path.exists(path.join(out_path, filename)): filepaths_to_download[filename] = path.join(out_path, filename) - # make sure we don't download more than 6 files per day - assert len(filepaths_to_download) <= 6, "more files dropped than expected" + # make sure we don't download more than 7 files per day + assert len(filepaths_to_download) <= 7, "more files dropped than expected" # download! for infile, outfile in filepaths_to_download.items(): From cd05134afafb3ecd51b733c091ce476096e11df0 Mon Sep 17 00:00:00 2001 From: Kathryn M Mazaitis Date: Thu, 6 Jan 2022 12:52:33 -0500 Subject: [PATCH 2/2] Factor out constant and update tests --- changehc/delphi_changehc/constants.py | 2 ++ .../delphi_changehc/download_ftp_files.py | 5 +++-- changehc/tests/test_download_ftp_files.py | 21 ++++++++----------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/changehc/delphi_changehc/constants.py b/changehc/delphi_changehc/constants.py index 38ee1e2c1..c934c556a 100644 --- a/changehc/delphi_changehc/constants.py +++ b/changehc/delphi_changehc/constants.py @@ -9,3 +9,5 @@ NA = "NA" HRR = "hrr" FIPS = "fips" + +EXPECTED_FILES_PER_DROP = 7 diff --git a/changehc/delphi_changehc/download_ftp_files.py b/changehc/delphi_changehc/download_ftp_files.py index 46846102b..f85ef9944 100644 --- a/changehc/delphi_changehc/download_ftp_files.py +++ b/changehc/delphi_changehc/download_ftp_files.py @@ -8,6 +8,7 @@ # third party import paramiko +from .constants import EXPECTED_FILES_PER_DROP def print_callback(filename, bytes_so_far, bytes_total): """Log file transfer progress.""" @@ -32,8 +33,8 @@ def get_files_from_dir(sftp, filedate, out_path): not path.exists(path.join(out_path, filename)): filepaths_to_download[filename] = path.join(out_path, filename) - # make sure we don't download more than 7 files per day - assert len(filepaths_to_download) <= 7, "more files dropped than expected" + # make sure we don't download too many files per day + assert len(filepaths_to_download) <= EXPECTED_FILES_PER_DROP, "more files dropped than expected" # download! for infile, outfile in filepaths_to_download.items(): diff --git a/changehc/tests/test_download_ftp_files.py b/changehc/tests/test_download_ftp_files.py index 8e8dd45c1..0338e2cd4 100644 --- a/changehc/tests/test_download_ftp_files.py +++ b/changehc/tests/test_download_ftp_files.py @@ -6,6 +6,7 @@ # first party from delphi_changehc.download_ftp_files import * +from delphi_changehc.constants import EXPECTED_FILES_PER_DROP class TestDownloadFTPFiles: @@ -51,22 +52,18 @@ def test_get_files(self, mock_path): get_files_from_dir(one_new_one_old, "00005566", "") assert one_new_one_old.num_gets == 1 - # When seven new files are present, AssertionError - new_file1 = self.FileAttr(dt.timestamp(dt.now()), "00001122_foo1") - new_file2 = self.FileAttr(dt.timestamp(dt.now()), "00001122_foo2") - new_file3 = self.FileAttr(dt.timestamp(dt.now()), "00001122_foo3") - new_file4 = self.FileAttr(dt.timestamp(dt.now()), "00001122_foo4") - new_file5 = self.FileAttr(dt.timestamp(dt.now()), "00001122_foo5") - new_file6 = self.FileAttr(dt.timestamp(dt.now()), "00001122_foo6") - new_file7 = self.FileAttr(dt.timestamp(dt.now()), "00001122_foo7") - seven_new = self.MockSFTP([new_file1, new_file2, new_file3, new_file4, - new_file5, new_file6, new_file7]) + # When too many new files are present, AssertionError + file_batch = [ + self.FileAttr(dt.timestamp(dt.now()), f"00001122_foo{i}") + for i in range(EXPECTED_FILES_PER_DROP + 1) + ] + too_many_new = self.MockSFTP(file_batch) with pytest.raises(AssertionError): - get_files_from_dir(seven_new, "00001122", "") + get_files_from_dir(too_many_new, "00001122", "") # When the file already exists, no files are downloaded mock_path.exists.return_value = True - one_exists = self.MockSFTP([new_file1]) + one_exists = self.MockSFTP([file_batch[0]]) get_files_from_dir(one_new, "00001122", "") assert one_exists.num_gets == 0