mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
7 files changed
+166
-20
No files matched your search
@@ -36,8 +36,12 @@ def compute():
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def node(compute, controller):
|
||||
project = Project(str(uuid.uuid4()), controller=controller)
|
||||
def project(controller):
|
||||
return Project(str(uuid.uuid4()), controller=controller)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def node(compute, project):
|
||||
node = Node(project, compute, "demo",
|
||||
node_id=str(uuid.uuid4()),
|
||||
node_type="vpcs",
|
||||
@@ -48,14 +52,14 @@ def node(compute, controller):
|
||||
|
||||
def test_json(node, compute):
|
||||
assert node.__json__() == {
|
||||
"compute_id": compute.id,
|
||||
"compute_id": str(compute.id),
|
||||
"project_id": node.project.id,
|
||||
"node_id": node.id,
|
||||
"node_type": node.node_type,
|
||||
"name": "demo",
|
||||
"console": node.console,
|
||||
"console_type": node.console_type,
|
||||
"console_host": compute.host,
|
||||
"console_host": str(compute.host),
|
||||
"command_line": None,
|
||||
"node_directory": None,
|
||||
"properties": node.properties,
|
||||
@@ -123,6 +127,7 @@ def test_update(node, compute, project, async_run, controller):
|
||||
response.json = {"console": 2048}
|
||||
compute.put = AsyncioMagicMock(return_value=response)
|
||||
controller._notification = AsyncioMagicMock()
|
||||
project.dump = MagicMock()
|
||||
|
||||
async_run(node.update(x=42, console=2048, console_type="vnc", properties={"startup_script": "echo test"}, name="demo"))
|
||||
data = {
|
||||
@@ -136,6 +141,7 @@ def test_update(node, compute, project, async_run, controller):
|
||||
assert node.x == 42
|
||||
assert node._properties == {"startup_script": "echo test"}
|
||||
controller._notification.emit.assert_called_with("node.updated", node.__json__())
|
||||
assert project.dump.called
|
||||
|
||||
|
||||
def test_update_properties(node, compute, project, async_run, controller):
|
||||
|
||||
@@ -74,13 +74,6 @@ def test_captures_directory(tmpdir):
|
||||
assert os.path.exists(p.captures_directory)
|
||||
|
||||
|
||||
def test_add_compute(async_run):
|
||||
compute = MagicMock()
|
||||
project = Project()
|
||||
async_run(project.add_compute(compute))
|
||||
assert compute in project._computes
|
||||
|
||||
|
||||
def test_add_node_local(async_run, controller):
|
||||
"""
|
||||
For a local server we send the project path
|
||||
@@ -225,3 +218,13 @@ def test_delete(async_run, project, controller):
|
||||
async_run(project.delete())
|
||||
assert not os.path.exists(project.path)
|
||||
|
||||
|
||||
def test_dump():
|
||||
directory = Config.instance().get_section_config("Server").get("projects_path")
|
||||
|
||||
with patch("gns3server.utils.path.get_default_project_directory", return_value=directory):
|
||||
p = Project(project_id='00010203-0405-0607-0809-0a0b0c0d0e0f', name="Test")
|
||||
p.dump()
|
||||
with open(os.path.join(directory, p.id, "Test.gns3")) as f:
|
||||
content = f.read()
|
||||
assert "00010203-0405-0607-0809-0a0b0c0d0e0f" in content
|
||||
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2016 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
from tests.utils import asyncio_patch
|
||||
|
||||
from gns3server.controller.project import Project
|
||||
from gns3server.controller.compute import Compute
|
||||
from gns3server.controller.topology import project_to_topology
|
||||
from gns3server.version import __version__
|
||||
|
||||
|
||||
def test_project_to_topology_empty(tmpdir):
|
||||
project = Project(name="Test")
|
||||
topo = project_to_topology(project)
|
||||
assert topo == {
|
||||
"project_id": project.id,
|
||||
"name": "Test",
|
||||
"revision": 5,
|
||||
"topology": {
|
||||
"nodes": [],
|
||||
"links": [],
|
||||
"computes": []
|
||||
},
|
||||
"type": "topology",
|
||||
"version": __version__
|
||||
}
|
||||
|
||||
|
||||
def test_basic_topology(tmpdir, async_run, controller):
|
||||
project = Project(name="Test", controller=controller)
|
||||
compute = Compute("my_compute", controller)
|
||||
compute.http_query = MagicMock()
|
||||
|
||||
with asyncio_patch("gns3server.controller.node.Node.create"):
|
||||
node1 = async_run(project.add_node(compute, "Node 1", "node_1"))
|
||||
node2 = async_run(project.add_node(compute, "Node 2", "node_2"))
|
||||
|
||||
link = async_run(project.add_link())
|
||||
async_run(link.add_node(node1, 0, 0))
|
||||
async_run(link.add_node(node2, 0, 0))
|
||||
|
||||
topo = project_to_topology(project)
|
||||
assert len(topo["topology"]["nodes"]) == 2
|
||||
assert node1.__json__() in topo["topology"]["nodes"]
|
||||
assert topo["topology"]["links"][0] == link.__json__()
|
||||
assert topo["topology"]["computes"][0] == compute.__json__()
|
||||
|
||||
Reference in new issue
Block a user