Skip to content

Commit 3840fc3

Browse files
committed
tests updated
1 parent e90175a commit 3840fc3

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,17 +340,17 @@ def import_project() -> flask.Response:
340340
if not filename.lower().endswith(".zip"):
341341
flask.abort(400, "Uploaded file must be a .zip")
342342

343-
project_folder_path: str = flask.current_app.config["DATA_FOLDER_PATH"]
343+
data_folder_path: str = flask.current_app.config["DATA_FOLDER_PATH"]
344344
try:
345-
if os.path.exists(project_folder_path):
346-
shutil.rmtree(project_folder_path)
347-
os.makedirs(project_folder_path, exist_ok=True)
345+
if os.path.exists(data_folder_path):
346+
shutil.rmtree(data_folder_path)
347+
os.makedirs(data_folder_path, exist_ok=True)
348348
except PermissionError:
349349
flask.abort(423, "Project files are locked; cannot overwrite")
350350

351351
zip_file.stream.seek(0)
352352
with zipfile.ZipFile(zip_file.stream) as zip_archive:
353-
project_folder = os.path.abspath(project_folder_path)
353+
project_folder = os.path.abspath(data_folder_path)
354354
for member in zip_archive.namelist():
355355
target = os.path.abspath(os.path.normpath(os.path.join(project_folder, member)))
356356
if not (target == project_folder or target.startswith(project_folder + os.sep)):

tests/test_models_routes.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ def test_export_project_route(client, tmp_path):
6666
"styles": {"1": {"visibility": True, "opacity": 1.0, "color": [0.2, 0.6, 0.9]}}
6767
}
6868
filename = "export_project_test.zip"
69+
project_folder = client.application.config["DATA_FOLDER_PATH"]
70+
os.makedirs(project_folder, exist_ok=True)
71+
database_root_path = os.path.join(project_folder, "project.db")
72+
with open(database_root_path, "wb") as f:
73+
f.write(b"test_project_db")
6974
response = client.post(route, json={"snapshot": snapshot, "filename": filename})
7075
assert response.status_code == 200
7176
assert response.headers.get("new-file-name") == filename
@@ -79,10 +84,9 @@ def test_export_project_route(client, tmp_path):
7984
assert "snapshot.json" in names
8085
parsed = json.loads(zip_file.read("snapshot.json").decode("utf-8"))
8186
assert parsed == snapshot
82-
assert "1/project.db" in names
87+
assert "project.db" in names
8388
response.close()
84-
upload_folder = client.application.config["UPLOAD_FOLDER"]
85-
export_path = os.path.join(upload_folder, filename)
89+
export_path = os.path.join(project_folder, filename)
8690
if os.path.exists(export_path):
8791
os.remove(export_path)
8892

@@ -93,17 +97,15 @@ def test_import_project_route(client, tmp_path):
9397
"styles": {"1": {"visibility": True, "opacity": 1.0, "color": [0.2, 0.6, 0.9]}}
9498
}
9599

100+
client.application.config["DATA_FOLDER_PATH"] = os.path.join(str(tmp_path), "project_data")
96101
data_folder = client.application.config["DATA_FOLDER_PATH"]
97-
pre_existing_db_path = os.path.join(data_folder, "1", "project.db")
98-
os.makedirs(os.path.dirname(pre_existing_db_path), exist_ok=True)
99-
with open(pre_existing_db_path, "wb") as file:
100-
file.write(b"old_db_content")
102+
pre_existing_db_path = os.path.join(data_folder, "project.db")
101103

102104
tmp_zip = tmp_path / "import_project_test.zip"
103105
new_database_bytes = b"new_db_content"
104106
with zipfile.ZipFile(tmp_zip, "w", compression=zipfile.ZIP_DEFLATED) as zip_file:
105107
zip_file.writestr("snapshot.json", json.dumps(snapshot))
106-
zip_file.writestr("1/project.db", new_database_bytes)
108+
zip_file.writestr("project.db", new_database_bytes)
107109

108110
with open(tmp_zip, "rb") as file:
109111
response = client.post(

0 commit comments

Comments
 (0)