Skip to content

Commit 7451bf7

Browse files
committed
test modified to fit with new folder_path (refacto needed)
1 parent 9027f76 commit 7451bf7

File tree

4 files changed

+89
-38
lines changed

4 files changed

+89
-38
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ __pycache__
99
.vscode
1010
uploads
1111
node_modules
12-
schemas.json
12+
schemas.json
13+
tmp

tests/conftest.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Standard library imports
22
import time
33
import shutil
4+
import os
45

56
# Third party imports
67
import pytest
8+
import uuid
79

810
# Local application imports
911
from app import app
@@ -31,3 +33,23 @@ def client():
3133
def app_context():
3234
with app.app_context():
3335
yield
36+
37+
@pytest.fixture
38+
def uuid_project_structure():
39+
uuid_project = uuid.uuid4().hex
40+
uuid_data = uuid.uuid4().hex
41+
42+
base_path = os.path.join("tmp", "vease", uuid_project)
43+
data_path = os.path.join(base_path, uuid_data)
44+
uploads_path = os.path.join(base_path, "uploads")
45+
46+
os.makedirs(data_path, exist_ok=True)
47+
os.makedirs(uploads_path, exist_ok=True)
48+
49+
return {
50+
"uuid_project": uuid_project,
51+
"uuid_data": uuid_data,
52+
"base_path": base_path,
53+
"data_path": data_path,
54+
"uploads_path": uploads_path,
55+
}

tests/test_models_routes.py

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,58 @@
1-
def test_model_mesh_components(client):
2-
route = f"/models/vtm_component_indices"
3-
get_full_data = lambda: {"id": "cube"}
4-
json = get_full_data()
5-
response = client.post(route, json=json)
6-
assert response.status_code == 200
1+
import shutil
2+
import os
73

8-
uuid_dict = response.json["uuid_to_flat_index"]
9-
assert isinstance(uuid_dict, dict)
4+
def test_model_mesh_components(client, uuid_project_structure):
5+
route = "/models/vtm_component_indices"
6+
uuid_data = uuid_project_structure["uuid_data"]
7+
data_path = uuid_project_structure["data_path"]
108

11-
indices = list(uuid_dict.values())
12-
indices.sort()
13-
assert all(indices[i] > indices[i - 1] for i in range(1, len(indices)))
14-
for uuid in uuid_dict.keys():
15-
assert isinstance(uuid, str)
9+
shutil.copy("./tests/data/cube.vtm", os.path.join(data_path, "viewable.vtm"))
1610

11+
original_path = client.application.config["DATA_FOLDER_PATH"]
12+
client.application.config["DATA_FOLDER_PATH"] = uuid_project_structure["base_path"]
1713

18-
def test_extract_brep_uuids(client):
14+
try:
15+
response = client.post(route, json={"id": uuid_data})
16+
assert response.status_code == 200
17+
uuid_dict = response.json["uuid_to_flat_index"]
18+
assert isinstance(uuid_dict, dict)
19+
20+
indices = list(uuid_dict.values())
21+
indices.sort()
22+
assert all(indices[i] > indices[i - 1] for i in range(1, len(indices)))
23+
for uuid_key in uuid_dict.keys():
24+
assert isinstance(uuid_key, str)
25+
finally:
26+
client.application.config["DATA_FOLDER_PATH"] = original_path
27+
28+
29+
30+
def test_extract_brep_uuids(client, uuid_project_structure):
1931
route = "/models/mesh_components"
20-
json_data = {"filename": "cube.og_brep", "geode_object": "BRep"}
21-
response = client.post(route, json=json_data)
22-
23-
assert response.status_code == 200
24-
uuid_dict = response.json["uuid_dict"]
25-
assert isinstance(uuid_dict, dict)
26-
expected_keys = {"Block", "Line", "Surface", "Corner"}
27-
assert any(key in uuid_dict for key in expected_keys)
28-
for key, value in uuid_dict.items():
29-
assert isinstance(value, list)
30-
assert all(isinstance(v, str) for v in value)
32+
uuid_data = uuid_project_structure["uuid_data"]
33+
data_path = uuid_project_structure["data_path"]
34+
35+
shutil.copy("./tests/data/cube.og_brep", os.path.join(data_path, "cube.og_brep"))
36+
37+
original_path = client.application.config["DATA_FOLDER_PATH"]
38+
client.application.config["DATA_FOLDER_PATH"] = uuid_project_structure["base_path"]
39+
40+
try:
41+
json_data = {
42+
"filename": "cube.og_brep",
43+
"geode_object": "BRep",
44+
"id": uuid_data
45+
}
46+
response = client.post(route, json=json_data)
47+
assert response.status_code == 200
48+
49+
uuid_dict = response.json["uuid_dict"]
50+
assert isinstance(uuid_dict, dict)
51+
expected_keys = {"Block", "Line", "Surface", "Corner"}
52+
assert any(key in uuid_dict for key in expected_keys)
53+
for key, value in uuid_dict.items():
54+
assert isinstance(value, list)
55+
assert all(isinstance(v, str) for v in value)
56+
finally:
57+
client.application.config["DATA_FOLDER_PATH"] = original_path
58+

tests/test_utils_functions.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,22 @@ def test_handle_exception(client):
7171
assert type(data["code"]) is int
7272

7373

74-
def test_generate_native_viewable_and_light_viewable():
75-
geode_object = "BRep"
76-
folder_absolute_path = os.path.abspath("./data")
77-
data = geode_functions.load(
78-
geode_object, os.path.join(folder_absolute_path, "test.og_brep")
79-
)
80-
folder_absolute_path = "None"
81-
result = utils_functions.generate_native_viewable_and_light_viewable(
82-
geode_object, data, folder_absolute_path
83-
)
74+
def test_generate_native_viewable_and_light_viewable(client):
75+
app = client.application
76+
with app.app_context():
77+
geode_object = "BRep"
78+
data = geode_functions.load(geode_object, "./tests/data/test.og_brep")
79+
80+
result = utils_functions.generate_native_viewable_and_light_viewable(
81+
geode_object, data
82+
)
83+
8484
assert type(result) is dict
8585
assert type(result["name"]) is str
8686
assert type(result["native_file_name"]) is str
87-
assert re.match(r"[0-9a-f]{32}\.[a-zA-Z0-9]+", result["native_file_name"])
87+
assert result["native_file_name"] == "native.og_brep"
8888
assert type(result["viewable_file_name"]) is str
89-
assert re.match(r"[0-9a-f]{32}\.[a-zA-Z0-9]+", result["viewable_file_name"])
89+
assert result["viewable_file_name"] == "viewable.vtm"
9090
assert type(result["id"]) is str
9191
assert re.match(r"[0-9a-f]{32}", result["id"])
9292
assert type(result["object_type"]) is str

0 commit comments

Comments
 (0)