Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ werkzeug==3.1.2
# flask
# flask-cors

opengeodeweb-microservice==1.*,>=1.0.11rc1
4 changes: 4 additions & 0 deletions src/opengeodeweb_back/utils_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions tests/test_models_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
33 changes: 23 additions & 10 deletions tests/test_utils_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<?xml version="1.0"?>')

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(
Expand Down