Skip to content

Commit 28df816

Browse files
committed
feat(routes): add tests
1 parent e8fba7c commit 28df816

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed

tests/test_routes.py

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import os
2+
import base64
3+
from werkzeug.datastructures import FileStorage
4+
5+
6+
def test_allowed_files(client):
7+
route = f"/allowed_files"
8+
response = client.post(route, json={"key": None})
9+
assert response.status_code == 200
10+
extensions = response.json["extensions"]
11+
assert type(extensions) is list
12+
for extension in extensions:
13+
assert type(extension) is str
14+
15+
16+
def test_allowed_objects(client):
17+
route = f"/allowed_objects"
18+
19+
def get_full_data():
20+
return {
21+
"filename": "corbi.og_brep",
22+
"key": None,
23+
}
24+
25+
# Normal test with filename 'corbi.og_brep'
26+
response = client.post(route, json=get_full_data())
27+
assert response.status_code == 200
28+
allowed_objects = response.json["allowed_objects"]
29+
assert type(allowed_objects) is list
30+
for allowed_object in allowed_objects:
31+
assert type(allowed_object) is str
32+
33+
for key, value in get_full_data().items():
34+
json = get_full_data()
35+
json.pop(key)
36+
response = client.post(route, json=json)
37+
assert response.status_code == 400
38+
error_description = response.json["description"]
39+
assert error_description == f"Validation error: '{key}' is a required property"
40+
41+
42+
def test_upload_file(client):
43+
response = client.put(
44+
f"/upload_file",
45+
data={"content": FileStorage(open("./tests/corbi.og_brep", "rb"))},
46+
)
47+
48+
assert response.status_code == 201
49+
50+
51+
def test_missing_files(client):
52+
route = f"/missing_files"
53+
54+
def get_full_data():
55+
return {
56+
"input_geode_object": "BRep",
57+
"filename": "corbi.og_brep",
58+
}
59+
60+
json = get_full_data()
61+
response = client.post(
62+
route,
63+
json=json,
64+
)
65+
66+
assert response.status_code == 200
67+
has_missing_files = response.json["has_missing_files"]
68+
mandatory_files = response.json["mandatory_files"]
69+
additional_files = response.json["additional_files"]
70+
assert type(has_missing_files) is bool
71+
assert type(mandatory_files) is list
72+
assert type(additional_files) is list
73+
74+
for key, value in get_full_data().items():
75+
json = get_full_data()
76+
json.pop(key)
77+
response = client.post(route, json=json)
78+
assert response.status_code == 400
79+
error_description = response.json["description"]
80+
assert error_description == f"Validation error: '{key}' is a required property"
81+
82+
83+
def test_geographic_coordinate_systems(client):
84+
route = f"/geographic_coordinate_systems"
85+
86+
# Normal test with geode_object 'BRep'
87+
response = client.post(route, json={"input_geode_object": "BRep"})
88+
assert response.status_code == 200
89+
crs_list = response.json["crs_list"]
90+
assert type(crs_list) is list
91+
for crs in crs_list:
92+
assert type(crs) is dict
93+
94+
# Test without geode_object
95+
response = client.post(route, json={})
96+
assert response.status_code == 400
97+
error_message = response.json["description"]
98+
assert (
99+
error_message == "Validation error: 'input_geode_object' is a required property"
100+
)
101+
102+
103+
def test_geode_objects_and_output_extensions(client):
104+
route = f"/geode_objects_and_output_extensions"
105+
106+
def get_full_data():
107+
return {"input_geode_object": "BRep", "filename": "corbi.og_brep"}
108+
109+
response = client.post(route, json=get_full_data())
110+
111+
assert response.status_code == 200
112+
geode_objects_and_output_extensions = response.json[
113+
"geode_objects_and_output_extensions"
114+
]
115+
assert type(geode_objects_and_output_extensions) is list
116+
for geode_object_and_output_extensions in geode_objects_and_output_extensions:
117+
assert type(geode_object_and_output_extensions) is dict
118+
assert type(geode_object_and_output_extensions["geode_object"]) is str
119+
assert type(geode_object_and_output_extensions["output_extensions"]) is list
120+
121+
# Test without input_geode_object
122+
response = client.post(route, json={})
123+
assert response.status_code == 400
124+
error_message = response.json["description"]
125+
assert (
126+
error_message == "Validation error: 'input_geode_object' is a required property"
127+
)

0 commit comments

Comments
 (0)