Skip to content

Commit c0e82c4

Browse files
committed
finished moving tests, better app.py
1 parent b2ff0a4 commit c0e82c4

File tree

6 files changed

+16
-27
lines changed

6 files changed

+16
-27
lines changed

requirements.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ geode-common==33.11.0
77
geode-viewables==3.3.0
88
flask[async]==3.1.2
99
flask-cors==6.0.1
10-
werkzeug==3.1.3
10+
werkzeug==3.1.2
1111
flask-sqlalchemy==3.1.1

src/opengeodeweb_back/app.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@
3535
SECONDS_BETWEEN_SHUTDOWNS = float(app.config.get("SECONDS_BETWEEN_SHUTDOWNS"))
3636

3737

38-
def get_db_path_from_config():
39-
database_uri = f"{os.path.abspath(
40-
os.path.join(app.config.get('DATA_FOLDER_PATH'), app.config.get('DATABASE_FILENAME'))
41-
)}"
42-
return database_uri
43-
44-
4538
app.register_blueprint(
4639
blueprint_routes.routes,
4740
url_prefix="/opengeodeweb_back",
@@ -142,14 +135,10 @@ def run_server():
142135
flush=True,
143136
)
144137

145-
db_path = get_db_path_from_config()
146-
print("db_path", db_path, flush=True)
147-
if db_path:
148-
db_dir = os.path.dirname(db_path)
149-
if db_dir and not os.path.exists(db_dir):
150-
os.makedirs(db_dir, exist_ok=True)
151-
init_database(db_path)
152-
print(f"Database initialized at: {db_path}")
138+
db_path = os.path.join(args.data_folder_path, app.config.get("DATABASE_FILENAME"))
139+
os.makedirs(os.path.dirname(db_path), exist_ok=True)
140+
init_database(db_path)
141+
print(f"Database initialized at: {db_path}", flush=True)
153142

154143
app.run(debug=args.debug, host=args.host, port=args.port, ssl_context=SSL)
155144

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def configure_test_environment() -> Generator[None, None, None]:
2828
app.config["TESTING"] = True
2929
app.config["SERVER_NAME"] = "TEST"
3030
app.config["DATA_FOLDER_PATH"] = "./data/"
31-
app.config["UPLOAD_FOLDER"] = "./src/tests/data/"
31+
app.config["UPLOAD_FOLDER"] = "./tests/data/"
3232

3333
db_path = os.path.join(base_path, "data", "project.db")
3434
app.config["SQLALCHEMY_DATABASE_URI"] = f"sqlite:///{db_path}"

tests/test_models_routes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_model_mesh_components(client, test_id):
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("./src/tests/data/cube.vtm", data_path)
16+
shutil.copy("./tests/data/cube.vtm", data_path)
1717

1818
response = client.post(route, json={"id": test_id})
1919
assert response.status_code == 200
@@ -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("src", "tests", "data", brep_filename)
45+
src_path = os.path.join("tests", "data", brep_filename)
4646
dest_path = os.path.join(
4747
flask.current_app.config["DATA_FOLDER_PATH"], data_entry.id, brep_filename
4848
)

tests/test_routes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def get_full_data():
5050
def test_upload_file(client, filename="test.og_brep"):
5151
response = client.put(
5252
f"/opengeodeweb_back/upload_file",
53-
data={"file": FileStorage(open(f"./src/tests/data/{filename}", "rb"))},
53+
data={"file": FileStorage(open(f"./tests/data/{filename}", "rb"))},
5454
)
5555
assert response.status_code == 201
5656

@@ -179,7 +179,7 @@ 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("./src/tests/data/hat.vtp", data_path)
182+
shutil.copy("./tests/data/hat.vtp", data_path)
183183
assert os.path.exists(data_path), f"File not found at {data_path}"
184184
response = client.post(
185185
"/opengeodeweb_back/texture_coordinates", json={"id": data.id}
@@ -203,7 +203,7 @@ def test_vertex_attribute_names(client, test_id):
203203

204204
data_path = geode_functions.data_file_path(data.id, data.native_file_name)
205205
os.makedirs(os.path.dirname(data_path), exist_ok=True)
206-
shutil.copy("./src/tests/data/test.vtp", data_path)
206+
shutil.copy("./tests/data/test.vtp", data_path)
207207
assert os.path.exists(data_path), f"File not found at {data_path}"
208208
response = client.post(route, json={"id": data.id})
209209
assert response.status_code == 200
@@ -225,7 +225,7 @@ def test_polygon_attribute_names(client, test_id):
225225

226226
data_path = geode_functions.data_file_path(data.id, data.native_file_name)
227227
os.makedirs(os.path.dirname(data_path), exist_ok=True)
228-
shutil.copy("./src/tests/data/test.vtp", data_path)
228+
shutil.copy("./tests/data/test.vtp", data_path)
229229
assert os.path.exists(data_path), f"File not found at {data_path}"
230230
response = client.post(route, json={"id": data.id})
231231
assert response.status_code == 200
@@ -247,7 +247,7 @@ def test_polyhedron_attribute_names(client, test_id):
247247

248248
data_path = geode_functions.data_file_path(data.id, data.native_file_name)
249249
os.makedirs(os.path.dirname(data_path), exist_ok=True)
250-
shutil.copy("./src/tests/data/test.vtu", data_path)
250+
shutil.copy("./tests/data/test.vtu", data_path)
251251
assert os.path.exists(data_path), f"File not found at {data_path}"
252252
response = client.post(route, json={"id": data.id})
253253
print(response.json)

tests/test_utils_functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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, "./src/tests/data/test.og_brep")
102+
data = geode_functions.load(geode_object, "./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, "./src/tests/data/test.og_brep")
137+
data = geode_functions.load(geode_object, "./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, "./src/tests/data/test.og_brep")
159+
data = geode_functions.load(geode_object, "./tests/data/test.og_brep")
160160

161161
result = (
162162
utils_functions.generate_native_viewable_and_light_viewable_from_object(

0 commit comments

Comments
 (0)