mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-11-16 16:54:51 +02:00
Support of supplier and variables in topology
This commit is contained in:
parent
e4436096c2
commit
f2700ed445
@ -85,6 +85,8 @@ def project_to_topology(project):
|
||||
"show_grid": project.show_grid,
|
||||
"grid_size": project.grid_size,
|
||||
"show_interface_labels": project.show_interface_labels,
|
||||
"variables": project.variables,
|
||||
"supplier": project.supplier,
|
||||
"topology": {
|
||||
"nodes": [],
|
||||
"links": [],
|
||||
|
@ -23,6 +23,8 @@ from gns3server.schemas.compute import COMPUTE_OBJECT_SCHEMA
|
||||
from gns3server.schemas.drawing import DRAWING_OBJECT_SCHEMA
|
||||
from gns3server.schemas.link import LINK_OBJECT_SCHEMA
|
||||
from gns3server.schemas.node import NODE_OBJECT_SCHEMA
|
||||
from gns3server.schemas.project import VARIABLES_OBJECT_SCHEMA
|
||||
from gns3server.schemas.project import SUPPLIER_OBJECT_SCHEMA
|
||||
|
||||
|
||||
TOPOLOGY_SCHEMA = {
|
||||
@ -97,6 +99,8 @@ TOPOLOGY_SCHEMA = {
|
||||
"type": "boolean",
|
||||
"description": "Show interface labels on the drawing area"
|
||||
},
|
||||
"supplier": SUPPLIER_OBJECT_SCHEMA,
|
||||
"variables": VARIABLES_OBJECT_SCHEMA,
|
||||
"topology": {
|
||||
"description": "The topology content",
|
||||
"type": "object",
|
||||
|
@ -81,6 +81,26 @@ def test_basic_topology(tmpdir, async_run, controller):
|
||||
assert topo["topology"]["drawings"][0] == drawing.__json__(topology_dump=True)
|
||||
|
||||
|
||||
def test_project_to_topology(tmpdir, controller):
|
||||
variables = [
|
||||
{"name": "TEST1"},
|
||||
{"name": "TEST2", "value": "value1"}
|
||||
]
|
||||
supplier = {
|
||||
'logo': 'logo.png',
|
||||
'url': 'http://example.com'
|
||||
}
|
||||
|
||||
project = Project(name="Test", controller=controller)
|
||||
compute = Compute("my_compute", controller)
|
||||
compute.http_query = MagicMock()
|
||||
project.variables = variables
|
||||
project.supplier = supplier
|
||||
topo = project_to_topology(project)
|
||||
assert topo["variables"] == variables
|
||||
assert topo["supplier"] == supplier
|
||||
|
||||
|
||||
def test_load_topology(tmpdir):
|
||||
data = {
|
||||
"project_id": "69f26504-7aa3-48aa-9f29-798d44841211",
|
||||
@ -137,3 +157,55 @@ def test_load_newer_topology(tmpdir):
|
||||
json.dump(data, f)
|
||||
with pytest.raises(aiohttp.web.HTTPConflict):
|
||||
topo = load_topology(path)
|
||||
|
||||
|
||||
def test_load_topology_with_variables(tmpdir):
|
||||
variables = [
|
||||
{"name": "TEST1"},
|
||||
{"name": "TEST2", "value": "value1"}
|
||||
]
|
||||
data = {
|
||||
"project_id": "69f26504-7aa3-48aa-9f29-798d44841211",
|
||||
"name": "Test",
|
||||
"revision": GNS3_FILE_FORMAT_REVISION,
|
||||
"topology": {
|
||||
"nodes": [],
|
||||
"links": [],
|
||||
"computes": [],
|
||||
"drawings": []
|
||||
},
|
||||
"variables": variables,
|
||||
"type": "topology",
|
||||
"version": __version__}
|
||||
|
||||
path = str(tmpdir / "test.gns3")
|
||||
with open(path, "w+") as f:
|
||||
json.dump(data, f)
|
||||
topo = load_topology(path)
|
||||
assert topo == data
|
||||
|
||||
|
||||
def test_load_topology_with_supplier(tmpdir):
|
||||
supplier = {
|
||||
'logo': 'logo.png',
|
||||
'url': 'http://example.com'
|
||||
}
|
||||
data = {
|
||||
"project_id": "69f26504-7aa3-48aa-9f29-798d44841211",
|
||||
"name": "Test",
|
||||
"revision": GNS3_FILE_FORMAT_REVISION,
|
||||
"topology": {
|
||||
"nodes": [],
|
||||
"links": [],
|
||||
"computes": [],
|
||||
"drawings": []
|
||||
},
|
||||
"supplier": supplier,
|
||||
"type": "topology",
|
||||
"version": __version__}
|
||||
|
||||
path = str(tmpdir / "test.gns3")
|
||||
with open(path, "w+") as f:
|
||||
json.dump(data, f)
|
||||
topo = load_topology(path)
|
||||
assert topo == data
|
@ -104,6 +104,20 @@ def test_update_project(http_controller):
|
||||
assert response.json["name"] == "test2"
|
||||
|
||||
|
||||
def test_update_project_with_variables(http_controller):
|
||||
variables = [
|
||||
{"name": "TEST1"},
|
||||
{"name": "TEST2", "value": "value1"}
|
||||
]
|
||||
query = {"name": "test", "project_id": "10010203-0405-0607-0809-0a0b0c0d0e0f", "variables": variables}
|
||||
response = http_controller.post("/projects", query)
|
||||
assert response.status == 201
|
||||
query = {"name": "test2"}
|
||||
response = http_controller.put("/projects/10010203-0405-0607-0809-0a0b0c0d0e0f", query, example=True)
|
||||
assert response.status == 200
|
||||
assert response.json["variables"] == variables
|
||||
|
||||
|
||||
def test_list_projects(http_controller, tmpdir):
|
||||
http_controller.post("/projects", {"name": "test", "path": str(tmpdir), "project_id": "00010203-0405-0607-0809-0a0b0c0d0e0f"})
|
||||
response = http_controller.get("/projects", example=True)
|
||||
|
Loading…
Reference in New Issue
Block a user