Add tests for network node adding/removal

This commit is contained in:
Marek Wolan
2023-08-24 10:26:17 +01:00
parent a82ffb9747
commit 4077eb3a5c
3 changed files with 60 additions and 2 deletions

View File

@@ -0,0 +1,38 @@
import pytest
from primaite.simulator.network.container import NetworkContainer
from primaite.simulator.network.hardware.base import Node
def test_adding_removing_nodes():
"""Check that we can create and add a node to a network."""
net = NetworkContainer()
n1 = Node(hostname="computer")
net.add_node(n1)
assert n1.parent is net
assert n1 in net
net.remove_node(n1)
assert n1.parent is None
assert n1 not in net
def test_readding_node():
"""Check that warning is raised when readding a node."""
net = NetworkContainer()
n1 = Node(hostname="computer")
net.add_node(n1)
with pytest.raises(RuntimeWarning):
net.add_node(n1)
assert n1.parent is net
assert n1 in net
def test_removing_nonexistent_node():
"""Check that warning is raised when trying to remove a node that is not in the network."""
net = NetworkContainer()
n1 = Node(hostname="computer")
with pytest.raises(RuntimeWarning):
net.remove_node(n1)
assert n1.parent is None
assert n1 not in net