2018-04-26 00:33:58 +01:00
|
|
|
import pytest
|
2019-09-11 05:33:35 +01:00
|
|
|
|
2018-05-01 18:40:25 +01:00
|
|
|
from core.emulator.emudata import NodeOptions
|
2019-04-30 07:31:47 +01:00
|
|
|
from core.emulator.enumerations import NodeTypes
|
2019-09-28 07:29:15 +01:00
|
|
|
from core.errors import CoreError
|
2018-04-26 00:33:58 +01:00
|
|
|
|
2019-09-10 23:10:24 +01:00
|
|
|
MODELS = ["router", "host", "PC", "mdr"]
|
|
|
|
NET_TYPES = [NodeTypes.SWITCH, NodeTypes.HUB, NodeTypes.WIRELESS_LAN]
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestNodes:
|
|
|
|
@pytest.mark.parametrize("model", MODELS)
|
|
|
|
def test_node_add(self, session, model):
|
|
|
|
# given
|
2019-10-22 23:31:50 +01:00
|
|
|
options = NodeOptions(model=model)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# when
|
2019-10-22 23:31:50 +01:00
|
|
|
node = session.add_node(options=options)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# then
|
|
|
|
assert node
|
|
|
|
assert node.alive()
|
|
|
|
assert node.up
|
|
|
|
|
|
|
|
def test_node_update(self, session):
|
|
|
|
# given
|
|
|
|
node = session.add_node()
|
|
|
|
position_value = 100
|
|
|
|
update_options = NodeOptions()
|
|
|
|
update_options.set_position(x=position_value, y=position_value)
|
|
|
|
|
|
|
|
# when
|
2019-10-23 04:55:06 +01:00
|
|
|
session.edit_node(node.id, update_options)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# then
|
|
|
|
assert node.position.x == position_value
|
|
|
|
assert node.position.y == position_value
|
|
|
|
|
|
|
|
def test_node_delete(self, session):
|
|
|
|
# given
|
|
|
|
node = session.add_node()
|
|
|
|
|
|
|
|
# when
|
2019-04-27 06:07:51 +01:00
|
|
|
session.delete_node(node.id)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# then
|
2019-09-11 21:12:42 +01:00
|
|
|
with pytest.raises(CoreError):
|
2019-04-30 07:31:47 +01:00
|
|
|
session.get_node(node.id)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
@pytest.mark.parametrize("net_type", NET_TYPES)
|
|
|
|
def test_net(self, session, net_type):
|
|
|
|
# given
|
|
|
|
|
|
|
|
# when
|
|
|
|
node = session.add_node(_type=net_type)
|
|
|
|
|
|
|
|
# then
|
|
|
|
assert node
|
|
|
|
assert node.up
|