Add tests for port and protocol validation and update changelog
This commit is contained in:
@@ -0,0 +1 @@
|
||||
# © Crown-owned copyright 2024, Defence Science and Technology Laboratory UK
|
||||
@@ -0,0 +1,23 @@
|
||||
# © Crown-owned copyright 2024, Defence Science and Technology Laboratory UK
|
||||
import pytest
|
||||
|
||||
from primaite.utils.validation.ip_protocol import IPProtocol, is_valid_protocol, PROTOCOL_LOOKUP, protocol_validator
|
||||
|
||||
|
||||
def test_port_conversion():
|
||||
for proto_name, proto_val in PROTOCOL_LOOKUP.items():
|
||||
assert protocol_validator(proto_name) == proto_val
|
||||
assert is_valid_protocol(proto_name)
|
||||
|
||||
|
||||
def test_port_passthrough():
|
||||
for proto_val in PROTOCOL_LOOKUP.values():
|
||||
assert protocol_validator(proto_val) == proto_val
|
||||
assert is_valid_protocol(proto_val)
|
||||
|
||||
|
||||
def test_invalid_ports():
|
||||
for port in (123, "abcdefg", "NONEXISTENT_PROTO"):
|
||||
with pytest.raises(ValueError):
|
||||
protocol_validator(port)
|
||||
assert not is_valid_protocol(port)
|
||||
25
tests/unit_tests/_primaite/_utils/_validation/test_port.py
Normal file
25
tests/unit_tests/_primaite/_utils/_validation/test_port.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# © Crown-owned copyright 2024, Defence Science and Technology Laboratory UK
|
||||
import pytest
|
||||
|
||||
from primaite.utils.validation.port import is_valid_port, Port, PORT_LOOKUP, port_validator
|
||||
|
||||
|
||||
def test_port_conversion():
|
||||
valid_port_lookup = {k: v for k, v in PORT_LOOKUP.items() if k != "UNUSED"}
|
||||
for port_name, port_val in valid_port_lookup.items():
|
||||
assert port_validator(port_name) == port_val
|
||||
assert is_valid_port(port_name)
|
||||
|
||||
|
||||
def test_port_passthrough():
|
||||
valid_port_lookup = {k: v for k, v in PORT_LOOKUP.items() if k != "UNUSED"}
|
||||
for port_val in valid_port_lookup.values():
|
||||
assert port_validator(port_val) == port_val
|
||||
assert is_valid_port(port_val)
|
||||
|
||||
|
||||
def test_invalid_ports():
|
||||
for port in (999999, -20, 3.214, "NONEXISTENT_PORT"):
|
||||
with pytest.raises(ValueError):
|
||||
port_validator(port)
|
||||
assert not is_valid_port(port)
|
||||
Reference in New Issue
Block a user