Skip to content

Commit a4c4aec

Browse files
committed
add tests for remote source download vs local
1 parent 552d036 commit a4c4aec

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

nssp/tests/test_patch.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,59 @@ def test_get_patch_dates(self):
142142
for date in expected_dates:
143143
assert date in patch_dates
144144

145+
@mock_patch('delphi_nssp.patch.get_source_data')
146+
@mock_patch('delphi_nssp.patch.run_module')
147+
@mock_patch('delphi_nssp.patch.get_structured_logger')
148+
@mock_patch('delphi_nssp.patch.read_params')
149+
def test_patch_from_local_source(self, mock_read_params, mock_get_structured_logger, mock_run_module, mock_get_source_data):
150+
mock_read_params.return_value = {
151+
"common": {
152+
"log_filename": "test.log",
153+
"custom_run": True
154+
},
155+
"patch": {
156+
"user": "user",
157+
"start_issue": "2021-01-01",
158+
"end_issue": "2021-01-16",
159+
"patch_dir": "./patch_dir",
160+
"source_dir": "./source_dir"
161+
}
162+
}
163+
patch()
164+
165+
mock_get_source_data.assert_not_called()
166+
167+
@mock_patch('delphi_nssp.patch.get_source_data')
168+
@mock_patch('delphi_nssp.patch.rmtree')
169+
@mock_patch('delphi_nssp.patch.run_module')
170+
@mock_patch('delphi_nssp.patch.get_structured_logger')
171+
@mock_patch('delphi_nssp.patch.read_params')
172+
def test_patch_download_remote_source(self, mock_read_params, mock_get_structured_logger, mock_run_module, mock_rmtree, mock_get_source_data):
173+
mock_read_params.return_value = {
174+
"common": {
175+
"log_filename": "test.log",
176+
"custom_run": True
177+
},
178+
"patch": {
179+
"user": "user",
180+
"start_issue": "2021-01-01",
181+
"end_issue": "2021-01-16",
182+
"patch_dir": "./patch_dir",
183+
"source_dir": "./does_not_exist"
184+
}
185+
}
186+
patch()
187+
mock_get_source_data.assert_called_once()
188+
assert mock_rmtree.call_count == 1
189+
shutil.rmtree(mock_read_params.return_value["patch"]["patch_dir"])
190+
191+
145192

193+
@mock_patch('delphi_nssp.patch.get_source_data')
146194
@mock_patch('delphi_nssp.patch.run_module')
147195
@mock_patch('delphi_nssp.patch.get_structured_logger')
148196
@mock_patch('delphi_nssp.patch.read_params')
149-
def test_patch_confirm_dir_structure_created(self, mock_read_params, mock_get_structured_logger, mock_run_module):
197+
def test_patch_confirm_dir_structure_created(self, mock_read_params, mock_get_structured_logger, mock_run_module, mock_get_source_data):
150198
mock_read_params.return_value = {
151199
"common": {
152200
"log_filename": "test.log",
@@ -180,7 +228,7 @@ def test_patch_confirm_dir_structure_created(self, mock_read_params, mock_get_st
180228

181229
@mock_patch('delphi_nssp.patch.get_structured_logger')
182230
@mock_patch('delphi_nssp.patch.read_params')
183-
def test_patch_confirm_values_generated(self, mock_read_params, mock_get_structured_logger):
231+
def test_full_patch_code(self, mock_read_params, mock_get_structured_logger):
184232
mock_get_structured_logger.return_value.name = "delphi_nssp.patch"
185233
mock_read_params.return_value = {
186234
"common": {

nssp/tests/test_pull.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ def test_get_source_data(self):
4545
mock_sftp = MagicMock()
4646
mock_sftp.stat = MagicMock()
4747
mock_ssh.open_sftp.return_value = mock_sftp
48-
49-
# Mock the paramiko SSHClient
5048
with patch("paramiko.SSHClient", return_value=mock_ssh):
5149
get_source_data(params, logger)
5250

@@ -55,7 +53,7 @@ def test_get_source_data(self):
5553
assert mock_sftp.get.call_count == 3
5654

5755
@patch("delphi_nssp.pull.Socrata")
58-
def test_pull_nssp_data(self, mock_socrata, caplog):
56+
def test_normal_pull_nssp_data(self, mock_socrata, caplog):
5957
today = pd.Timestamp.today().strftime("%Y%m%d")
6058
backup_dir = 'test_raw_data_backups'
6159

0 commit comments

Comments
 (0)