mirror of
https://github.com/GNS3/gns3-gui.git
synced 2026-05-17 00:46:01 +03:00
Project variables and supplier
This commit is contained in:
@@ -72,6 +72,8 @@ class Project(QtCore.QObject):
|
||||
self._grid_size = graphic_settings.get("grid_size", 75)
|
||||
self._show_interface_labels = graphic_settings.get("show_interface_labels", False)
|
||||
self._show_interface_labels_on_new_project = config.showInterfaceLabelsOnNewProject()
|
||||
self._variables = None
|
||||
self._supplier = None
|
||||
|
||||
self._name = "untitled"
|
||||
self._filename = None
|
||||
@@ -208,6 +210,32 @@ class Project(QtCore.QObject):
|
||||
"""
|
||||
return self._show_interface_labels
|
||||
|
||||
def setVariables(self, variables):
|
||||
"""
|
||||
Sets variables of project
|
||||
"""
|
||||
self._variables = variables
|
||||
|
||||
def variables(self):
|
||||
"""
|
||||
Returns variables assigned to the project
|
||||
:return: boolean
|
||||
"""
|
||||
return self._variables
|
||||
|
||||
def setSupplier(self, supplier):
|
||||
"""
|
||||
Sets supplier of project
|
||||
"""
|
||||
self._supplier = supplier
|
||||
|
||||
def supplier(self):
|
||||
"""
|
||||
Returns supplier
|
||||
:return: boolean
|
||||
"""
|
||||
return self._supplier
|
||||
|
||||
def setName(self, name):
|
||||
"""
|
||||
Set project name
|
||||
@@ -413,7 +441,9 @@ class Project(QtCore.QObject):
|
||||
"snap_to_grid": self._snap_to_grid,
|
||||
"show_grid": self._show_grid,
|
||||
"grid_size": self._grid_size,
|
||||
"show_interface_labels": self._show_interface_labels
|
||||
"show_interface_labels": self._show_interface_labels,
|
||||
"variables": self._variables,
|
||||
"supplier": self._supplier
|
||||
}
|
||||
self.put("", self._projectUpdatedCallback, body=body)
|
||||
|
||||
@@ -453,6 +483,9 @@ class Project(QtCore.QObject):
|
||||
self._show_layers = result.get("show_layers", False)
|
||||
self._snap_to_grid = result.get("snap_to_grid", False)
|
||||
self._show_grid = result.get("show_grid", False)
|
||||
self._variables = result.get("variables", None)
|
||||
self._supplier = result.get("supplier", None)
|
||||
|
||||
grid_size = result.get("grid_size", None)
|
||||
if grid_size:
|
||||
self._grid_size = grid_size
|
||||
|
||||
@@ -168,6 +168,7 @@ class Topology(QtCore.QObject):
|
||||
|
||||
self._main_window.uiGraphicsView.setZoom(self._project.zoom())
|
||||
|
||||
|
||||
def createLoadProject(self, project_settings):
|
||||
"""
|
||||
Create load a project based on settings, not on the .gns3
|
||||
|
||||
@@ -128,8 +128,6 @@ def test_project_delete_on_created_project(controller):
|
||||
|
||||
|
||||
def test_project_destroy(controller):
|
||||
|
||||
|
||||
project = Project()
|
||||
project.setId(str(uuid4()))
|
||||
project.destroy()
|
||||
@@ -140,3 +138,49 @@ def test_project_destroy(controller):
|
||||
|
||||
assert args[0] == "DELETE"
|
||||
assert args[1] == "/projects/{project_id}".format(project_id=project.id())
|
||||
|
||||
|
||||
def test_project_variables():
|
||||
project = Project()
|
||||
project.setVariables([{'name': 'TEST'}])
|
||||
|
||||
variables = project.variables()
|
||||
assert variables == [{'name': 'TEST'}]
|
||||
|
||||
|
||||
def test_project_supplier():
|
||||
project = Project()
|
||||
project.setSupplier({'logo': 'test.png', 'url': 'http://domain'})
|
||||
|
||||
supplier = project.supplier()
|
||||
assert supplier == {'logo': 'test.png', 'url': 'http://domain'}
|
||||
|
||||
|
||||
def test_project_parse_response():
|
||||
result = {
|
||||
'project_id': 'projectid',
|
||||
'name': 'projectname',
|
||||
'filename': 'filename.gns3',
|
||||
'variables': [{'name': 'TEST'}],
|
||||
'supplier': {'logo': 'test.png', 'url': 'http://domain'}
|
||||
}
|
||||
project = Project()
|
||||
project._parseResponse(result)
|
||||
assert project.id() == 'projectid'
|
||||
assert project.name() == 'projectname'
|
||||
assert project.filename() == 'filename.gns3'
|
||||
assert project.variables() == [{'name': 'TEST'}]
|
||||
assert project.supplier() == {'logo': 'test.png', 'url': 'http://domain'}
|
||||
|
||||
|
||||
def test_project_update(controller):
|
||||
project = Project()
|
||||
project.setVariables([{'name': 'TEST'}])
|
||||
project.setSupplier({'logo': 'test.png', 'url': 'http://domain'})
|
||||
project.update()
|
||||
mock = controller._http_client.createHTTPQuery
|
||||
args, kwargs = mock.call_args
|
||||
body = kwargs['body']
|
||||
assert body['variables'] == [{'name': 'TEST'}]
|
||||
assert body['supplier'] == {'logo': 'test.png', 'url': 'http://domain'}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user