Early import project api

This commit is contained in:
Julien Duponchelle
2016-07-21 14:48:13 +02:00
parent 14f6bd60fb
commit b5ab53bbe9
8 changed files with 221 additions and 4 deletions

View File

@ -202,3 +202,21 @@ def test_write_file(http_controller, tmpdir, project):
response = http_controller.post("/projects/{project_id}/files/../hello".format(project_id=project.id), raw=True)
assert response.status == 403
def test_import(http_controller, tmpdir, controller):
with zipfile.ZipFile(str(tmpdir / "test.zip"), 'w') as myzip:
myzip.writestr("project.gns3", b'{"version": "2.0.0", "name": "test"}')
myzip.writestr("demo", b"hello")
project_id = str(uuid.uuid4())
with open(str(tmpdir / "test.zip"), "rb") as f:
response = http_controller.post("/projects/{project_id}/import".format(project_id=project_id), body=f.read(), raw=True)
assert response.status == 201
project = controller.get_project(project_id)
with open(os.path.join(project.path, "demo")) as f:
content = f.read()
assert content == "hello"