mirror of
https://github.com/GNS3/gns3-server
synced 2025-02-26 07:02:12 +00:00
Raise an error if you overwrite an existing project
This commit is contained in:
parent
c12413e0ce
commit
3b70b4f217
@ -51,6 +51,12 @@ class Project:
|
|||||||
self._name = name
|
self._name = name
|
||||||
self._auto_start = False
|
self._auto_start = False
|
||||||
self._status = status
|
self._status = status
|
||||||
|
|
||||||
|
# Disallow overwrite of existing project
|
||||||
|
if project_id is None and path is not None:
|
||||||
|
if os.path.exists(path):
|
||||||
|
raise aiohttp.web.HTTPForbidden(text="The path {} already exist.".format(path))
|
||||||
|
|
||||||
if project_id is None:
|
if project_id is None:
|
||||||
self._id = str(uuid4())
|
self._id = str(uuid4())
|
||||||
else:
|
else:
|
||||||
@ -187,7 +193,6 @@ class Project:
|
|||||||
return name
|
return name
|
||||||
raise aiohttp.web.HTTPConflict(text="A node name could not be allocated (node limit reached?)")
|
raise aiohttp.web.HTTPConflict(text="A node name could not be allocated (node limit reached?)")
|
||||||
|
|
||||||
|
|
||||||
def has_allocated_node_name(self, name):
|
def has_allocated_node_name(self, name):
|
||||||
"""
|
"""
|
||||||
Returns either a node name is already allocated or not.
|
Returns either a node name is already allocated or not.
|
||||||
|
@ -56,6 +56,17 @@ def test_path(tmpdir):
|
|||||||
assert os.path.exists(os.path.join(directory, p.id))
|
assert os.path.exists(os.path.join(directory, p.id))
|
||||||
|
|
||||||
|
|
||||||
|
def test_path_exist(tmpdir):
|
||||||
|
"""
|
||||||
|
Should raise an error when you try to owerwrite
|
||||||
|
an existing project
|
||||||
|
"""
|
||||||
|
os.makedirs(str(tmpdir / "demo"))
|
||||||
|
with pytest.raises(aiohttp.web.HTTPForbidden):
|
||||||
|
p = Project(name="Test", path=str(tmpdir / "demo"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_init_path(tmpdir):
|
def test_init_path(tmpdir):
|
||||||
|
|
||||||
p = Project(path=str(tmpdir), project_id=str(uuid4()), name="Test")
|
p = Project(path=str(tmpdir), project_id=str(uuid4()), name="Test")
|
||||||
@ -69,8 +80,8 @@ def test_changing_path_with_quote_not_allowed(tmpdir):
|
|||||||
|
|
||||||
|
|
||||||
def test_captures_directory(tmpdir):
|
def test_captures_directory(tmpdir):
|
||||||
p = Project(path=str(tmpdir), name="Test")
|
p = Project(path=str(tmpdir / "capturestest"), name="Test")
|
||||||
assert p.captures_directory == str(tmpdir / "project-files" / "captures")
|
assert p.captures_directory == str(tmpdir / "capturestest" / "project-files" / "captures")
|
||||||
assert os.path.exists(p.captures_directory)
|
assert os.path.exists(p.captures_directory)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user