def test_appliance_json_with_platform(): a = Appliance(None, { "node_type": "dynamips", "name": "Test", "default_name_format": "{name}-{0}", "category": 0, "symbol": "dynamips.svg", "server": "local", "platform": "c3725" }) assert a.__json__() == { "appliance_id": a.id, "node_type": "dynamips", "builtin": False, "name": "Test", "default_name_format": "{name}-{0}", "category": "router", "symbol": "dynamips.svg", "compute_id": "local", "platform": "c3725" }
def test_appliance_json_with_not_known_category(): a = Appliance(None, { "node_type": "qemu", "name": "Test", "default_name_format": "{name}-{0}", "category": 'Not known', "symbol": "qemu.svg", "server": "local", "platform": None }) assert a.__json__() == { "appliance_id": a.id, "node_type": "qemu", "builtin": False, "name": "Test", "default_name_format": "{name}-{0}", "category": "Not known", "symbol": "qemu.svg", "compute_id": "local", "platform": None }
def test_add_node_from_appliance(async_run, controller): """ For a local server we send the project path """ compute = MagicMock() compute.id = "local" project = Project(controller=controller, name="Test") controller._notification = MagicMock() controller._appliances["fakeid"] = Appliance( "fakeid", { "server": "local", "name": "Test", "default_name_format": "{name}-{0}", "node_type": "vpcs", "properties": { "a": 1 } }) controller._computes["local"] = compute response = MagicMock() response.json = {"console": 2048} compute.post = AsyncioMagicMock(return_value=response) node = async_run(project.add_node_from_appliance("fakeid", x=23, y=12)) compute.post.assert_any_call('/projects', data={ "name": project._name, "project_id": project._id, "path": project._path }) compute.post.assert_any_call('/projects/{}/vpcs/nodes'.format(project.id), data={ 'node_id': node.id, 'name': 'Test-1', 'a': 1, }, timeout=1200) assert compute in project._project_created_on_compute controller.notification.emit.assert_any_call("node.created", node.__json__()) # Make sure we can call twice the node creation node = async_run(project.add_node_from_appliance("fakeid", x=13, y=12)) compute.post.assert_any_call('/projects/{}/vpcs/nodes'.format(project.id), data={ 'node_id': node.id, 'name': 'Test-2', 'a': 1 }, timeout=1200)
def test_appliance_json_with_platform(): a = Appliance( None, { "node_type": "dynamips", "name": "Test", "default_name_format": "{name}-{0}", "category": 0, "symbol": "dynamips.svg", "server": "local", "platform": "c3725" }) assert a.__json__() == { "appliance_id": a.id, "node_type": "dynamips", "builtin": False, "name": "Test", "default_name_format": "{name}-{0}", "category": "router", "symbol": "dynamips.svg", "compute_id": "local", "platform": "c3725" }
def test_appliance_json_with_not_known_category(): a = Appliance( None, { "node_type": "qemu", "name": "Test", "default_name_format": "{name}-{0}", "category": 'Not known', "symbol": "qemu.svg", "server": "local", "platform": None }) assert a.__json__() == { "appliance_id": a.id, "node_type": "qemu", "builtin": False, "name": "Test", "default_name_format": "{name}-{0}", "category": "Not known", "symbol": "qemu.svg", "compute_id": "local", "platform": None }
def test_appliance_list(http_controller, controller): id = str(uuid.uuid4()) controller.load_appliances() controller._appliances[id] = Appliance(id, { "node_type": "qemu", "category": 0, "name": "test", "symbol": "guest.svg", "default_name_format": "{name}-{0}", "server": "local" }) response = http_controller.get("/appliances", example=True) assert response.status == 200 assert response.route == "/appliances" assert len(response.json) > 0
def test_appliance_fix_linked_base(): """ Version of the gui before 2.1 use linked_base and the server linked_clone """ a = Appliance( None, { "node_type": "qemu", "name": "Test", "default_name_format": "{name}-{0}", "category": 0, "symbol": "qemu.svg", "server": "local", "linked_base": True }) assert a.data["linked_clone"] assert "linked_base" not in a.data
def test_create_node_from_appliance(http_controller, controller, project, compute): id = str(uuid.uuid4()) controller._appliances = {id: Appliance(id, { "node_type": "qemu", "category": 0, "name": "test", "symbol": "guest.svg", "default_name_format": "{name}-{0}", "server": "example.com" })} with asyncio_patch("gns3server.controller.project.Project.add_node_from_appliance") as mock: response = http_controller.post("/projects/{}/appliances/{}".format(project.id, id), { "x": 42, "y": 12 }) mock.assert_called_with(id, x=42, y=12, compute_id=None) print(response.body) assert response.route == "/projects/{project_id}/appliances/{appliance_id}" assert response.status == 201