Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 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: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ jobs:
test:
uses: Geode-solutions/actions/.github/workflows/py-test.yml@master
with:
repos: ${{ vars.REPOS }}
npm: true
secrets: inherit
1 change: 1 addition & 0 deletions .github/workflows/test_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ jobs:
test:
uses: Geode-solutions/actions/.github/workflows/py-test-pr.yml@master
with:
repos: ${{ vars.REPOS }}
npm: true
secrets: inherit
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from src.opengeodeweb_back.routes.models import blueprint_models
from src.opengeodeweb_back.utils_functions import handle_exception
from src.opengeodeweb_back import app_config
from src.opengeodeweb_back.database import initialize_database
from opengeodeweb_microservice.database.connection import init_database


""" Global config """
Expand Down Expand Up @@ -58,6 +58,6 @@ def return_error():

# ''' Main '''
if __name__ == "__main__":
initialize_database(app)
init_database(app)
print(f"Python is running in {FLASK_DEBUG} mode")
app.run(debug=FLASK_DEBUG, host=DEFAULT_HOST, port=PORT, ssl_context=SSL)
13 changes: 6 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,27 @@ build-backend = "setuptools.build_meta"
name = "OpenGeodeWeb-Back"
version = "0.0.0"
dynamic = ["dependencies"]
authors = [
{ name="Geode-solutions", email="[email protected]" },
]
authors = [{ name = "Geode-solutions", email = "[email protected]" }]
description = "OpenGeodeWeb-Back is an open source framework that proposes handy python functions and wrappers for the OpenGeode ecosystem"
readme = "README.md"
requires-python = ">=3.9, <3.13"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]

[project.urls]
"Homepage" = "https://github.com/Geode-solutions/OpenGeodeWeb-Back"
"Bug Tracker" = "https://github.com/Geode-solutions/OpenGeodeWeb-Back/issues"

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}
dependencies = { file = ["requirements.txt"] }

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.package-data]
"opengeodeweb_back.routes.schemas" = ["*.json"]
"opengeodeweb_back.routes.models.schemas" = ["*.json"]
opengeodeweb_microservice = ["py.typed"]
3 changes: 2 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ fastjsonschema==2.16.2
Flask[async]==3.0.3
Flask-Cors==6.0.1
werkzeug==3.0.3
Flask-SQLAlchemy==3.1.1
Flask-SQLAlchemy==3.1.1
# OpenGeodeWeb-Microservice
4 changes: 3 additions & 1 deletion src/opengeodeweb_back/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

# Third party imports
# Local application imports
from .database import DATABASE_FILENAME
from opengeodeweb_microservice.database.connection import get_database

DATABASE_FILENAME = "project.db"


class Config(object):
Expand Down
45 changes: 0 additions & 45 deletions src/opengeodeweb_back/data.py

This file was deleted.

19 changes: 0 additions & 19 deletions src/opengeodeweb_back/database.py

This file was deleted.

8 changes: 4 additions & 4 deletions src/opengeodeweb_back/geode_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
# Local application imports
from .geode_objects import geode_objects_dict
from . import utils_functions
from .data import Data
from .database import database
from opengeodeweb_microservice.microservice.data import Data
from opengeodeweb_microservice.database.connection import get_session


def geode_object_value(geode_object: str):
Expand Down Expand Up @@ -61,12 +61,12 @@ def load_data(data_id: str) -> Any:
flask.abort(404, f"Data with id {data_id} not found")

file_absolute_path = data_file_path(data_id, data_entry.native_file_name)
print("Loading file: ", file_absolute_path)
print("File exists: ", os.path.exists(file_absolute_path))
return load(data_entry.geode_object, file_absolute_path)


def get_data_info(data_id: str) -> Data:
from .data import Data

data_entry = Data.get(data_id)
if not data_entry:
flask.abort(404, f"Data with id {data_id} not found")
Expand Down
1 change: 1 addition & 0 deletions src/opengeodeweb_back/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
partial
18 changes: 13 additions & 5 deletions src/opengeodeweb_back/utils_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

# Local application imports
from . import geode_functions
from .data import Data
from .database import database
from opengeodeweb_microservice.microservice.data import Data
from opengeodeweb_microservice.database.connection import get_session


