mirror of
https://github.com/Cian-H/I-Form_Server_Node_Deployer.git
synced 2025-12-23 06:32:08 +00:00
Tests created for ip interface
This commit is contained in:
@@ -26,9 +26,10 @@ mkdocs-material = {extras = ["all"], version = "^9.4.8"}
|
|||||||
ruff = "^0.1.1"
|
ruff = "^0.1.1"
|
||||||
black = "^23.10.1"
|
black = "^23.10.1"
|
||||||
snoop = "^0.4.3"
|
snoop = "^0.4.3"
|
||||||
pytest = "^7.4.3"
|
|
||||||
mypy = "^1.6.1"
|
mypy = "^1.6.1"
|
||||||
docker-stubs = {git = "https://github.com/rdozier-work/docker-stubs"}
|
docker-stubs = {git = "https://github.com/rdozier-work/docker-stubs"}
|
||||||
|
pytest = "^7.4.3"
|
||||||
|
hypothesis = "^6.88.3"
|
||||||
|
|
||||||
[tool.poetry.group.docs.dependencies]
|
[tool.poetry.group.docs.dependencies]
|
||||||
mkdocs = "^1.5.3"
|
mkdocs = "^1.5.3"
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import os
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import pickle
|
import pickle
|
||||||
import shutil
|
import shutil
|
||||||
|
from ipaddress import IPv4Address, IPv6Address
|
||||||
|
|
||||||
|
from hypothesis import given
|
||||||
|
from hypothesis import strategies as st
|
||||||
from node_deployer.config import config
|
from node_deployer.config import config
|
||||||
import tomllib
|
import tomllib
|
||||||
|
|
||||||
@@ -33,7 +36,7 @@ def cleanup():
|
|||||||
|
|
||||||
atexit.register(cleanup)
|
atexit.register(cleanup)
|
||||||
|
|
||||||
from node_deployer import autoignition, create_disk, create_img # noqa: E402
|
from node_deployer import ip_interface, autoignition, create_disk, create_img # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
with open(config.PROJECT_ROOT / "tests/data/node_deployer/test_args.toml", "rb") as f:
|
with open(config.PROJECT_ROOT / "tests/data/node_deployer/test_args.toml", "rb") as f:
|
||||||
@@ -42,6 +45,62 @@ with open(config.PROJECT_ROOT / "tests/data/node_deployer/test_args.toml", "rb")
|
|||||||
TEST_DATA_DIR = config.PROJECT_ROOT / "tests/data/node_deployer"
|
TEST_DATA_DIR = config.PROJECT_ROOT / "tests/data/node_deployer"
|
||||||
|
|
||||||
|
|
||||||
|
class TestIPInterface:
|
||||||
|
TEST_ATTRS = (
|
||||||
|
"compressed",
|
||||||
|
"exploded",
|
||||||
|
"is_global",
|
||||||
|
"is_link_local",
|
||||||
|
"is_loopback",
|
||||||
|
"is_multicast",
|
||||||
|
"is_private",
|
||||||
|
"is_reserved",
|
||||||
|
"is_unspecified",
|
||||||
|
"max_prefixlen",
|
||||||
|
"packed",
|
||||||
|
"reverse_pointer",
|
||||||
|
"version",
|
||||||
|
)
|
||||||
|
|
||||||
|
@given(st.ip_addresses(v=4))
|
||||||
|
def test_ipv4_parsing(self, ip: IPv4Address):
|
||||||
|
ip_str = str(ip)
|
||||||
|
test_result = ip_interface.IPAddress(ip_str)
|
||||||
|
assert test_result.obj == ip
|
||||||
|
|
||||||
|
@given(st.ip_addresses(v=4))
|
||||||
|
def test_ipv4_attr_passthrough(self, ip: IPv4Address):
|
||||||
|
# Should be able to access all attributes of ipaddress.IPv4Address directly,
|
||||||
|
# not just a copy of the attribute object at instantiation
|
||||||
|
ip_addr = ip_interface.IPAddress(str(ip))
|
||||||
|
for attr in self.TEST_ATTRS:
|
||||||
|
assert getattr(ip_addr, attr) is getattr(ip_addr.obj, attr)
|
||||||
|
|
||||||
|
@given(st.ip_addresses(v=4))
|
||||||
|
def test_ipv4_bool(self, ip: IPv4Address):
|
||||||
|
ip_addr = ip_interface.IPAddress(str(ip))
|
||||||
|
assert bool(ip_addr) != ip.is_unspecified
|
||||||
|
|
||||||
|
@given(st.ip_addresses(v=6))
|
||||||
|
def test_ipv6_parsing(self, ip: IPv6Address):
|
||||||
|
ip_str = str(ip)
|
||||||
|
test_result = ip_interface.IPAddress(ip_str)
|
||||||
|
assert test_result.obj == ip
|
||||||
|
|
||||||
|
@given(st.ip_addresses(v=6))
|
||||||
|
def test_ipv6_attr_passthrough(self, ip: IPv6Address):
|
||||||
|
# Should be able to access all attributes of ipaddress.IPv4Address directly,
|
||||||
|
# not just a copy of the attribute object at instantiation
|
||||||
|
ip_addr = ip_interface.IPAddress(str(ip))
|
||||||
|
for attr in self.TEST_ATTRS:
|
||||||
|
assert getattr(ip_addr, attr) is getattr(ip_addr.obj, attr)
|
||||||
|
|
||||||
|
@given(st.ip_addresses(v=6))
|
||||||
|
def test_ipv6_bool(self, ip: IPv6Address):
|
||||||
|
ip_addr = ip_interface.IPAddress(str(ip))
|
||||||
|
assert bool(ip_addr) != ip.is_unspecified
|
||||||
|
|
||||||
|
|
||||||
class TestAutoignition:
|
class TestAutoignition:
|
||||||
def test_json_to_img(self, tmp_path: Path):
|
def test_json_to_img(self, tmp_path: Path):
|
||||||
tmp_path.mkdir(parents=True, exist_ok=True)
|
tmp_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user