mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Close, commit and delete supported for projects in controller
This commit is contained in:
19 files changed
+560
-117
No files matched your search
Whitespace-only changes.
@@ -16,9 +16,14 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest
|
||||
import uuid
|
||||
import aiohttp
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
|
||||
from gns3server.controller import Controller
|
||||
from gns3server.controller.hypervisor import Hypervisor
|
||||
from gns3server.controller.project import Project
|
||||
from gns3server.config import Config
|
||||
|
||||
|
||||
@@ -38,3 +43,49 @@ def test_addHypervisor(controller):
|
||||
assert len(controller.hypervisors) == 1
|
||||
controller.addHypervisor(Hypervisor("test2"))
|
||||
assert len(controller.hypervisors) == 2
|
||||
|
||||
|
||||
def test_addProject(controller, async_run):
|
||||
uuid1 = str(uuid.uuid4())
|
||||
project1 = Project(project_id=uuid1)
|
||||
uuid2 = str(uuid.uuid4())
|
||||
|
||||
async_run(controller.addProject(project1))
|
||||
assert len(controller.projects) == 1
|
||||
async_run(controller.addProject(Project(project_id=uuid1)))
|
||||
assert len(controller.projects) == 1
|
||||
async_run(controller.addProject(Project(project_id=uuid2)))
|
||||
assert len(controller.projects) == 2
|
||||
|
||||
|
||||
def test_removeProject(controller, async_run):
|
||||
uuid1 = str(uuid.uuid4())
|
||||
project1 = Project(project_id=uuid1)
|
||||
|
||||
async_run(controller.addProject(project1))
|
||||
assert len(controller.projects) == 1
|
||||
|
||||
controller.removeProject(project1)
|
||||
assert len(controller.projects) == 0
|
||||
|
||||
|
||||
def test_addProject_with_hypervisor(controller, async_run):
|
||||
uuid1 = str(uuid.uuid4())
|
||||
project1 = Project(project_id=uuid1)
|
||||
|
||||
hypervisor = Hypervisor("test1")
|
||||
hypervisor.post = MagicMock()
|
||||
controller.addHypervisor(hypervisor)
|
||||
|
||||
async_run(controller.addProject(project1))
|
||||
hypervisor.post.assert_called_with("/projects", project1)
|
||||
|
||||
|
||||
def test_getProject(controller, async_run):
|
||||
uuid1 = str(uuid.uuid4())
|
||||
project = Project(project_id=uuid1)
|
||||
|
||||
async_run(controller.addProject(project))
|
||||
assert controller.getProject(uuid1) == project
|
||||
with pytest.raises(aiohttp.web.HTTPNotFound):
|
||||
assert controller.getProject("dsdssd")
|
||||
@@ -17,10 +17,13 @@
|
||||
|
||||
|
||||
import pytest
|
||||
from unittest.mock import patch
|
||||
import json
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
from gns3server.controller.project import Project
|
||||
from gns3server.controller.hypervisor import Hypervisor, HypervisorError
|
||||
from gns3server.version import __version__
|
||||
from tests.utils import asyncio_patch
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -46,6 +49,25 @@ def test_hypervisor_local(hypervisor):
|
||||
s = Hypervisor("test")
|
||||
|
||||
|
||||
def test_hypervisor_httpQuery(hypervisor, async_run):
|
||||
response = MagicMock()
|
||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||
response.status = 200
|
||||
|
||||
async_run(hypervisor.post("/projects", {"a": "b"}))
|
||||
mock.assert_called_with("POST", "https://example.com:84/v2/hypervisor/projects", data='{"a": "b"}', headers={'content-type': 'application/json'})
|
||||
|
||||
|
||||
def test_hypervisor_httpQuery_project(hypervisor, async_run):
|
||||
response = MagicMock()
|
||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||
response.status = 200
|
||||
|
||||
project = Project()
|
||||
async_run(hypervisor.post("/projects", project))
|
||||
mock.assert_called_with("POST", "https://example.com:84/v2/hypervisor/projects", data=json.dumps(project.__json__()), headers={'content-type': 'application/json'})
|
||||
|
||||
|
||||
def test_json(hypervisor):
|
||||
assert hypervisor.__json__() == {
|
||||
"hypervisor_id": "my_hypervisor_id",
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2015 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 gns3server.controller.project import Project
|
||||
|
||||
|
||||
def test_affect_uuid():
|
||||
p = Project()
|
||||
assert len(p.id) == 36
|
||||
|
||||
p = Project(project_id='00010203-0405-0607-0809-0a0b0c0d0e0f')
|
||||
assert p.id == '00010203-0405-0607-0809-0a0b0c0d0e0f'
|
||||
|
||||
|
||||
def test_json(tmpdir):
|
||||
p = Project()
|
||||
assert p.__json__() == {"name": p.name, "project_id": p.id, "temporary": False, "path": None}
|
||||
Reference in new issue
Block a user