Skip to content

Commit 2a67c27

Browse files
committed
fix test
1 parent d70d6e1 commit 2a67c27

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

nssp/delphi_nssp/patch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ def good_patch_config(params, logger):
7474
logger.error("Custom flag is on, but patch section is missing.")
7575
valid_config = False
7676
else:
77-
required_patch_keys = ["start_issue", "end_issue", "patch_dir", "source_dir", "source_host"]
77+
required_patch_keys = ["start_issue", "end_issue", "patch_dir", "source_dir"]
7878

7979
source_dir = params["patch"]["source_dir"]
8080
if not path.isdir(source_dir) or not listdir(source_dir):
8181
required_patch_keys.append("user")
82+
required_patch_keys.append("source_host")
8283

8384
missing_keys = [key for key in required_patch_keys if key not in patch_config]
8485
if missing_keys:

nssp/delphi_nssp/pull.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,30 @@ def get_source_data(params, logger):
5151
remote_source_files = [f"{date.strftime('%Y%m%d')}.csv.gz" for date in dates]
5252

5353
# Download source files
54-
with ssh.open_sftp() as sftp:
54+
sftp = ssh.open_sftp()
55+
try:
56+
sftp.stat(params["common"]["backup_dir"])
57+
except IOError:
58+
logger.error("Source backup directory does not exist on the remote server.")
59+
60+
sftp.chdir(params["common"]["backup_dir"])
61+
62+
num_files_transferred = 0
63+
for remote_file_name in remote_source_files:
64+
callback_for_filename = functools.partial(print_callback, remote_file_name, logger, progress_chunks=[0, 50])
65+
local_file_path = path.join(params["patch"]["source_dir"], remote_file_name)
5566
try:
56-
sftp.stat(params["common"]["backup_dir"])
67+
sftp.stat(remote_file_name)
5768
except IOError:
58-
logger.error("Source backup directory does not exist on the remote server.")
59-
60-
sftp.chdir(params["common"]["backup_dir"])
61-
62-
num_files_transferred = 0
63-
for remote_file_name in remote_source_files:
64-
callback_for_filename = functools.partial(print_callback, remote_file_name, logger, progress_chunks=[0, 50])
65-
local_file_path = path.join(params["patch"]["source_dir"], remote_file_name)
66-
try:
67-
sftp.stat(remote_file_name)
68-
except IOError:
69-
logger.warning(
70-
"Source backup for this date does not exist on the remote server.",
71-
missing_filename=remote_file_name,
72-
)
73-
continue
74-
sftp.get(remote_file_name, local_file_path, callback=callback_for_filename)
75-
logger.info("Transfer finished", remote_file_name=remote_file_name, local_file_path=local_file_path)
76-
num_files_transferred += 1
69+
logger.warning(
70+
"Source backup for this date does not exist on the remote server.",
71+
missing_filename=remote_file_name,
72+
)
73+
continue
74+
sftp.get(remote_file_name, local_file_path, callback=callback_for_filename)
75+
logger.info("Transfer finished", remote_file_name=remote_file_name, local_file_path=local_file_path)
76+
num_files_transferred += 1
77+
ssh.close()
7778

7879
if num_files_transferred == 0:
7980
logger.error("No source data was transferred. Check the source backup server for potential issues.")

nssp/tests/test_patch.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_config_all_valid_configurations(self, mock_logger):
9999
mock_logger.info.assert_called_once_with("Good patch configuration.")
100100

101101
@mock_patch('logging.Logger')
102-
def test_config_user_param(self, mock_logger):
102+
def test_config_user_and_host_param(self, mock_logger):
103103
# Case 6.1: pre-existing local source data,
104104
# so no "user" param in patch section needed
105105
patch_config = {
@@ -110,13 +110,12 @@ def test_config_user_param(self, mock_logger):
110110
"patch_dir": "dir",
111111
"start_issue": "2024-04-21",
112112
"end_issue": "2024-04-22",
113-
"source_dir": "./source_dir",
114-
"source_host": "prod.server.edu"
113+
"source_dir": "./source_dir"
115114
}
116115
}
117116
assert good_patch_config(patch_config, mock_logger)
118117

119-
# Case 6.2: source_dir does not exist, so "user" param is needed
118+
# Case 6.2: source_dir does not exist, so "user" and "source_host" param is needed
120119
patch_config = {
121120
"common": {
122121
"custom_run": True,
@@ -130,7 +129,7 @@ def test_config_user_param(self, mock_logger):
130129
}
131130
assert not good_patch_config(patch_config, mock_logger)
132131
mock_logger.error.assert_has_calls([
133-
call("Patch section is missing required key(s)", missing_keys=["user"]),
132+
call("Patch section is missing required key(s)", missing_keys=["user", "source_host"]),
134133
])
135134

136135
def test_get_patch_dates(self):

0 commit comments

Comments
 (0)