UT: Split test_target_machine_not_exists

This commit is contained in:
Kekoa Kaaikala 2022-09-30 19:54:52 +00:00
parent 28560bd65d
commit 3b6a0cd6af
1 changed files with 18 additions and 9 deletions

View File

@ -161,22 +161,31 @@ def handler(scan_event_handler, request):
return getattr(scan_event_handler, request.param) return getattr(scan_event_handler, request.param)
@pytest.mark.parametrize( def test_ping_scan_event_target_machine_not_exists(
"event,handler", scan_event_handler, machine_repository: IMachineRepository
[(PING_SCAN_EVENT, HANDLE_PING_SCAN_METHOD), (TCP_SCAN_EVENT, HANDLE_TCP_SCAN_METHOD)], ):
indirect=["handler"], event = PING_SCAN_EVENT
)
def test_target_machine_not_exists(event, handler, machine_repository: IMachineRepository):
machine_repository.get_machines_by_ip = MagicMock(side_effect=UnknownRecordError) 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 = Machine(id=SEED_ID, network_interfaces=[IPv4Interface(event.target)])
if event == PING_SCAN_EVENT:
expected_machine.operating_system = event.os expected_machine.operating_system = event.os
machine_repository.upsert_machine.assert_called_with(expected_machine) 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)])
machine_repository.upsert_machine.assert_called_with(expected_machine)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"event,handler", "event,handler",
[(PING_SCAN_EVENT, HANDLE_PING_SCAN_METHOD), (TCP_SCAN_EVENT, HANDLE_TCP_SCAN_METHOD)], [(PING_SCAN_EVENT, HANDLE_PING_SCAN_METHOD), (TCP_SCAN_EVENT, HANDLE_TCP_SCAN_METHOD)],