|
|
|
@ -47,7 +47,9 @@ async def node(controller, project):
|
|
|
|
|
|
|
|
|
|
async def test_affect_uuid():
|
|
|
|
|
|
|
|
|
|
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'
|
|
|
|
@ -55,7 +57,9 @@ async def test_affect_uuid():
|
|
|
|
|
|
|
|
|
|
async def test_json():
|
|
|
|
|
|
|
|
|
|
with patch('gns3server.controller.project.Project.emit_controller_notification') as mock_notification:
|
|
|
|
|
p = Project(name="Test")
|
|
|
|
|
mock_notification.assert_called()
|
|
|
|
|
|
|
|
|
|
assert p.__json__() == {
|
|
|
|
|
"name": "Test",
|
|
|
|
@ -83,11 +87,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.__json__())
|
|
|
|
|
project.emit_controller_notification.assert_any_call("project.updated", project.__json__())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_update_on_compute(controller):
|
|
|
|
@ -106,7 +110,9 @@ async def test_path(projects_dir):
|
|
|
|
|
|
|
|
|
|
directory = projects_dir
|
|
|
|
|
with patch("gns3server.utils.path.get_default_project_directory", return_value=directory):
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
|
@ -124,7 +130,9 @@ def test_path_exist(tmpdir):
|
|
|
|
|
|
|
|
|
|
async def test_init_path(tmpdir):
|
|
|
|
|
|
|
|
|
|
with patch('gns3server.controller.project.Project.emit_controller_notification') as mock_notification:
|
|
|
|
|
p = Project(path=str(tmpdir), project_id=str(uuid4()), name="Test")
|
|
|
|
|
mock_notification.assert_called()
|
|
|
|
|
assert p.path == str(tmpdir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -132,12 +140,14 @@ async def test_init_path(tmpdir):
|
|
|
|
|
async def test_changing_path_with_quote_not_allowed(tmpdir):
|
|
|
|
|
|
|
|
|
|
with pytest.raises(aiohttp.web.HTTPForbidden):
|
|
|
|
|
with patch('gns3server.controller.project.Project.emit_controller_notification'):
|
|
|
|
|
p = Project(project_id=str(uuid4()), name="Test")
|
|
|
|
|
p.path = str(tmpdir / "project\"53")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_captures_directory(tmpdir):
|
|
|
|
|
|
|
|
|
|
with patch('gns3server.controller.project.Project.emit_controller_notification'):
|
|
|
|
|
p = Project(path=str(tmpdir / "capturestest"), name="Test")
|
|
|
|
|
assert p.captures_directory == str(tmpdir / "capturestest" / "project-files" / "captures")
|
|
|
|
|
assert os.path.exists(p.captures_directory)
|
|
|
|
@ -649,6 +659,7 @@ async def test_dump(projects_dir):
|
|
|
|
|
|
|
|
|
|
directory = projects_dir
|
|
|
|
|
with patch("gns3server.utils.path.get_default_project_directory", return_value=directory):
|
|
|
|
|
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:
|
|
|
|
@ -658,6 +669,7 @@ async def test_dump(projects_dir):
|
|
|
|
|
|
|
|
|
|
async def test_open_close(controller):
|
|
|
|
|
|
|
|
|
|
with patch('gns3server.controller.project.Project.emit_controller_notification'):
|
|
|
|
|
project = Project(controller=controller, name="Test")
|
|
|
|
|
assert project.status == "opened"
|
|
|
|
|
await project.close()
|
|
|
|
@ -665,14 +677,15 @@ async def test_open_close(controller):
|
|
|
|
|
await project.open()
|
|
|
|
|
assert not project.start_all.called
|
|
|
|
|
assert project.status == "opened"
|
|
|
|
|
project.emit_notification = MagicMock()
|
|
|
|
|
project.emit_controller_notification = MagicMock()
|
|
|
|
|
await project.close()
|
|
|
|
|
assert project.status == "closed"
|
|
|
|
|
project.emit_notification.assert_any_call("project.closed", project.__json__())
|
|
|
|
|
project.emit_controller_notification.assert_any_call("project.closed", project.__json__())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_open_auto_start(controller):
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|