Skip to content

Commit

Permalink
Fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-riggs committed Feb 10, 2025
1 parent d2a839c commit b785044
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/cryoemservices/cli/dlq_rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ def run() -> None:
)

if args.messages:
if isinstance(args.messages, str):
extra_messages = list(Path(".").glob(args.messages))
if len(args.messages) == 1:
extra_messages = list(Path(".").glob(args.messages[0]))
else:
extra_messages = args.messages
extra_messages = [Path(msg) for msg in args.messages]
dlq_reinject(
extra_messages,
float(args.wait),
Expand Down
47 changes: 45 additions & 2 deletions tests/cli/test_dlq_rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ def test_rabbitmq_dlq_purge_reinject_remove(

@mock.patch("cryoemservices.cli.dlq_rabbitmq.dlq_reinject")
@mock.patch("cryoemservices.cli.dlq_rabbitmq.check_dlq_rabbitmq")
def test_rabbitmq_dlq_reinject_extras(mock_check, mock_reinject, config_file, tmp_path):
def test_rabbitmq_dlq_reinject_extras_string(
mock_check, mock_reinject, config_file, tmp_path
):
"""Test that the messages glob happens as expected through the CLI"""
os.chdir(tmp_path)
(tmp_path / "DLQ").mkdir()
Expand Down Expand Up @@ -364,6 +366,47 @@ def test_rabbitmq_dlq_reinject_extras(mock_check, mock_reinject, config_file, tm
assert mock_reinject.call_args_list[0][0][3] is False


@mock.patch("cryoemservices.cli.dlq_rabbitmq.dlq_reinject")
@mock.patch("cryoemservices.cli.dlq_rabbitmq.check_dlq_rabbitmq")
def test_rabbitmq_dlq_reinject_extras_list(
mock_check, mock_reinject, config_file, tmp_path
):
"""Test that a list of messages can be sent through the CLI"""
os.chdir(tmp_path)
(tmp_path / "DLQ").mkdir()
for i in range(4):
(tmp_path / f"DLQ/msg0{i}").touch()

sys.argv = [
"cryoemservices.dlq_rabbitmq",
"--config_file",
str(config_file),
"--messages",
"DLQ/msg00",
"DLQ/msg01",
"DLQ/msg02",
]
dlq_rabbitmq.run()

# DLQ checks are always run
mock_check.assert_called_once()

# The provided messages should have been reinjected
mock_reinject.assert_called_once()
assert len(mock_reinject.call_args_list) == 1
assert len(mock_reinject.call_args_list[0][0]) == 4
assert sorted(mock_reinject.call_args_list[0][0][0]) == [
Path("DLQ/msg00"),
Path("DLQ/msg01"),
Path("DLQ/msg02"),
]
assert mock_reinject.call_args_list[0][0][1] == 0.0
assert (
mock_reinject.call_args_list[0][0][2] == tmp_path / "rabbitmq-credentials.yaml"
)
assert mock_reinject.call_args_list[0][0][3] is False


def test_dlq_rabbitmq_exists():
"""Test the DLQ check CLI is made"""
result = subprocess.run(
Expand All @@ -382,5 +425,5 @@ def test_dlq_rabbitmq_exists():
)
assert cleaned_help_line == (
"usage:cryoemservices.dlq_rabbitmq[-h]-cCONFIG_FILE[-qQUEUE]"
"[--reinject][-mMESSAGES][--remove][-wWAIT][--skip_checks]"
"[--reinject][-m[MESSAGES...]][--remove][-wWAIT][--skip_checks]"
)

0 comments on commit b785044

Please sign in to comment.