mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-26 15:44:34 +02:00
refactor(gns3server,tests): StrEnum, ASYNC109 and others
This commit is contained in:
54 files changed
+195
-165
No files matched your search
@@ -40,7 +40,7 @@ async def _connect(port):
|
||||
)
|
||||
|
||||
|
||||
async def _wait_for_session_count(server, expected_count, timeout=2):
|
||||
async def _wait_for_session_count(server, expected_count, timeout=2): # noqa: ASYNC109 - mock signature must match patched API
|
||||
deadline = asyncio.get_running_loop().time() + timeout
|
||||
last_count = 0
|
||||
while asyncio.get_running_loop().time() < deadline:
|
||||
|
||||
@@ -24,7 +24,7 @@ def _get_listen_port(server):
|
||||
return server.sockets[0].getsockname()[1]
|
||||
|
||||
|
||||
async def _wait_for_connection_count(server, expected_count, timeout=2):
|
||||
async def _wait_for_connection_count(server, expected_count, timeout=2): # noqa: ASYNC109 - mock signature must match patched API
|
||||
deadline = asyncio.get_running_loop().time() + timeout
|
||||
last_count = 0
|
||||
while asyncio.get_running_loop().time() < deadline:
|
||||
|
||||
@@ -4,6 +4,7 @@ Unit tests for packet filter validation.
|
||||
|
||||
import pytest
|
||||
|
||||
from gns3server.utils import packet_filter_validation
|
||||
from gns3server.utils.packet_filter_validation import (
|
||||
FilterValidationError,
|
||||
filter_inactive_filters,
|
||||
@@ -105,15 +106,26 @@ class TestPacketFilterValidation:
|
||||
validate_filter_parameters("bpf", ["tcp port 80\nnot arp"])
|
||||
validate_filter_parameters("bpf", ["tcp and not port 22\nhost 192.168.1.1\nicmp"])
|
||||
|
||||
def test_bpf_multi_line_invalid(self):
|
||||
def test_bpf_multi_line_invalid(self, monkeypatch):
|
||||
"""Test multi-line BPF with invalid line."""
|
||||
monkeypatch.setattr(
|
||||
packet_filter_validation,
|
||||
"validate_bpf_syntax",
|
||||
lambda expression: {"valid": expression != "invalid!!!", "error": "syntax error"},
|
||||
)
|
||||
with pytest.raises(FilterValidationError) as excinfo:
|
||||
validate_filter_parameters("bpf", ["tcp port 80\ninvalid!!!"])
|
||||
err = str(excinfo.value).lower()
|
||||
assert "syntax error" in err
|
||||
|
||||
def test_bpf_invalid(self):
|
||||
def test_bpf_invalid(self, monkeypatch):
|
||||
"""Test invalid BPF parameters."""
|
||||
monkeypatch.setattr(
|
||||
packet_filter_validation,
|
||||
"validate_bpf_syntax",
|
||||
lambda expression: {"valid": expression != "tcp port", "error": "syntax error"},
|
||||
)
|
||||
|
||||
# Wrong type
|
||||
with pytest.raises(FilterValidationError, match="must be a string"):
|
||||
validate_filter_parameters("bpf", [123])
|
||||
|
||||
Reference in new issue
Block a user