diff --git a/requirements.txt b/requirements.txt index 31057f2a..08d64bdf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -60,4 +60,3 @@ werkzeug==3.1.2 # flask # flask-cors -opengeodeweb-microservice==1.*,>=1.0.11rc1 diff --git a/src/opengeodeweb_back/utils_functions.py b/src/opengeodeweb_back/utils_functions.py index 75c99bf0..1264690d 100644 --- a/src/opengeodeweb_back/utils_functions.py +++ b/src/opengeodeweb_back/utils_functions.py @@ -212,6 +212,10 @@ def save_all_viewables_and_return_info( data.native_file = os.path.basename(native_files[0]) data.viewable_file = os.path.basename(viewable_path) data.light_viewable_file = os.path.basename(light_path) + + if not data.input_file: + data.input_file = data.native_file + assert data.native_file is not None assert data.viewable_file is not None assert data.light_viewable_file is not None diff --git a/tests/test_models_routes.py b/tests/test_models_routes.py index 379e5b16..c31ae710 100644 --- a/tests/test_models_routes.py +++ b/tests/test_models_routes.py @@ -69,6 +69,41 @@ def test_export_project_route(client: FlaskClient, tmp_path: Path) -> None: database_root_path = os.path.join(project_folder, "project.db") with open(database_root_path, "wb") as f: f.write(b"test_project_db") + + with get_session() as session: + session.query(Data).delete() + session.commit() + + data1 = Data( + id="test_data_1", + geode_object="BRep", + viewer_object="BRep", + input_file="test_native.txt", + native_file="test_native.txt", + additional_files=[], + ) + data2 = Data( + id="test_data_2", + geode_object="Section", + viewer_object="Section", + input_file="test_input.txt", + native_file="test_native2.txt", + additional_files=[], + ) + session.add(data1) + session.add(data2) + session.commit() + + data1_dir = os.path.join(project_folder, "test_data_1") + os.makedirs(data1_dir, exist_ok=True) + with open(os.path.join(data1_dir, "test_native.txt"), "w") as f: + f.write("native file content") + + data2_dir = os.path.join(project_folder, "test_data_2") + os.makedirs(data2_dir, exist_ok=True) + with open(os.path.join(data2_dir, "test_input.txt"), "w") as f: + f.write("input file content") + response = client.post(route, json={"snapshot": snapshot, "filename": filename}) assert response.status_code == 200 assert response.headers.get("new-file-name") == filename @@ -77,13 +112,18 @@ def test_export_project_route(client: FlaskClient, tmp_path: Path) -> None: zip_bytes = response.get_data() tmp_zip_path = tmp_path / filename tmp_zip_path.write_bytes(zip_bytes) + with zipfile.ZipFile(tmp_zip_path, "r") as zip_file: names = zip_file.namelist() assert "snapshot.json" in names parsed = json.loads(zip_file.read("snapshot.json").decode("utf-8")) assert parsed == snapshot assert "project.db" in names + assert "test_data_1/test_native.txt" in names + assert "test_data_2/test_input.txt" in names + response.close() + export_path = os.path.join(project_folder, filename) if os.path.exists(export_path): os.remove(export_path) diff --git a/tests/test_utils_functions.py b/tests/test_utils_functions.py index 905217b1..5da9bbd5 100644 --- a/tests/test_utils_functions.py +++ b/tests/test_utils_functions.py @@ -183,16 +183,29 @@ def test_generate_native_viewable_and_light_viewable_from_object( ) ) - assert isinstance(result, dict) - assert isinstance(result["native_file"], str) - assert result["native_file"].startswith("native.") - assert isinstance(result["viewable_file"], str) - assert result["viewable_file"].endswith(".vtm") - assert isinstance(result["id"], str) - assert re.match(r"[0-9a-f]{32}", result["id"]) - assert isinstance(result["viewer_type"], str) - assert isinstance(result["binary_light_viewable"], str) - assert result["input_file"] == "" + assert isinstance(result, dict) + assert isinstance(result["native_file"], str) + assert result["native_file"].startswith("native.") + assert isinstance(result["viewable_file"], str) + assert result["viewable_file"].endswith(".vtm") + assert isinstance(result["id"], str) + assert re.match(r"[0-9a-f]{32}", result["id"]) + assert isinstance(result["viewer_type"], str) + assert isinstance(result["binary_light_viewable"], str) + assert result["binary_light_viewable"].startswith('') + + assert result["input_file"] == result["native_file"] + + data = Data.get(result["id"]) + assert data is not None + assert data.input_file == data.native_file + assert data.light_viewable_file is not None + assert data.light_viewable_file.endswith(".vtp") + + data_path = os.path.join(app.config["DATA_FOLDER_PATH"], result["id"]) + assert os.path.exists(os.path.join(data_path, result["native_file"])) + assert os.path.exists(os.path.join(data_path, result["viewable_file"])) + assert os.path.exists(os.path.join(data_path, data.light_viewable_file)) def test_generate_native_viewable_and_light_viewable_from_file(