Skip to content

Commit 1727032

Browse files
Fix: ingester tests and move_to_failed_dir (#1602)
* fix: correct move to fail dir * fix: remove unnecessary unit test patches Removes patches to os.join side_effects
1 parent 73fdd99 commit 1727032

File tree

2 files changed

+3
-29
lines changed

2 files changed

+3
-29
lines changed

backend/kernelCI_app/management/commands/helpers/kcidbng_ingester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def process_file(
311311

312312
if "error" in metadata:
313313
try:
314-
move_file_to_failed_dir(os.path.join(file.path, file.name), failed_dir)
314+
move_file_to_failed_dir(file.path, failed_dir)
315315
except Exception:
316316
pass
317317
return False

backend/kernelCI_app/tests/unitTests/commands/monitorSubmissions/file_utils_test.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -238,52 +238,26 @@ def test_verify_dir_not_writable(self, mock_access, mock_isdir, mock_exists):
238238

239239
class TestVerifySpoolDirs:
240240
@patch("kernelCI_app.management.commands.helpers.file_utils.verify_dir")
241-
@patch("os.path.join")
242-
def test_verify_spool_dirs_success(self, mock_join, mock_verify_dir):
241+
def test_verify_spool_dirs_success(self, mock_verify_dir):
243242
"""Test verify_spool_dirs with successful directory verification."""
244243
joined_fail_dir = "/".join([SPOOL_DIR_TESTING, FAIL_SPOOL_SUBDIR])
245244
joined_archive_dir = "/".join([SPOOL_DIR_TESTING, ARCHIVE_SPOOL_SUBDIR])
246-
mock_join.side_effect = [joined_fail_dir, joined_archive_dir]
247245

248246
verify_spool_dirs(SPOOL_DIR_TESTING)
249247

250-
assert mock_join.call_count == 2
251-
mock_join.assert_any_call(SPOOL_DIR_TESTING, FAIL_SPOOL_SUBDIR)
252-
mock_join.assert_any_call(SPOOL_DIR_TESTING, ARCHIVE_SPOOL_SUBDIR)
253-
254248
assert mock_verify_dir.call_count == 3
255249
mock_verify_dir.assert_any_call(SPOOL_DIR_TESTING)
256250
mock_verify_dir.assert_any_call(joined_fail_dir)
257251
mock_verify_dir.assert_any_call(joined_archive_dir)
258252

259253
@patch("kernelCI_app.management.commands.helpers.file_utils.verify_dir")
260-
@patch("os.path.join")
261-
def test_verify_spool_dirs_join_failure(self, mock_join, mock_verify_dir):
262-
"""Test verify_spool_dirs when os.path.join fails."""
263-
mock_join.side_effect = TypeError("Really any Exception, this is an example")
264-
265-
with pytest.raises(TypeError):
266-
verify_spool_dirs(SPOOL_DIR_TESTING)
267-
268-
mock_join.assert_called_once_with(SPOOL_DIR_TESTING, FAIL_SPOOL_SUBDIR)
269-
mock_verify_dir.assert_not_called()
270-
271-
@patch("kernelCI_app.management.commands.helpers.file_utils.verify_dir")
272-
@patch("os.path.join")
273-
def test_verify_spool_dirs_verify_spool_dir_fails(self, mock_join, mock_verify_dir):
254+
def test_verify_spool_dirs_verify_spool_dir_fails(self, mock_verify_dir):
274255
"""Test verify_spool_dirs when spool directory verification fails."""
275-
joined_fail_dir = "/".join([SPOOL_DIR_TESTING, FAIL_SPOOL_SUBDIR])
276-
joined_archive_dir = "/".join([SPOOL_DIR_TESTING, ARCHIVE_SPOOL_SUBDIR])
277-
mock_join.side_effect = [joined_fail_dir, joined_archive_dir]
278256

279257
# Meant to represent any kind of failure in verify_dir
280258
mock_verify_dir.side_effect = Exception("Spool directory verification failed")
281259

282260
with pytest.raises(Exception, match="Spool directory verification failed"):
283261
verify_spool_dirs(SPOOL_DIR_TESTING)
284262

285-
assert mock_join.call_count == 2
286-
mock_join.assert_any_call(SPOOL_DIR_TESTING, FAIL_SPOOL_SUBDIR)
287-
mock_join.assert_any_call(SPOOL_DIR_TESTING, ARCHIVE_SPOOL_SUBDIR)
288-
289263
mock_verify_dir.assert_called_once_with(SPOOL_DIR_TESTING)

0 commit comments

Comments
 (0)