Skip to content

Commit b6b6e3b

Browse files
committed
tests' paths fixed
1 parent 66162b0 commit b6b6e3b

File tree

6 files changed

+41
-36
lines changed

6 files changed

+41
-36
lines changed

src/opengeodeweb_back/app.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ def errorhandler(e):
6565
return utils_functions.handle_exception(e)
6666

6767

68+
@app.route(
69+
"/error",
70+
methods=["POST"],
71+
)
72+
def return_error():
73+
flask.abort(500, f"Test")
74+
75+
6876
@app.route("/", methods=["POST"])
6977
@cross_origin()
7078
def root():

src/tests/conftest.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,14 @@ def configure_test_environment() -> Generator[None, None, None]:
2222
base_path = Path(__file__).parent
2323
test_data_path = base_path / "data"
2424

25-
# Clean up any existing test data
2625
shutil.rmtree("./data", ignore_errors=True)
27-
if test_data_path.exists():
28-
shutil.copytree(test_data_path, f"./data/{TEST_ID}/", dirs_exist_ok=True)
26+
shutil.copytree(test_data_path, f"./data/{TEST_ID}/", dirs_exist_ok=True)
2927

30-
# Configure app for testing
3128
app.config["TESTING"] = True
3229
app.config["SERVER_NAME"] = "TEST"
3330
app.config["DATA_FOLDER_PATH"] = "./data/"
34-
app.config["UPLOAD_FOLDER"] = "./tests/data/"
31+
app.config["UPLOAD_FOLDER"] = "./src/tests/data/"
3532

36-
# Setup database
3733
db_path = os.path.join(base_path, "data", "project.db")
3834
app.config["SQLALCHEMY_DATABASE_URI"] = f"sqlite:///{db_path}"
3935

@@ -45,7 +41,6 @@ def configure_test_environment() -> Generator[None, None, None]:
4541

4642
yield
4743

48-
# Cleanup after tests
4944
tmp_data_path = app.config.get("DATA_FOLDER_PATH")
5045
if tmp_data_path and os.path.exists(tmp_data_path):
5146
shutil.rmtree(tmp_data_path, ignore_errors=True)

src/tests/test_geode_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Third party imports
66

77
# Local application imports
8-
from src.opengeodeweb_back import geode_functions, geode_objects
8+
from opengeodeweb_back import geode_functions, geode_objects
99

1010

1111
data_folder = os.path.join(os.path.dirname(__file__), "data")

src/tests/test_models_routes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
import shutil
33
import flask
44

5-
from src.opengeodeweb_back import geode_functions
5+
from opengeodeweb_back import geode_functions
66
from opengeodeweb_microservice.database.data import Data
77
from opengeodeweb_microservice.database.connection import get_session
88

99

1010
def test_model_mesh_components(client, test_id):
11-
route = f"/models/vtm_component_indices"
11+
route = "/opengeodeweb_back/models/vtm_component_indices"
1212

1313
with client.application.app_context():
1414
data_path = geode_functions.data_file_path(test_id, "viewable.vtm")
1515
os.makedirs(os.path.dirname(data_path), exist_ok=True)
16-
shutil.copy("./tests/data/cube.vtm", data_path)
16+
shutil.copy("./src/tests/data/cube.vtm", data_path)
1717

1818
response = client.post(route, json={"id": test_id})
1919
assert response.status_code == 200
@@ -29,7 +29,7 @@ def test_model_mesh_components(client, test_id):
2929

3030

3131
def test_extract_brep_uuids(client, test_id):
32-
route = "/models/mesh_components"
32+
route = "/opengeodeweb_back/models/mesh_components"
3333
brep_filename = "cube.og_brep"
3434

3535
with client.application.app_context():
@@ -42,7 +42,7 @@ def test_extract_brep_uuids(client, test_id):
4242
if session:
4343
session.commit()
4444

45-
src_path = os.path.join("tests", "data", brep_filename)
45+
src_path = os.path.join("src", "tests", "data", brep_filename)
4646
dest_path = os.path.join(
4747
flask.current_app.config["DATA_FOLDER_PATH"], data_entry.id, brep_filename
4848
)

src/tests/test_routes.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
# Local application imports
99
from opengeodeweb_microservice.database.data import Data
1010
from opengeodeweb_microservice.database.connection import get_session
11-
from src.opengeodeweb_back import geode_functions, test_utils
11+
from opengeodeweb_back import geode_functions, test_utils
1212

