def test_reserve_tcp_port(): pm = PortManager() project = Project(project_id=str(uuid.uuid4())) pm.reserve_tcp_port(2001, project) with patch("gns3server.compute.project.Project.emit") as mock_emit: port = pm.reserve_tcp_port(2001, project) assert port != 2001
def test_reserve_tcp_port(): pm = PortManager() project = Project(project_id=str(uuid.uuid4())) pm.reserve_tcp_port(2001, project) with patch("gns3server.compute.project.Project.emit") as mock_emit: port = pm.reserve_tcp_port(2001, project) assert port != 2001
def test_reserve_tcp_port_outside_range(): pm = PortManager() project = Project(project_id=str(uuid.uuid4())) with patch("gns3server.compute.project.Project.emit") as mock_emit: port = pm.reserve_tcp_port(80, project) assert port != 80
def test_reserve_tcp_port_already_used(): """ This test simulate a scenario where the port is already taken by another programm on the server """ pm = PortManager() project = Project(project_id=str(uuid.uuid4())) with patch("gns3server.compute.port_manager.PortManager._check_port") as mock_check: def execute_mock(host, port, *args): if port == 2001: raise OSError("Port is already used") else: return True mock_check.side_effect = execute_mock with patch("gns3server.compute.project.Project.emit") as mock_emit: port = pm.reserve_tcp_port(2001, project) assert port != 2001
def test_reserve_tcp_port_already_used(): """ This test simulate a scenario where the port is already taken by another program on the server """ pm = PortManager() project = Project(project_id=str(uuid.uuid4())) with patch("gns3server.compute.port_manager.PortManager._check_port" ) as mock_check: def execute_mock(host, port, *args): if port == 2001: raise OSError("Port is already used") else: return True mock_check.side_effect = execute_mock with patch("gns3server.compute.project.Project.emit"): port = pm.reserve_tcp_port(2001, project) assert port != 2001
def test_reserve_tcp_port_outside_range(): pm = PortManager() project = Project(project_id=str(uuid.uuid4())) with patch("gns3server.compute.project.Project.emit") as mock_emit: port = pm.reserve_tcp_port(80, project) assert port != 80