Skip to content

Commit de811b8

Browse files
SpliiTgithub-actions[bot]
authored andcommitted
Apply prepare changes
1 parent 6d1ac42 commit de811b8

File tree

4 files changed

+60
-48
lines changed

4 files changed

+60
-48
lines changed

requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ markupsafe==3.0.3
3636
# flask
3737
# jinja2
3838
# werkzeug
39-
opengeode-core==15.29.0
39+
opengeode-core==15.27.4
4040
# via
4141
# -r requirements.in
4242
# geode-common
@@ -59,7 +59,7 @@ opengeode-io==7.4.0
5959
# -r requirements.in
6060
# geode-viewables
6161
# opengeode-geosciencesio
62-
sqlalchemy==2.0.43
62+
sqlalchemy==2.0.44
6363
# via flask-sqlalchemy
6464
typing-extensions==4.15.0
6565
# via sqlalchemy
@@ -69,4 +69,3 @@ werkzeug==3.1.2
6969
# flask
7070
# flask-cors
7171

72-
opengeodeweb-microservice~=1.0

src/opengeodeweb_back/app.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Packages"""
2+
23
import argparse
34
import os
45
import time
@@ -54,14 +55,17 @@
5455
utils_functions.kill_task, SECONDS_BETWEEN_SHUTDOWNS, app
5556
)
5657

58+
5759
@app.errorhandler(HTTPException)
5860
def errorhandler(e: HTTPException) -> tuple[dict[str, Any], int] | Response:
5961
return utils_functions.handle_exception(e)
6062

63+
6164
@app.errorhandler(Exception)
6265
def handle_generic_exception(e: Exception) -> Response:
6366
return flask.make_response({"error": str(e)}, 500)
6467

68+
6569
@app.route(
6670
"/error",
6771
methods=["POST"],
@@ -70,17 +74,20 @@ def return_error() -> Response:
7074
flask.abort(500, f"Test")
7175
return flask.make_response({}, 500)
7276

77+
7378
@app.route("/", methods=["POST"])
7479
@cross_origin()
7580
def root() -> Response:
7681
return flask.make_response({}, 200)
7782

83+
7884
@app.route("/kill", methods=["POST"])
7985
@cross_origin()
8086
def kill() -> None:
8187
print("Manual server kill, shutting down...", flush=True)
8288
os._exit(0)
8389

90+
8491
def run_server() -> None:
8592
parser = argparse.ArgumentParser(
8693
prog="OpenGeodeWeb-Back", description="Backend server for OpenGeodeWeb"
@@ -142,6 +149,7 @@ def run_server() -> None:
142149
print(f"Database initialized at: {db_path}", flush=True)
143150
app.run(debug=args.debug, host=args.host, port=args.port, ssl_context=SSL)
144151

152+
145153
# ''' Main '''
146154
if __name__ == "__main__":
147155
run_server()

src/opengeodeweb_back/routes/create/blueprint_create.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
import json
33
import os
44
from typing import Any, TypedDict
5+
56
# Third party imports
67
import flask
78
import opengeode
9+
810
# Local application imports
911
from opengeodeweb_back import geode_functions, utils_functions
1012
from opengeodeweb_back.utils_functions import save_all_viewables_and_return_info
@@ -15,29 +17,31 @@
1517
# --- Type definitions ---
1618
type SchemaDict = dict[str, Any]
1719

20+
1821
class PointDict(TypedDict):
1922
x: float
2023
y: float
2124

25+
2226
class CreatePointParams(TypedDict):
2327
name: str
2428
x: float
2529
y: float
2630
z: float
2731

32+
2833
class CreateAOIParams(TypedDict):
2934
name: str
3035
points: list[PointDict]
3136
z: float
3237

38+
3339
# Load schemas
3440
with open(os.path.join(schemas, "create_point.json"), "r") as file:
3541
create_point_json: SchemaDict = json.load(file)
3642

37-
@routes.route(
38-
create_point_json["route"],
39-
methods=create_point_json["methods"]
40-
)
43+
44+
@routes.route(create_point_json["route"], methods=create_point_json["methods"])
4145
def create_point() -> flask.Response:
4246
"""Endpoint to create a single point in 3D space."""
4347
print(f"create_point : {flask.request=}", flush=True)
@@ -67,14 +71,13 @@ def create_point() -> flask.Response:
6771
raise ValueError("binary_light_viewable is missing in the result")
6872
return flask.make_response(result, 200)
6973

74+
7075
# Load schema for AOI creation
7176
with open(os.path.join(schemas, "create_aoi.json"), "r") as file:
7277
create_aoi_json: SchemaDict = json.load(file)
7378

74-
@routes.route(
75-
create_aoi_json["route"],
76-
methods=create_aoi_json["methods"]
77-
)
79+
80+
@routes.route(create_aoi_json["route"], methods=create_aoi_json["methods"])
7881
def create_aoi() -> flask.Response:
7982
"""Endpoint to create an Area of Interest (AOI) as an EdgedCurve3D."""
8083
print(f"create_aoi : {flask.request=}", flush=True)
@@ -104,8 +107,10 @@ def create_aoi() -> flask.Response:
104107
next_i = (i + 1) % num_vertices
105108
edge_id = builder.create_edge()
106109
builder.set_edge_vertex(opengeode.EdgeVertex(edge_id, 0), vertex_indices[i])
107-
builder.set_edge_vertex(opengeode.EdgeVertex(edge_id, 1), vertex_indices[next_i])
108-
110+
builder.set_edge_vertex(
111+
opengeode.EdgeVertex(edge_id, 1), vertex_indices[next_i]
112+
)
113+
109114
# Save and get info
110115
result = save_all_viewables_and_return_info(
111116
geode_object="EdgedCurve3D",

tests/test_create_routes.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@
1010
# Local application imports
1111
from src.opengeodeweb_back import test_utils
1212

13+
1314
@pytest.fixture
1415
def point_data() -> Dict[str, Any]:
15-
return {
16-
"name": "test_point",
17-
"x": 1.0,
18-
"y": 2.0,
19-
"z": 3.0
20-
}
16+
return {"name": "test_point", "x": 1.0, "y": 2.0, "z": 3.0}
17+
2118

2219
@pytest.fixture
2320
def aoi_data() -> Dict[str, Any]:
@@ -27,11 +24,12 @@ def aoi_data() -> Dict[str, Any]:
2724
{"x": 0.0, "y": 0.0},
2825
{"x": 1.0, "y": 0.0},
2926
{"x": 1.0, "y": 1.0},
30-
{"x": 0.0, "y": 1.0}
27+
{"x": 0.0, "y": 1.0},
3128
],
32-
"z": 0.0
29+
"z": 0.0,
3330
}
3431

32+
3533
def test_create_point(client: FlaskClient, point_data: Dict[str, Any]) -> None:
3634
"""Test the creation of a point with valid data."""
3735
route: str = "/opengeodeweb_back/create/create_point"
@@ -54,7 +52,8 @@ def test_create_point(client: FlaskClient, point_data: Dict[str, Any]) -> None:
5452
assert response_data["geode_object"] == "PointSet3D"
5553

5654
# Test with missing parameters
57-
test_utils.test_route_wrong_params(client, route, lambda: point_data.copy()) # type: ignore
55+
test_utils.test_route_wrong_params(client, route, lambda: point_data.copy()) # type: ignore
56+
5857

5958
def test_create_aoi(client: FlaskClient, aoi_data: Dict[str, Any]) -> None:
6059
"""Test the creation of an AOI with valid data."""
@@ -78,7 +77,8 @@ def test_create_aoi(client: FlaskClient, aoi_data: Dict[str, Any]) -> None:
7877
assert response_data["geode_object"] == "EdgedCurve3D"
7978

8079
# Test with missing parameters
81-
test_utils.test_route_wrong_params(client, route, lambda: aoi_data.copy())# type: ignore
80+
test_utils.test_route_wrong_params(client, route, lambda: aoi_data.copy()) # type: ignore
81+
8282

8383
def test_create_point_with_invalid_data(client: FlaskClient) -> None:
8484
"""Test the point creation endpoint with invalid data."""
@@ -89,21 +89,20 @@ def test_create_point_with_invalid_data(client: FlaskClient) -> None:
8989
"name": "invalid_point",
9090
"x": "not_a_number",
9191
"y": 2.0,
92-
"z": 3.0
92+
"z": 3.0,
9393
}
9494
response = client.post(route, json=invalid_data)
9595
assert response.status_code == 400
9696

9797
# Test with missing coordinates
98-
invalid_data = {
99-
"name": "invalid_point",
100-
"y": 2.0,
101-
"z": 3.0
102-
}
98+
invalid_data = {"name": "invalid_point", "y": 2.0, "z": 3.0}
10399
response = client.post(route, json=invalid_data)
104100
assert response.status_code == 400
105101

106-
def test_create_aoi_with_invalid_data(client: FlaskClient, aoi_data: Dict[str, Any]) -> None:
102+
103+
def test_create_aoi_with_invalid_data(
104+
client: FlaskClient, aoi_data: Dict[str, Any]
105+
) -> None:
107106
"""Test the AOI creation endpoint with invalid data."""
108107
route: str = "/opengeodeweb_back/create/create_aoi"
109108

@@ -114,32 +113,26 @@ def test_create_aoi_with_invalid_data(client: FlaskClient, aoi_data: Dict[str, A
114113
{"x": "not_a_number", "y": 0.0},
115114
{"x": 1.0, "y": 0.0},
116115
{"x": 1.0, "y": 1.0},
117-
{"x": 0.0, "y": 1.0}
118-
]
116+
{"x": 0.0, "y": 1.0},
117+
],
119118
}
120119
response = client.post(route, json=invalid_data)
121120
assert response.status_code == 400
122121

123122
# Test with too few points
124-
invalid_data = {
125-
**aoi_data,
126-
"points": [
127-
{"x": 0.0, "y": 0.0},
128-
{"x": 1.0, "y": 0.0}
129-
]
130-
}
123+
invalid_data = {**aoi_data, "points": [{"x": 0.0, "y": 0.0}, {"x": 1.0, "y": 0.0}]}
131124
response = client.post(route, json=invalid_data)
132125
assert response.status_code == 400
133126

134127
# Test with invalid z value
135-
invalid_data = {
136-
**aoi_data,
137-
"z": "not_a_number"
138-
}
128+
invalid_data = {**aoi_data, "z": "not_a_number"}
139129
response = client.post(route, json=invalid_data)
140130
assert response.status_code == 400
141131

142-
def test_create_point_file_generation(client: FlaskClient, point_data: Dict[str, Any]) -> None:
132+
133+
def test_create_point_file_generation(
134+
client: FlaskClient, point_data: Dict[str, Any]
135+
) -> None:
143136
"""Test that the point creation generates the correct files."""
144137
route: str = "/opengeodeweb_back/create/create_point"
145138

@@ -162,7 +155,9 @@ def test_create_point_file_generation(client: FlaskClient, point_data: Dict[str,
162155
assert os.path.exists(native_file_path)
163156

164157
# Check viewable file exists
165-
viewable_file_path: str = os.path.join(data_folder, response_data["viewable_file_name"])
158+
viewable_file_path: str = os.path.join(
159+
data_folder, response_data["viewable_file_name"]
160+
)
166161
assert os.path.exists(viewable_file_path)
167162

168163
# Check light viewable file exists if present
@@ -174,7 +169,10 @@ def test_create_point_file_generation(client: FlaskClient, point_data: Dict[str,
174169
assert response_data["native_file_name"].endswith(".og_pts3d")
175170
assert response_data["viewable_file_name"].endswith(".vtp")
176171

177-
def test_create_aoi_file_generation(client: FlaskClient, aoi_data: Dict[str, Any]) -> None:
172+
173+
def test_create_aoi_file_generation(
174+
client: FlaskClient, aoi_data: Dict[str, Any]
175+
) -> None:
178176
"""Test that the AOI creation generates the correct files."""
179177
route: str = "/opengeodeweb_back/create/create_aoi"
180178

@@ -197,7 +195,9 @@ def test_create_aoi_file_generation(client: FlaskClient, aoi_data: Dict[str, Any
197195
assert os.path.exists(native_file_path)
198196

199197
# Check viewable file exists
200-
viewable_file_path: str = os.path.join(data_folder, response_data["viewable_file_name"])
198+
viewable_file_path: str = os.path.join(
199+
data_folder, response_data["viewable_file_name"]
200+
)
201201
assert os.path.exists(viewable_file_path)
202202

203203
# Check light viewable file exists if present
@@ -207,4 +207,4 @@ def test_create_aoi_file_generation(client: FlaskClient, aoi_data: Dict[str, Any
207207

208208
# Verify file extensions
209209
assert response_data["native_file_name"].endswith(".og_edc3d")
210-
assert response_data["viewable_file_name"].endswith(".vtp")
210+
assert response_data["viewable_file_name"].endswith(".vtp")

0 commit comments

Comments
 (0)