Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/refactor inspector #309

Merged
merged 4 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 2 additions & 72 deletions blueprints/tools/blueprint_validity_checker.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Standard library imports
import os
#

# Third party imports
import flask
import flask_cors
import werkzeug
from opengeodeweb_back import geode_functions, inspector_functions
from opengeodeweb_back import geode_functions
import json

validity_checker_routes = flask.Blueprint("validity_checker_routes", __name__)
Expand All @@ -32,72 +31,3 @@ def validity_checker_versions():
return flask.make_response(
{"versions": geode_functions.versions(list_packages)}, 200
)


with open("blueprints/tools/validity_checker_test_names.json", "r") as file:
validity_checker_test_names_json = json.load(file)


@validity_checker_routes.route(
validity_checker_test_names_json["route"],
methods=validity_checker_test_names_json["methods"],
)
def validity_checker_test_names():
geode_functions.validate_request(flask.request, validity_checker_test_names_json)
model_checks = inspector_functions.json_return(
inspector_functions.inspectors()[flask.request.json["input_geode_object"]][
"tests_names"
]
)

return flask.make_response({"model_checks": model_checks}, 200)


with open("blueprints/tools/validity_checker_inspect_file.json", "r") as file:
validity_checker_inspect_file_json = json.load(file)


@validity_checker_routes.route(
validity_checker_inspect_file_json["route"],
methods=validity_checker_inspect_file_json["methods"],
)
def validity_checker_inspect_file():
geode_functions.validate_request(flask.request, validity_checker_inspect_file_json)
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]

secure_filename = werkzeug.utils.secure_filename(flask.request.json["filename"])
file_path = os.path.abspath(os.path.join(UPLOAD_FOLDER, secure_filename))
data = geode_functions.load(flask.request.json["input_geode_object"], file_path)
inspector = geode_functions.inspector(
flask.request.json["input_geode_object"], data
)
test_result = getattr(inspector, flask.request.json["test"])()

if type(test_result) == int:
expected_result = 0
elif type(test_result) == list:
expected_result = []
elif type(test_result) == dict:
expected_result = {}

if test_result != expected_result or type(test_result) != type(expected_result):
if type(test_result) is list:
if type(test_result[0]) is tuple:
temp_test_result = []
for tuple_item in test_result:
temp_list = []
for index in range(len(tuple_item)):
temp_list.append(tuple_item[index].string())
temp_test_result.append(temp_list)
test_result = temp_test_result
result = test_result == expected_result and type(test_result) == type(
expected_result
)

if result is False:
test_name = flask.request.json["test"]
print(f"Wrong test result: {test_name}", flush=True)

return flask.make_response(
{"result": result, "list_invalidities": str(test_result)}, 200
)
25 changes: 0 additions & 25 deletions blueprints/tools/validity_checker_inspect_file.json

This file was deleted.

17 changes: 0 additions & 17 deletions blueprints/tools/validity_checker_test_names.json

This file was deleted.

