mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Add to project an API to write a file
This commit is contained in:
2 files changed
+62
No files matched your search
@@ -261,3 +261,25 @@ def test_get_file(server, tmpdir):
|
||||
|
||||
response = server.get("/projects/{project_id}/files/../hello".format(project_id=project.id), raw=True)
|
||||
assert response.status == 403
|
||||
|
||||
|
||||
def test_write_file(server, tmpdir):
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"project_directory": str(tmpdir)}):
|
||||
project = ProjectManager.instance().create_project()
|
||||
|
||||
with open(os.path.join(project.path, "hello"), "w+") as f:
|
||||
f.write("world")
|
||||
|
||||
response = server.post("/projects/{project_id}/files/hello".format(project_id=project.id), body="universe", raw=True)
|
||||
assert response.status == 200
|
||||
|
||||
with open(os.path.join(project.path, "hello")) as f:
|
||||
content = f.read()
|
||||
assert content == "universe"
|
||||
|
||||
response = server.post("/projects/{project_id}/files/test/false".format(project_id=project.id), body="universe", raw=True)
|
||||
assert response.status == 404
|
||||
|
||||
response = server.post("/projects/{project_id}/files/../hello".format(project_id=project.id), body="universe", raw=True)
|
||||
assert response.status == 403
|
||||
Reference in new issue
Block a user