mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-21 21:45:20 +02:00
Merge branch '2.2' into 3.0
# Conflicts: # CHANGELOG # docs/api/notifications/link.updated.json # docs/api/notifications/log.warning.json # docs/api/v2/compute/ethernet_switch/projectsprojectidethernetswitchnodes.rst # docs/api/v2/compute/ethernet_switch/projectsprojectidethernetswitchnodesnodeid.rst # docs/api/v2/compute/iou/projectsprojectidiounodes.rst # docs/api/v2/compute/project/projects.rst # docs/api/v2/compute/qemu/projectsprojectidqemunodes.rst # docs/api/v2/compute/qemu/projectsprojectidqemunodesnodeid.rst # docs/api/v2/compute/qemu/projectsprojectidqemunodesnodeidstart.rst # docs/api/v2/controller/link/projectsprojectidlinks.rst # docs/api/v2/controller/link/projectsprojectidlinkslinkid.rst # docs/api/v2/controller/link/projectsprojectidlinkslinkidstartcapture.rst # docs/api/v2/controller/project/projects.rst # docs/api/v2/controller/project/projectsprojectidduplicate.rst # docs/controller_notifications.rst # docs/curl.rst # docs/gns3_file.json # docs/project_notifications.rst # gns3server/compute/qemu/qemu_vm.py # gns3server/controller/project.py # gns3server/crash_report.py # gns3server/schemas/ethernet_hub.py # gns3server/schemas/ethernet_switch.py # gns3server/static/web-ui/3rdpartylicenses.txt # gns3server/static/web-ui/index.html # gns3server/utils/asyncio/telnet_server.py # gns3server/version.py # gns3server/web/web_server.py # requirements.txt # tests/controller/test_project.py # tests/controller/test_topology.py # tests/handlers/api/controller/test_project.py
This commit is contained in:
34 files changed
+483
-168
No files matched your search
@@ -47,16 +47,20 @@ async def node(controller, project):
|
||||
@pytest.mark.asyncio
|
||||
async def test_affect_uuid():
|
||||
|
||||
p = Project(name="Test")
|
||||
assert len(p.id) == 36
|
||||
p = Project(project_id='00010203-0405-0607-0809-0a0b0c0d0e0f', name="Test 2")
|
||||
assert p.id == '00010203-0405-0607-0809-0a0b0c0d0e0f'
|
||||
with patch('gns3server.controller.project.Project.emit_controller_notification') as mock_notification:
|
||||
p = Project(name="Test")
|
||||
mock_notification.assert_called()
|
||||
assert len(p.id) == 36
|
||||
p = Project(project_id='00010203-0405-0607-0809-0a0b0c0d0e0f', name="Test 2")
|
||||
assert p.id == '00010203-0405-0607-0809-0a0b0c0d0e0f'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_json():
|
||||
|
||||
p = Project(name="Test")
|
||||
with patch('gns3server.controller.project.Project.emit_controller_notification') as mock_notification:
|
||||
p = Project(name="Test")
|
||||
mock_notification.assert_called()
|
||||
|
||||
assert p.asdict() == {
|
||||
"name": "Test",
|
||||
@@ -85,11 +89,11 @@ async def test_json():
|
||||
async def test_update(controller):
|
||||
|
||||
project = Project(controller=controller, name="Hello")
|
||||
project.emit_notification = MagicMock()
|
||||
project.emit_controller_notification = MagicMock()
|
||||
assert project.name == "Hello"
|
||||
await project.update(name="World")
|
||||
assert project.name == "World"
|
||||
project.emit_notification.assert_any_call("project.updated", project.asdict())
|
||||
project.emit_controller_notification.assert_any_call("project.updated", project.asdict())
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -110,7 +114,9 @@ async def test_path(projects_dir):
|
||||
|
||||
directory = projects_dir
|
||||
with patch("gns3server.utils.path.get_default_project_directory", return_value=directory):
|
||||
p = Project(project_id=str(uuid4()), name="Test")
|
||||
with patch('gns3server.controller.project.Project.emit_controller_notification') as mock_notification:
|
||||
p = Project(project_id=str(uuid4()), name="Test")
|
||||
mock_notification.assert_called()
|
||||
assert p.path == os.path.join(directory, p.id)
|
||||
assert os.path.exists(os.path.join(directory, p.id))
|
||||
|
||||
@@ -129,25 +135,29 @@ def test_path_exist(tmpdir):
|
||||
@pytest.mark.asyncio
|
||||
async def test_init_path(projects_dir):
|
||||
|
||||
project_id = str(uuid4())
|
||||
p = Project(project_id=project_id, name="Test")
|
||||
assert p.path == os.path.join(projects_dir, project_id)
|
||||
with patch('gns3server.controller.project.Project.emit_controller_notification') as mock_notification:
|
||||
project_id = str(uuid4())
|
||||
p = Project(project_id=project_id, name="Test")
|
||||
mock_notification.assert_called()
|
||||
assert p.path == os.path.join(projects_dir, project_id)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_changing_path_with_quote_not_allowed(projects_dir):
|
||||
|
||||
with pytest.raises(ControllerForbiddenError):
|
||||
p = Project(project_id=str(uuid4()), name="Test")
|
||||
p.path = os.path.join(projects_dir, "project\"53")
|
||||
with patch('gns3server.controller.project.Project.emit_controller_notification'):
|
||||
p = Project(project_id=str(uuid4()), name="Test")
|
||||
p.path = os.path.join(projects_dir, "project\"53")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_captures_directory(tmpdir):
|
||||
|
||||
p = Project(name="Test")
|
||||
assert p.captures_directory == str(p.path + os.path.sep + "project-files" + os.path.sep + "captures")
|
||||
assert os.path.exists(p.captures_directory)
|
||||
with patch('gns3server.controller.project.Project.emit_controller_notification'):
|
||||
p = Project(name="Test")
|
||||
assert p.captures_directory == str(p.path + os.path.sep + "project-files" + os.path.sep + "captures")
|
||||
assert os.path.exists(p.captures_directory)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -682,38 +692,41 @@ async def test_dump(projects_dir):
|
||||
|
||||
directory = projects_dir
|
||||
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
|
||||
with patch('gns3server.controller.project.Project.emit_controller_notification'):
|
||||
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
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_open_close(controller):
|
||||
|
||||
project = Project(controller=controller, name="Test")
|
||||
assert project.status == "opened"
|
||||
await project.close()
|
||||
project.start_all = AsyncioMagicMock()
|
||||
await project.open()
|
||||
assert not project.start_all.called
|
||||
assert project.status == "opened"
|
||||
project.emit_notification = MagicMock()
|
||||
await project.close()
|
||||
assert project.status == "closed"
|
||||
project.emit_notification.assert_any_call("project.closed", project.asdict())
|
||||
with patch('gns3server.controller.project.Project.emit_controller_notification'):
|
||||
project = Project(controller=controller, name="Test")
|
||||
assert project.status == "opened"
|
||||
await project.close()
|
||||
project.start_all = AsyncioMagicMock()
|
||||
await project.open()
|
||||
assert not project.start_all.called
|
||||
assert project.status == "opened"
|
||||
project.emit_controller_notification = MagicMock()
|
||||
await project.close()
|
||||
assert project.status == "closed"
|
||||
project.emit_controller_notification.assert_any_call("project.closed", project.asdict())
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_open_auto_start(controller):
|
||||
|
||||
project = Project(controller=controller, name="Test", auto_start=True)
|
||||
assert project.status == "opened"
|
||||
await project.close()
|
||||
project.start_all = AsyncioMagicMock()
|
||||
await project.open()
|
||||
assert project.start_all.called
|
||||
with patch('gns3server.controller.project.Project.emit_controller_notification'):
|
||||
project = Project(controller=controller, name="Test", auto_start=True)
|
||||
assert project.status == "opened"
|
||||
await project.close()
|
||||
project.start_all = AsyncioMagicMock()
|
||||
await project.open()
|
||||
assert project.start_all.called
|
||||
|
||||
|
||||
def test_is_running(project, node):
|
||||
|
||||
Reference in new issue
Block a user