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.6
3 changes: 2 additions & 1 deletion src/opengeodeweb_back/routes/blueprint_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def upload_file() -> flask.Response:

UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
if not os.path.exists(UPLOAD_FOLDER):
os.mkdir(UPLOAD_FOLDER)
os.makedirs(UPLOAD_FOLDER, exist_ok=True)

file = flask.request.files["file"]
filename = werkzeug.utils.secure_filename(os.path.basename(file.filename))
file.save(os.path.join(UPLOAD_FOLDER, filename))
Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
import pytest

# Local application imports
from src.opengeodeweb_back.app import app
from opengeodeweb_back.app import app

# from opengeodeweb_back import app_config
from opengeodeweb_microservice.database.connection import init_database

TEST_ID = "1"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_create_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from flask.testing import FlaskClient

# Local application imports
from src.opengeodeweb_back import test_utils
from opengeodeweb_back import test_utils


@pytest.fixture
Expand Down
14 changes: 5 additions & 9 deletions tests/test_models_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
from opengeodeweb_microservice.database.data import Data
from opengeodeweb_microservice.database.connection import get_session

base_dir = os.path.abspath(os.path.dirname(__file__))
data_dir = os.path.join(base_dir, "data")


def test_model_mesh_components(client, test_id):
route = "/opengeodeweb_back/models/vtm_component_indices"

with client.application.app_context():
data_path = geode_functions.data_file_path(test_id, "viewable.vtm")
os.makedirs(os.path.dirname(data_path), exist_ok=True)
shutil.copy("./tests/data/cube.vtm", data_path)
shutil.copy(os.path.join(data_dir, "cube.vtm"), data_path)

response = client.post(route, json={"id": test_id})
assert response.status_code == 200
Expand All @@ -30,7 +33,7 @@ def test_model_mesh_components(client, test_id):

def test_extract_brep_uuids(client, test_id):
route = "/opengeodeweb_back/models/mesh_components"
brep_filename = "cube.og_brep"
brep_filename = os.path.join(data_dir, "cube.og_brep")