65 changes: 25 additions & 40 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --pre requirements.in
# pip-compile requirements.in
#
asgiref==3.7.2
asgiref==3.8.1
# via
# flask
# opengeodeweb-back
Expand All @@ -13,19 +13,15 @@ attrs==23.2.0
# jsonschema
# opengeodeweb-back
# referencing
blinker==1.7.0
blinker==1.8.1
# via
# flask
# opengeodeweb-back
click==8.1.7
# via
# flask
# opengeodeweb-back
colorama==0.4.6
# via
# click
# opengeodeweb-back
flask[async]==3.0.1
flask[async]==3.0.3
# via
# -r requirements.in
# flask-cors
Expand All @@ -34,13 +30,13 @@ flask-cors==4.0.0
# via
# -r requirements.in
# opengeodeweb-back
geode-background==7.7.1
geode-background==7.9.8
# via
# geode-explicit
# geode-implicit
# geode-simplex
# opengeodeweb-back
geode-common==30.1.2
geode-common==31.0.8
# via
# geode-background
# geode-explicit
Expand All @@ -49,31 +45,27 @@ geode-common==30.1.2
# geode-simplex
# geode-viewables
# opengeodeweb-back
geode-conversion==5.2.1
geode-conversion==5.2.8
# via
# geode-explicit
# geode-implicit
# opengeodeweb-back
geode-explicit==4.4.3
geode-explicit==4.7.5
# via
# geode-implicit
# opengeodeweb-back
geode-implicit==2.6.1
geode-implicit==2.8.6
# via opengeodeweb-back
geode-numerics==4.3.0
geode-numerics==4.3.3
# via
# geode-implicit
# geode-simplex
# opengeodeweb-back
geode-simplex==6.5.1
geode-simplex==6.7.4
# via opengeodeweb-back
geode-viewables==2.2.0
geode-viewables==2.2.2
# via opengeodeweb-back
importlib-metadata==7.0.1
# via
# flask
# opengeodeweb-back
itsdangerous==2.1.2
itsdangerous==2.2.0
# via
# flask
# opengeodeweb-back
Expand All @@ -87,12 +79,12 @@ jsonschema-specifications==2023.12.1
# via
# jsonschema
# opengeodeweb-back
markupsafe==2.1.4
markupsafe==2.1.5
# via
# jinja2
# opengeodeweb-back
# werkzeug
opengeode-core==14.13.2
opengeode-core==14.19.2
# via
# geode-background
# geode-common
Expand All @@ -107,51 +99,44 @@ opengeode-core==14.13.2
# opengeode-inspector
# opengeode-io
# opengeodeweb-back
opengeode-geosciences==7.4.0
opengeode-geosciences==7.6.4
# via
# geode-implicit
# geode-viewables
# opengeode-geosciencesio
# opengeodeweb-back
opengeode-geosciencesio==4.6.0
opengeode-geosciencesio==4.7.6
# via
# geode-implicit
# opengeodeweb-back
opengeode-inspector==4.0.6
opengeode-inspector==5.1.3
# via
# geode-explicit
# geode-implicit
# geode-simplex
# opengeodeweb-back
opengeode-io==6.4.0
opengeode-io==6.5.1
# via
# geode-implicit
# geode-viewables
# opengeode-geosciencesio
# opengeodeweb-back
opengeodeweb-back==4.0.0
opengeodeweb-back==4.1.1
# via -r requirements.in
python-dotenv==1.0.1
# via -r requirements.in
referencing==0.33.0
referencing==0.35.0
# via
# jsonschema
# jsonschema-specifications
# opengeodeweb-back
rpds-py==0.17.1
rpds-py==0.18.0
# via
# jsonschema
# opengeodeweb-back
# referencing
typing-extensions==4.9.0
# via
# asgiref
# opengeodeweb-back
werkzeug==3.0.1
werkzeug==3.0.2
# via
# -r requirements.in
# flask
# opengeodeweb-back
zipp==3.17.0
# via
# importlib-metadata
# opengeodeweb-back
82 changes: 0 additions & 82 deletions tests/test_validity_checker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import os
import base64
from werkzeug.datastructures import FileStorage

base_route = "/tools/validity_checker"


Expand All @@ -12,81 +8,3 @@ def test_versions(client):
assert type(versions) is list
for version in versions:
assert type(version) is dict


def test_test_names(client):
ObjectArray = [
"BRep",
"CrossSection",
"EdgedCurve2D",
"EdgedCurve3D",
"Graph",
"HybridSolid3D",
"PointSet2D",
"PointSet3D",
"PolygonalSurface2D",
"PolygonalSurface3D",
"PolyhedralSolid3D",
"RegularGrid2D",
"RegularGrid3D",
"Section",
"StructuralModel",
"TetrahedralSolid3D",
"TriangulatedSurface2D",
"TriangulatedSurface3D",
"VertexSet",
]

for geode_object in ObjectArray:
# Normal test with all objects
response = client.post(
f"{base_route}/tests_names",
json={"input_geode_object": geode_object},
)
assert response.status_code == 200
model_checks = response.json["model_checks"]

assert type(model_checks) is list
for model_check in model_checks:
assert type(model_check) is dict
is_leaf = model_check["is_leaf"]
route = model_check["route"]
children = model_check["children"]
assert type(is_leaf) is bool
assert type(route) is str
assert type(children) is list
for check in children:
assert type(check) is dict
if check["is_leaf"] == True:
print("is_leaf")
response_test = client.post(
f"{base_route}/inspect_file",
json={
"object": "BRep",
"filename": "corbi.og_brep",
"test": check["route"],
},
)

assert response_test.status_code == 200
else:
print("not is_leaf")


def test_inspect_file(client):
# Test with file

filename = "corbi.og_brep"

response = client.put(
"opengeodeweb_back/upload_file",
data={"file": FileStorage(open(f"./tests/{filename}", "rb"))},
)
assert response.status_code == 201

response = client.post(
f"{base_route}/inspect_file",
json={
"filename": filename,
},
)
Loading