From 0bf9309e075f3a12c3eeb2008f38b403bee49da0 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Fri, 30 Sep 2022 13:48:35 +0530 Subject: [PATCH] UT: Assert mock_agent_event_queue.publish's call counts in test_tcp_scanner.py --- .../infection_monkey/network_scanning/test_tcp_scanner.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/monkey/tests/unit_tests/infection_monkey/network_scanning/test_tcp_scanner.py b/monkey/tests/unit_tests/infection_monkey/network_scanning/test_tcp_scanner.py index 3e0c38d7e..578f57508 100644 --- a/monkey/tests/unit_tests/infection_monkey/network_scanning/test_tcp_scanner.py +++ b/monkey/tests/unit_tests/infection_monkey/network_scanning/test_tcp_scanner.py @@ -38,6 +38,8 @@ def test_tcp_successful( assert port_scan_data[port].status == PortStatus.CLOSED assert port_scan_data[port].banner is None + assert mock_agent_event_queue.publish.call_count == 1 + @pytest.mark.parametrize("open_ports_data", [{}]) def test_tcp_empty_response( @@ -51,6 +53,8 @@ def test_tcp_empty_response( assert port_scan_data[port].status == PortStatus.CLOSED assert port_scan_data[port].banner is None + assert mock_agent_event_queue.publish.call_count == 1 + @pytest.mark.parametrize("open_ports_data", [OPEN_PORTS_DATA]) def test_tcp_no_ports_to_scan( @@ -59,6 +63,7 @@ def test_tcp_no_ports_to_scan( port_scan_data = scan_tcp_ports("127.0.0.1", [], 0, mock_agent_event_queue) assert len(port_scan_data) == 0 + assert mock_agent_event_queue.publish.call_count == 1 def test_exception_handling(monkeypatch, mock_agent_event_queue): @@ -67,3 +72,4 @@ def test_exception_handling(monkeypatch, mock_agent_event_queue): MagicMock(side_effect=Exception), ) assert scan_tcp_ports("abc", [123], 123, mock_agent_event_queue) == EMPTY_PORT_SCAN + assert mock_agent_event_queue.publish.call_count == 0