UT: Use constants for TCP and ping scan method names

This commit is contained in:
Mike Salvatore 2022-09-30 12:53:47 -04:00
parent 20b84aa1a4
commit 79f56e0789
1 changed files with 14 additions and 10 deletions

View File

@ -161,6 +161,10 @@ class error_machine_by_ip:
return machines return machines
HANDLE_PING_SCAN_METHOD = "handle_ping_scan_event"
HANDLE_TCP_SCAN_METHOD = "handle_tcp_scan_event"
@pytest.fixture @pytest.fixture
def handler(scan_event_handler, request): def handler(scan_event_handler, request):
return getattr(scan_event_handler, request.param) return getattr(scan_event_handler, request.param)
@ -168,7 +172,7 @@ def handler(scan_event_handler, request):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"event,handler", "event,handler",
[(PING_SCAN_EVENT, "handle_ping_scan_event"), (TCP_SCAN_EVENT, "handle_tcp_scan_event")], [(PING_SCAN_EVENT, HANDLE_PING_SCAN_METHOD), (TCP_SCAN_EVENT, HANDLE_TCP_SCAN_METHOD)],
indirect=["handler"], indirect=["handler"],
) )
def test_scan_event_handler__target_machine_not_exists( def test_scan_event_handler__target_machine_not_exists(
@ -187,7 +191,7 @@ def test_scan_event_handler__target_machine_not_exists(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"event,handler", "event,handler",
[(PING_SCAN_EVENT, "handle_ping_scan_event"), (TCP_SCAN_EVENT, "handle_tcp_scan_event")], [(PING_SCAN_EVENT, HANDLE_PING_SCAN_METHOD), (TCP_SCAN_EVENT, HANDLE_TCP_SCAN_METHOD)],
indirect=["handler"], indirect=["handler"],
) )
def test_scan_event_handler__upserts_node( def test_scan_event_handler__upserts_node(
@ -209,7 +213,7 @@ def test_scan_event_handler__upserts_node(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"event,handler", "event,handler",
[(PING_SCAN_EVENT, "handle_ping_scan_event"), (TCP_SCAN_EVENT, "handle_tcp_scan_event")], [(PING_SCAN_EVENT, HANDLE_PING_SCAN_METHOD), (TCP_SCAN_EVENT, HANDLE_TCP_SCAN_METHOD)],
indirect=["handler"], indirect=["handler"],
) )
def test_scan_event_handler__node_not_upserted_if_no_matching_agent( def test_scan_event_handler__node_not_upserted_if_no_matching_agent(
@ -230,7 +234,7 @@ def test_scan_event_handler__node_not_upserted_if_no_matching_agent(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"event,handler", "event,handler",
[(PING_SCAN_EVENT, "handle_ping_scan_event"), (TCP_SCAN_EVENT, "handle_tcp_scan_event")], [(PING_SCAN_EVENT, HANDLE_PING_SCAN_METHOD), (TCP_SCAN_EVENT, HANDLE_TCP_SCAN_METHOD)],
indirect=["handler"], indirect=["handler"],
) )
def test_scan_event_handler__node_not_upserted_if_machine_retrievalerror( def test_scan_event_handler__node_not_upserted_if_machine_retrievalerror(
@ -256,8 +260,8 @@ def test_scan_event_handler__node_not_upserted_if_machine_retrievalerror(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"event,handler", "event,handler",
[ [
(PING_SCAN_EVENT_NO_OS, "handle_ping_scan_event"), (PING_SCAN_EVENT_NO_OS, HANDLE_PING_SCAN_METHOD),
(TCP_SCAN_EVENT_CLOSED, "handle_tcp_scan_event"), (TCP_SCAN_EVENT_CLOSED, HANDLE_TCP_SCAN_METHOD),
], ],
indirect=["handler"], indirect=["handler"],
) )
@ -274,7 +278,7 @@ def test_scan_event_handler__machine_not_upserted(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"event,handler", "event,handler",
[(PING_SCAN_EVENT, "handle_ping_scan_event"), (TCP_SCAN_EVENT, "handle_tcp_scan_event")], [(PING_SCAN_EVENT, HANDLE_PING_SCAN_METHOD), (TCP_SCAN_EVENT, HANDLE_TCP_SCAN_METHOD)],
indirect=["handler"], indirect=["handler"],
) )
def test_scan_event_handler__machine_not_upserted_if_existing_machine_has_os( def test_scan_event_handler__machine_not_upserted_if_existing_machine_has_os(
@ -291,7 +295,7 @@ def test_scan_event_handler__machine_not_upserted_if_existing_machine_has_os(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"event,handler", "event,handler",
[(PING_SCAN_EVENT, "handle_ping_scan_event"), (TCP_SCAN_EVENT, "handle_tcp_scan_event")], [(PING_SCAN_EVENT, HANDLE_PING_SCAN_METHOD), (TCP_SCAN_EVENT, HANDLE_TCP_SCAN_METHOD)],
indirect=["handler"], indirect=["handler"],
) )
def test_scan_event_handler__node_not_upserted_if_machine_storageerror( def test_scan_event_handler__node_not_upserted_if_machine_storageerror(
@ -319,8 +323,8 @@ def test_scan_event_handler__node_not_upserted_if_machine_storageerror(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"event,handler", "event,handler",
[ [
(PING_SCAN_EVENT_NO_RESPONSE, "handle_ping_scan_event"), (PING_SCAN_EVENT_NO_RESPONSE, HANDLE_PING_SCAN_METHOD),
(TCP_SCAN_EVENT_CLOSED, "handle_tcp_scan_event"), (TCP_SCAN_EVENT_CLOSED, HANDLE_TCP_SCAN_METHOD),
], ],
indirect=["handler"], indirect=["handler"],
) )