From 3f89e50930d9a4c18bf7c3fae37fb46d18fbd82a Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Fri, 30 Sep 2022 16:50:37 +0200 Subject: [PATCH] UT: Fix tcp_scanner tests to patch the time function --- .../network_scanning/test_tcp_scanner.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 17acd421a..f3c897f11 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 @@ -1,4 +1,3 @@ -import time from unittest.mock import MagicMock import pytest @@ -19,12 +18,11 @@ TIMESTAMP = 123.321 HOST_IP = "127.0.0.1" -@pytest.fixture(scope="module") +@pytest.fixture(autouse=True) def patch_timestamp(monkeypatch): monkeypatch.setattr( - time, - "time", - TIMESTAMP, + "infection_monkey.network_scanning.tcp_scanner.time", + lambda: TIMESTAMP, ) @@ -32,7 +30,7 @@ def patch_timestamp(monkeypatch): def patch_check_tcp_ports(monkeypatch, open_ports_data): monkeypatch.setattr( "infection_monkey.network_scanning.tcp_scanner._check_tcp_ports", - lambda *_: open_ports_data, + lambda *_: (TIMESTAMP, open_ports_data), ) @@ -44,6 +42,7 @@ def _get_tcp_scan_event(port_scan_data: PortScanData): return TCPScanEvent( source=get_agent_id(), target=HOST_IP, + timestamp=TIMESTAMP, ports=port_statuses, )