Export API

This commit is contained in:
Julien Duponchelle committed 2016-03-30 17:42:00 +02:00
1 parent f39af9deb7
commit 879591eaf5
6 files changed
+108 -1

No files matched your search

+28
View File
@@ -20,6 +20,7 @@ import os
import asyncio
import pytest
import aiohttp
import zipfile
from uuid import uuid4
from unittest.mock import patch
@@ -258,3 +259,30 @@ def test_list_files(tmpdir, loop):
"md5sum": "098f6bcd4621d373cade4e832627b4f6"
}
]
def test_export(tmpdir):
project = Project()
path = project.path
os.makedirs(os.path.join(path, "vm-1", "dynamips"))
with open(os.path.join(path, "vm-1", "dynamips", "test"), 'w+') as f:
f.write("HELLO")
with open(os.path.join(path, "vm-1", "dynamips", "test_log.txt"), 'w+') as f:
f.write("LOG")
os.makedirs(os.path.join(path, "project-files", "snapshots"))
with open(os.path.join(path, "project-files", "snapshots", "test"), 'w+') as f:
f.write("WORLD")
z = project.export()
with open(str(tmpdir / 'zipfile.zip'), 'wb') as f:
for data in z:
f.write(data)
with zipfile.ZipFile(str(tmpdir / 'zipfile.zip')) as myzip:
with myzip.open("vm-1/dynamips/test") as myfile:
content = myfile.read()
assert content == b"HELLO"
assert 'project-files/snapshots/test' not in myzip.namelist()
assert 'vm-1/dynamips/test_log.txt' not in myzip.namelist()