API for editing files on the controller

Ref https://github.com/GNS3/gns3-gui/issues/1401
This commit is contained in:
Julien Duponchelle committed 2016-07-20 21:52:12 +02:00
1 parent bc8a319142
commit e557ccd078
3 files changed
+125

No files matched your search

@@ -175,3 +175,30 @@ def test_export(http_controller, tmpdir, loop, project):
with myzip.open("a") as myfile:
content = myfile.read()
assert content == b"hello"
def test_get_file(http_controller, tmpdir, loop, project):
os.makedirs(project.path, exist_ok=True)
with open(os.path.join(project.path, 'hello'), 'w+') as f:
f.write('world')
response = http_controller.get("/projects/{project_id}/files/hello".format(project_id=project.id), raw=True)
assert response.status == 200
assert response.body == b"world"
response = http_controller.get("/projects/{project_id}/files/false".format(project_id=project.id), raw=True)
assert response.status == 404
response = http_controller.get("/projects/{project_id}/files/../hello".format(project_id=project.id), raw=True)
assert response.status == 403
def test_write_file(http_controller, tmpdir, project):
response = http_controller.post("/projects/{project_id}/files/hello".format(project_id=project.id), body="world", raw=True)
assert response.status == 200
with open(os.path.join(project.path, "hello")) as f:
assert f.read() == "world"
response = http_controller.post("/projects/{project_id}/files/../hello".format(project_id=project.id), raw=True)
assert response.status == 403