1313

1414
def test_allowed_files(client):
15-
route = f"/allowed_files"
15+
route = f"/opengeodeweb_back/allowed_files"
1616
get_full_data = lambda: {"supported_feature": "None"}
1717
json = get_full_data()
1818
response = client.post(route, json=json)
@@ -27,7 +27,7 @@ def test_allowed_files(client):
2727

2828

2929
def test_allowed_objects(client):
30-
route = f"/allowed_objects"
30+
route = f"/opengeodeweb_back/allowed_objects"
3131

3232
def get_full_data():
3333
return {
@@ -49,14 +49,14 @@ def get_full_data():
4949

5050
def test_upload_file(client, filename="test.og_brep"):
5151
response = client.put(
52-
f"/upload_file",
53-
data={"file": FileStorage(open(f"./tests/data/{filename}", "rb"))},
52+
f"/opengeodeweb_back/upload_file",
53+
data={"file": FileStorage(open(f"./src/tests/data/{filename}", "rb"))},
5454
)
5555
assert response.status_code == 201
5656

5757

5858
def test_missing_files(client):
59-
route = f"/missing_files"
59+
route = f"/opengeodeweb_back/missing_files"
6060

6161
def get_full_data():
6262
return {
@@ -79,7 +79,7 @@ def get_full_data():
7979

8080

8181
def test_geographic_coordinate_systems(client):
82-
route = f"/geographic_coordinate_systems"
82+
route = f"/opengeodeweb_back/geographic_coordinate_systems"
8383
get_full_data = lambda: {"input_geode_object": "BRep"}
8484
# Normal test with geode_object 'BRep'
8585
response = client.post(route, json=get_full_data())
@@ -94,7 +94,7 @@ def test_geographic_coordinate_systems(client):
9494

9595

9696
def test_inspect_file(client):
97-
route = f"/inspect_file"
97+
route = f"/opengeodeweb_back/inspect_file"
9898

9999
def get_full_data():
100100
return {
@@ -115,7 +115,7 @@ def get_full_data():
115115

116116

117117
def test_geode_objects_and_output_extensions(client):
118-
route = "/geode_objects_and_output_extensions"
118+
route = "/opengeodeweb_back/geode_objects_and_output_extensions"
119119

120120
def get_full_data():
121121
return {
@@ -142,7 +142,7 @@ def get_full_data():
142142

143143
def test_save_viewable_file(client):
144144
test_upload_file(client, filename="corbi.og_brep")
145-
route = f"/save_viewable_file"
145+
route = f"/opengeodeweb_back/save_viewable_file"
146146

147147
def get_full_data():
148148
return {
@@ -179,9 +179,11 @@ def test_texture_coordinates(client, test_id):
179179

180180
data_path = geode_functions.data_file_path(data.id, data.native_file_name)
181181
os.makedirs(os.path.dirname(data_path), exist_ok=True)
182-
shutil.copy("./tests/data/hat.vtp", data_path)
182+
shutil.copy("./src/tests/data/hat.vtp", data_path)
183183
assert os.path.exists(data_path), f"File not found at {data_path}"
184-
response = client.post("/texture_coordinates", json={"id": data.id})
184+
response = client.post(
185+
"/opengeodeweb_back/texture_coordinates", json={"id": data.id}
186+
)
185187
assert response.status_code == 200
186188
texture_coordinates = response.json["texture_coordinates"]
187189
assert type(texture_coordinates) is list
@@ -190,7 +192,7 @@ def test_texture_coordinates(client, test_id):
190192

191193

192194
def test_vertex_attribute_names(client, test_id):
193-
route = f"/vertex_attribute_names"
195+
route = f"/opengeodeweb_back/vertex_attribute_names"
194196

195197
with client.application.app_context():
196198
data = Data.create(geode_object="PolygonalSurface3D", input_file="test.vtp")
@@ -201,7 +203,7 @@ def test_vertex_attribute_names(client, test_id):
201203

202204
data_path = geode_functions.data_file_path(data.id, data.native_file_name)
203205
os.makedirs(os.path.dirname(data_path), exist_ok=True)
204-
shutil.copy("./tests/data/test.vtp", data_path)
206+
shutil.copy("./src/tests/data/test.vtp", data_path)
205207
assert os.path.exists(data_path), f"File not found at {data_path}"
206208
response = client.post(route, json={"id": data.id})
207209
assert response.status_code == 200
@@ -212,7 +214,7 @@ def test_vertex_attribute_names(client, test_id):
212214

213215

214216
def test_polygon_attribute_names(client, test_id):
215-
route = f"/polygon_attribute_names"
217+
route = f"/opengeodeweb_back/polygon_attribute_names"
216218

217219
with client.application.app_context():
218220
data = Data.create(geode_object="PolygonalSurface3D", input_file="test.vtp")
@@ -223,7 +225,7 @@ def test_polygon_attribute_names(client, test_id):
223225

224226
data_path = geode_functions.data_file_path(data.id, data.native_file_name)
225227
os.makedirs(os.path.dirname(data_path), exist_ok=True)
226-
shutil.copy("./tests/data/test.vtp", data_path)
228+
shutil.copy("./src/tests/data/test.vtp", data_path)
227229
assert os.path.exists(data_path), f"File not found at {data_path}"
228230
response = client.post(route, json={"id": data.id})
229231
assert response.status_code == 200
@@ -234,7 +236,7 @@ def test_polygon_attribute_names(client, test_id):
234236

235237

236238
def test_polyhedron_attribute_names(client, test_id):
237-
route = f"/polyhedron_attribute_names"
239+
route = f"/opengeodeweb_back/polyhedron_attribute_names"
238240

239241
with client.application.app_context():
240242
data = Data.create(geode_object="PolyhedralSolid3D", input_file="test.vtu")
@@ -245,7 +247,7 @@ def test_polyhedron_attribute_names(client, test_id):
245247

246248
data_path = geode_functions.data_file_path(data.id, data.native_file_name)
247249
os.makedirs(os.path.dirname(data_path), exist_ok=True)
248-
shutil.copy("./tests/data/test.vtu", data_path)
250+
shutil.copy("./src/tests/data/test.vtu", data_path)
249251
assert os.path.exists(data_path), f"File not found at {data_path}"
250252
response = client.post(route, json={"id": data.id})
251253
print(response.json)
@@ -257,7 +259,7 @@ def test_polyhedron_attribute_names(client, test_id):
257259

258260

259261
def test_create_point(client):
260-
route = f"/create_point"
262+
route = f"/opengeodeweb_back/create_point"
261263
get_full_data = lambda: {"title": "test_point", "x": 1, "y": 2, "z": 3}
262264

263265
# Normal test with all keys

src/tests/test_utils_functions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Local application imports
1111
from opengeodeweb_microservice.database.data import Data
1212
from opengeodeweb_microservice.database.connection import get_session
13-
from src.opengeodeweb_back import geode_functions, utils_functions
13+
from opengeodeweb_back import geode_functions, utils_functions
1414

1515

1616
def test_increment_request_counter(app_context):
@@ -99,7 +99,7 @@ def test_save_all_viewables_and_return_info(client):
9999
assert os.path.exists(expected_db_path)
100100

101101
geode_object = "BRep"
102-
data = geode_functions.load(geode_object, "./tests/data/test.og_brep")
102+
data = geode_functions.load(geode_object, "./src/tests/data/test.og_brep")
103103
input_file = "test.og_brep"
104104
additional_files = ["additional_file.txt"]
105105

@@ -134,7 +134,7 @@ def test_save_all_viewables_commits_to_db(client):
134134
app = client.application
135135
with app.app_context():
136136
geode_object = "BRep"
137-
data = geode_functions.load(geode_object, "./tests/data/test.og_brep")
137+
data = geode_functions.load(geode_object, "./src/tests/data/test.og_brep")
138138
input_file = "test.og_brep"
139139
result = utils_functions.save_all_viewables_and_return_info(
140140
geode_object, data, input_file
@@ -156,7 +156,7 @@ def test_generate_native_viewable_and_light_viewable_from_object(client):
156156
app = client.application
157157
with app.app_context():
158158
geode_object = "BRep"
159-
data = geode_functions.load(geode_object, "./tests/data/test.og_brep")
159+
data = geode_functions.load(geode_object, "./src/tests/data/test.og_brep")
160160

161161
result = (
162162
utils_functions.generate_native_viewable_and_light_viewable_from_object(

0 commit comments

Comments
 (0)