UT: Fix tcp_scanner tests to patch the time function

This commit is contained in:
Ilija Lazoroski 2022-09-30 16:50:37 +02:00
parent 9154f6f9dc
commit 3f89e50930
1 changed files with 5 additions and 6 deletions

View File

@ -1,4 +1,3 @@
import time
from unittest.mock import MagicMock from unittest.mock import MagicMock
import pytest import pytest
@ -19,12 +18,11 @@ TIMESTAMP = 123.321
HOST_IP = "127.0.0.1" HOST_IP = "127.0.0.1"
@pytest.fixture(scope="module") @pytest.fixture(autouse=True)
def patch_timestamp(monkeypatch): def patch_timestamp(monkeypatch):
monkeypatch.setattr( monkeypatch.setattr(
time, "infection_monkey.network_scanning.tcp_scanner.time",
"time", lambda: TIMESTAMP,
TIMESTAMP,
) )
@ -32,7 +30,7 @@ def patch_timestamp(monkeypatch):
def patch_check_tcp_ports(monkeypatch, open_ports_data): def patch_check_tcp_ports(monkeypatch, open_ports_data):
monkeypatch.setattr( monkeypatch.setattr(
"infection_monkey.network_scanning.tcp_scanner._check_tcp_ports", "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( return TCPScanEvent(
source=get_agent_id(), source=get_agent_id(),
target=HOST_IP, target=HOST_IP,
timestamp=TIMESTAMP,
ports=port_statuses, ports=port_statuses,
) )