From 3b6a0cd6af84233be5b4c6b981e7d529a1bc2450 Mon Sep 17 00:00:00 2001 From: Kekoa Kaaikala Date: Fri, 30 Sep 2022 19:54:52 +0000 Subject: [PATCH] UT: Split test_target_machine_not_exists --- .../test_scan_event_handler.py | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/monkey/tests/unit_tests/monkey_island/cc/agent_event_handlers/test_scan_event_handler.py b/monkey/tests/unit_tests/monkey_island/cc/agent_event_handlers/test_scan_event_handler.py index 908e17dca..ad1ced7fa 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/agent_event_handlers/test_scan_event_handler.py +++ b/monkey/tests/unit_tests/monkey_island/cc/agent_event_handlers/test_scan_event_handler.py @@ -161,19 +161,28 @@ def handler(scan_event_handler, request): return getattr(scan_event_handler, request.param) -@pytest.mark.parametrize( - "event,handler", - [(PING_SCAN_EVENT, HANDLE_PING_SCAN_METHOD), (TCP_SCAN_EVENT, HANDLE_TCP_SCAN_METHOD)], - indirect=["handler"], -) -def test_target_machine_not_exists(event, handler, machine_repository: IMachineRepository): +def test_ping_scan_event_target_machine_not_exists( + scan_event_handler, machine_repository: IMachineRepository +): + event = PING_SCAN_EVENT machine_repository.get_machines_by_ip = MagicMock(side_effect=UnknownRecordError) - handler(event) + scan_event_handler.handle_ping_scan_event(event) + + expected_machine = Machine(id=SEED_ID, network_interfaces=[IPv4Interface(event.target)]) + expected_machine.operating_system = event.os + machine_repository.upsert_machine.assert_called_with(expected_machine) + + +def test_tcp_scan_event_target_machine_not_exists( + scan_event_handler, machine_repository: IMachineRepository +): + event = TCP_SCAN_EVENT + machine_repository.get_machines_by_ip = MagicMock(side_effect=UnknownRecordError) + + scan_event_handler.handle_tcp_scan_event(event) expected_machine = Machine(id=SEED_ID, network_interfaces=[IPv4Interface(event.target)]) - if event == PING_SCAN_EVENT: - expected_machine.operating_system = event.os machine_repository.upsert_machine.assert_called_with(expected_machine)