with client.application.app_context():
data_entry = Data.create(
Expand All @@ -43,13 +46,6 @@ def test_extract_brep_uuids(client, test_id):
if session:
session.commit()

src_path = os.path.join("tests", "data", brep_filename)
dest_path = os.path.join(
flask.current_app.config["DATA_FOLDER_PATH"], data_entry.id, brep_filename
)
os.makedirs(os.path.dirname(dest_path), exist_ok=True)
shutil.copy2(src_path, dest_path)

response = client.post(route, json={"id": data_entry.id})
assert response.status_code == 200
assert "uuid_dict" in response.json
Expand Down
32 changes: 18 additions & 14 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Standard library imports
import os
import shutil

# Third party imports
from werkzeug.datastructures import FileStorage
Expand All @@ -10,6 +9,9 @@
from opengeodeweb_microservice.database.connection import get_session
from opengeodeweb_back import geode_functions, test_utils

base_dir = os.path.abspath(os.path.dirname(__file__))
data_dir = os.path.join(base_dir, "data")


def test_allowed_files(client):
route = f"/opengeodeweb_back/allowed_files"
Expand Down Expand Up @@ -48,9 +50,11 @@ def get_full_data():


def test_upload_file(client, filename="test.og_brep"):
file = os.path.join(data_dir, filename)
print(f"{file=}", flush=True)
response = client.put(
f"/opengeodeweb_back/upload_file",
data={"file": FileStorage(open(f"./tests/data/{filename}", "rb"))},
data={"file": FileStorage(open(file, "rb"))},
)
assert response.status_code == 201

Expand Down Expand Up @@ -171,19 +175,19 @@ def get_full_data():

def test_texture_coordinates(client, test_id):
with client.application.app_context():
file = os.path.join(data_dir, "hat.vtp")
data = Data.create(
geode_object="PolygonalSurface3D",
viewer_object=geode_functions.get_object_type("PolygonalSurface3D"),
input_file="hat.vtp",
input_file=file,
)
data.native_file_name = "hat.vtp"
data.native_file_name = file
session = get_session()
if session:
session.commit()

data_path = geode_functions.data_file_path(data.id, data.native_file_name)
os.makedirs(os.path.dirname(data_path), exist_ok=True)
shutil.copy("./tests/data/hat.vtp", data_path)
assert os.path.exists(data_path), f"File not found at {data_path}"
response = client.post(
"/opengeodeweb_back/texture_coordinates", json={"id": data.id}
Expand All @@ -199,19 +203,19 @@ def test_vertex_attribute_names(client, test_id):
route = f"/opengeodeweb_back/vertex_attribute_names"

with client.application.app_context():
file = os.path.join(data_dir, "test.vtp")
data = Data.create(
geode_object="PolygonalSurface3D",
viewer_object=geode_functions.get_object_type("PolygonalSurface3D"),
input_file="test.vtp",
input_file=file,
)
data.native_file_name = "test.vtp"
data.native_file_name = file
session = get_session()
if session:
session.commit()

data_path = geode_functions.data_file_path(data.id, data.native_file_name)
os.makedirs(os.path.dirname(data_path), exist_ok=True)
shutil.copy("./tests/data/test.vtp", data_path)
assert os.path.exists(data_path), f"File not found at {data_path}"
response = client.post(route, json={"id": data.id})
assert response.status_code == 200
Expand All @@ -225,19 +229,19 @@ def test_polygon_attribute_names(client, test_id):
route = f"/opengeodeweb_back/polygon_attribute_names"

with client.application.app_context():
file = os.path.join(data_dir, "test.vtp")
data = Data.create(
geode_object="PolygonalSurface3D",
viewer_object=geode_functions.get_object_type("PolygonalSurface3D"),
input_file="test.vtp",
input_file=file,
)
data.native_file_name = "test.vtp"
data.native_file_name = file
session = get_session()
if session:
session.commit()

data_path = geode_functions.data_file_path(data.id, data.native_file_name)
os.makedirs(os.path.dirname(data_path), exist_ok=True)
shutil.copy("./tests/data/test.vtp", data_path)
assert os.path.exists(data_path), f"File not found at {data_path}"
response = client.post(route, json={"id": data.id})
assert response.status_code == 200
Expand All @@ -251,19 +255,19 @@ def test_polyhedron_attribute_names(client, test_id):
route = f"/opengeodeweb_back/polyhedron_attribute_names"

with client.application.app_context():
file = os.path.join(data_dir, "test.vtu")
data = Data.create(
geode_object="PolyhedralSolid3D",
viewer_object=geode_functions.get_object_type("PolyhedralSolid3D"),
input_file="test.vtu",
input_file=file,
)
data.native_file_name = "test.vtu"
data.native_file_name = file
session = get_session()
if session:
session.commit()

data_path = geode_functions.data_file_path(data.id, data.native_file_name)
os.makedirs(os.path.dirname(data_path), exist_ok=True)
shutil.copy("./tests/data/test.vtu", data_path)
assert os.path.exists(data_path), f"File not found at {data_path}"
response = client.post(route, json={"id": data.id})
print(response.json)
Expand Down
18 changes: 13 additions & 5 deletions tests/test_utils_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
from opengeodeweb_microservice.database.connection import get_session
from opengeodeweb_back import geode_functions, utils_functions

base_dir = os.path.abspath(os.path.dirname(__file__))
data_dir = os.path.join(base_dir, "data")


def test_increment_request_counter(app_context):
assert flask.current_app.config.get("REQUEST_COUNTER") == 0
Expand Down Expand Up @@ -91,15 +94,16 @@ def test_create_data_folder_from_id(client):
def test_save_all_viewables_and_return_info(client):
app = client.application
with app.app_context():
base_dir = os.path.abspath(os.path.dirname(__file__))
expected_db_path = os.path.join(base_dir, "data", "project.db")
expected_db_path = os.path.join(data_dir, "project.db")
expected_uri = f"sqlite:///{expected_db_path}"

assert app.config["SQLALCHEMY_DATABASE_URI"] == expected_uri
assert os.path.exists(expected_db_path)

geode_object = "BRep"
data = geode_functions.load(geode_object, "./tests/data/test.og_brep")
data = geode_functions.load(
geode_object, os.path.join(data_dir, "test.og_brep")
)
input_file = "test.og_brep"
additional_files = ["additional_file.txt"]

Expand Down Expand Up @@ -142,7 +146,9 @@ def test_save_all_viewables_commits_to_db(client):
app = client.application
with app.app_context():
geode_object = "BRep"
data = geode_functions.load(geode_object, "./tests/data/test.og_brep")
data = geode_functions.load(
geode_object, os.path.join(data_dir, "test.og_brep")
)
input_file = "test.og_brep"

data_entry = Data.create(
Expand All @@ -166,7 +172,9 @@ def test_generate_native_viewable_and_light_viewable_from_object(client):
app = client.application
with app.app_context():
geode_object = "BRep"
data = geode_functions.load(geode_object, "./tests/data/test.og_brep")
data = geode_functions.load(
geode_object, os.path.join(data_dir, "test.og_brep")
)

result = (
utils_functions.generate_native_viewable_and_light_viewable_from_object(
Expand Down