def increment_request_counter(current_app: flask.Flask) -> None:
Expand Down Expand Up @@ -193,7 +193,9 @@ def save_all_viewables_and_return_info(
data_entry.viewable_file_name = os.path.basename(saved_viewable_file_path)
data_entry.light_viewable = os.path.basename(saved_light_viewable_file_path)

database.session.commit()
session = get_session()
if session:
session.commit()

return {
"native_file_name": data_entry.native_file_name,
Expand Down Expand Up @@ -247,8 +249,14 @@ def generate_native_viewable_and_light_viewable_from_file(

data = geode_functions.load(geode_object, copied_full_path)

database.session.delete(temp_data_entry)
database.session.flush()
# Remplacer :
# database.session.delete(temp_data_entry)
# database.session.flush()
# Par :
session = get_session()
if session:
session.delete(temp_data_entry)
session.flush()

return save_all_viewables_and_return_info(
geode_object,
Expand Down
7 changes: 5 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Local application imports
from app import app
from src.opengeodeweb_back.database import initialize_database
from opengeodeweb_microservice.database.connection import init_database

TEST_ID = "1"

Expand All @@ -28,7 +28,10 @@ def copy_data():
print("Current working directory:", os.getcwd())
print("Directory contents:", os.listdir("."))

initialize_database(app)
init_database(app)
# print(list(app.blueprints.keys()))
# for rule in app.url_map.iter_rules():
# print(f"Route: {rule.rule} -> {rule.endpoint}")


@pytest.fixture
Expand Down
42 changes: 22 additions & 20 deletions tests/test_models_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import flask

from src.opengeodeweb_back import geode_functions
from src.opengeodeweb_back.data import Data
from src.opengeodeweb_back.database import database
from opengeodeweb_microservice.microservice.data import Data
from opengeodeweb_microservice.database.connection import get_session


def test_model_mesh_components(client, test_id):
Expand Down Expand Up @@ -33,22 +33,24 @@ def test_extract_brep_uuids(client, test_id):
brep_filename = "cube.og_brep"

with client.application.app_context():
data_entry = Data.create(geode_object="BRep", input_file=brep_filename)
data_entry = Data.create(
geode_object="BRep",
input_file=brep_filename,
)
data_entry.native_file_name = brep_filename
database.session.commit()

data_path = geode_functions.data_file_path(data_entry.id, brep_filename)
os.makedirs(os.path.dirname(data_path), exist_ok=True)
shutil.copy(f"./tests/data/{brep_filename}", data_path)

json_data = {"id": data_entry.id}
response = client.post(route, json=json_data)

assert response.status_code == 200
uuid_dict = response.json["uuid_dict"]
assert isinstance(uuid_dict, dict)
expected_keys = {"Block", "Line", "Surface", "Corner"}
assert any(key in uuid_dict for key in expected_keys)
for key, value in uuid_dict.items():
assert isinstance(value, list)
assert all(isinstance(v, str) for v in value)
session = get_session()
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
uuid_dict = response.json["uuid_dict"]
assert isinstance(uuid_dict, dict)
48 changes: 26 additions & 22 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from werkzeug.datastructures import FileStorage

# Local application imports
from opengeodeweb_microservice.microservice.data import Data
from opengeodeweb_microservice.database.connection import get_session
from src.opengeodeweb_back import geode_functions, test_utils
from src.opengeodeweb_back.data import Data
from src.opengeodeweb_back.database import database


def test_allowed_files(client):
Expand Down Expand Up @@ -173,17 +173,15 @@ def test_texture_coordinates(client, test_id):
with client.application.app_context():
data = Data.create(geode_object="PolygonalSurface3D", input_file="hat.vtp")
data.native_file_name = "hat.vtp"
database.session.commit()
session = get_session()
if session:
session.commit()

data_path = geode_functions.data_file_path(data.id, "hat.vtp")
print(data_path)
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)

response = client.post(
"/texture_coordinates",
json={"id": data.id},
)
assert os.path.exists(data_path), f"File not found at {data_path}"
response = client.post("/texture_coordinates", json={"id": data.id})
assert response.status_code == 200
texture_coordinates = response.json["texture_coordinates"]
assert type(texture_coordinates) is list
Expand All @@ -197,13 +195,14 @@ def test_vertex_attribute_names(client, test_id):
with client.application.app_context():
data = Data.create(geode_object="PolygonalSurface3D", input_file="test.vtp")
data.native_file_name = "test.vtp"
database.session.commit()
session = get_session()
if session:
session.commit()

data_path = geode_functions.data_file_path(data.id, "test.vtp")
data_path = geode_functions.data_file_path(data.id, data.native_file_name)
os.makedirs(os.path.dirname(data_path), exist_ok=True)
if os.path.exists("./tests/data/hat.vtp"):
shutil.copy("./tests/data/hat.vtp", data_path)

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
vertex_attribute_names = response.json["vertex_attribute_names"]
Expand All @@ -218,12 +217,14 @@ def test_polygon_attribute_names(client, test_id):
with client.application.app_context():
data = Data.create(geode_object="PolygonalSurface3D", input_file="test.vtp")
data.native_file_name = "test.vtp"
database.session.commit()
session = get_session()
if session:
session.commit()

data_path = geode_functions.data_file_path(data.id, "test.vtp")
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)

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
polygon_attribute_names = response.json["polygon_attribute_names"]
Expand All @@ -238,13 +239,16 @@ def test_polyhedron_attribute_names(client, test_id):
with client.application.app_context():
data = Data.create(geode_object="PolyhedralSolid3D", input_file="test.vtu")
data.native_file_name = "test.vtu"
database.session.commit()
session = get_session()
if session:
session.commit()

data_path = geode_functions.data_file_path(data.id, "test.vtu")
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)
assert response.status_code == 200
polyhedron_attribute_names = response.json["polyhedron_attribute_names"]
assert type(polyhedron_attribute_names) is list
Expand Down
Loading
Loading