Skip to content

Commit

Permalink
Merge branch 'develop' into feature/performance
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Oct 24, 2023
2 parents c403410 + 5789090 commit 03b2cad
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 58 deletions.
4 changes: 0 additions & 4 deletions openatlas/api/resources/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ class LogicalOperatorError(Exception):
pass


class NoEntityAvailable(Exception):
pass


class NoLicenseError(Exception):
pass

Expand Down
11 changes: 6 additions & 5 deletions openatlas/api/resources/resolve_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from openatlas.api.formats.rdf import rdf_output
from openatlas.api.formats.xml import subunit_xml
from openatlas.api.resources.error import (
EntityDoesNotExistError, LastEntityError, NoEntityAvailable, TypeIDError)
EntityDoesNotExistError, LastEntityError, TypeIDError)
from openatlas.api.resources.model_mapper import (
get_all_links_of_entities, get_all_links_of_entities_inverse)
from openatlas.api.resources.search import search
Expand Down Expand Up @@ -48,8 +48,6 @@ def resolve_entities(
return export_entities_csv(entities, file_name)
if parser['export'] == 'csvNetwork':
return export_csv_for_network_analysis(entities, parser)
if not entities:
raise NoEntityAvailable
result = get_json_output(
sorting(
remove_duplicate_entities(entities),
Expand Down Expand Up @@ -157,9 +155,12 @@ def get_json_output(
total = get_start_entity(total, parser) \
if parser['last'] or parser['first'] else total
j = [i for i, x in enumerate(entities) if x.id == total[0]]
new_entities = [e for idx, e in enumerate(entities[j[0]:])]
formatted_entities = []
if entities:
new_entities = [e for idx, e in enumerate(entities[j[0]:])]
formatted_entities = get_entities_formatted(new_entities, parser)
return {
"results": get_entities_formatted(new_entities, parser),
"results": formatted_entities,
"pagination": {
'entitiesPerPage': int(parser['limit']),
'entities': count,
Expand Down
12 changes: 1 addition & 11 deletions openatlas/views/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
InvalidSystemClassError, InvalidViewClassError, InvalidLimitError,
InvalidSearchSyntax, ValueNotIntegerError, NoSearchStringError,
NotAPlaceError, QueryEmptyError, NotATypeError, TypeIDError,
LastEntityError, NoEntityAvailable, DisplayFileNotFoundError)
LastEntityError, DisplayFileNotFoundError)


@app.errorhandler(400)
Expand Down Expand Up @@ -176,16 +176,6 @@ def invalid_logical_operator(_e: Exception) -> tuple[Any, int]:
'status': 400}), 400


@app.errorhandler(NoEntityAvailable)
def no_entity_available(_e: Exception) -> tuple[Any, int]:
return jsonify({
'title': 'No entity available',
'message': 'No entity exist for this request.',
'url': request.url,
'timestamp': datetime.datetime.now(),
'status': 404}), 404


@app.errorhandler(NoLicenseError)
def no_license(_e: Exception) -> tuple[Any, int]:
return jsonify({
Expand Down
85 changes: 47 additions & 38 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,15 @@ def test_api(self) -> None:
format='lp',
search="""{"beginFrom":[{"operator":"lesserThan",
"values":["2020-1-1"],"logicalOperator":"and"}]}""")),
self.app.get(url_for(
'api_03.query',
entities=place.id,
cidoc_classes='E18',
view_classes='artifact',
system_classes='person',
format='lp',
search="""{"beginFrom":[{"operator":"lesserThan",
"values":["2020-1-1"],"logicalOperator":"or"}]}""")),
self.app.get(url_for(
'api_03.query',
entities=place.id,
Expand Down Expand Up @@ -796,44 +805,44 @@ def test_api(self) -> None:
last=place.id))
assert 'ID is last entity' in rv.get_json()['title']

for rv in [
self.app.get(url_for('api_03.query', entities=12345)),
self.app.get(
url_for(
'api_03.cidoc_class',
cidoc_class='E68',
last=1231)),
self.app.get(
url_for(
'api_03.view_class',
view_class='place',
search=
'{"typeName":[{"operator":"equal",'
'"values":'
'["Boundary Mark", "Height", "Dimension"],'
'"logicalOperator":"and"}]}')),
self.app.get(
url_for(
'api_03.view_class',
view_class='place',
search=
'{"beginFrom":[{"operator":"lesserThan",'
'"values":["2000-1-1"],'
'"logicalOperator":"or"}]}')),
self.app.get(
url_for(
'api_03.query',
entities=place.id,
cidoc_classes='E18',
view_classes='artifact',
system_classes='person',
format='lp',
search=
'{"entityDescription":[{"operator":"like",'
'"values":["IS", "sam", "FrOdo"],'
'"logicalOperator":"and"}]}'))]:
rv = rv.get_json()
assert 'No entity available' in rv['title']
# for rv in [
# self.app.get(url_for('api_03.query', entities=12345)),
# self.app.get(
# url_for(
# 'api_03.cidoc_class',
# cidoc_class='E68',
# last=1231)),
# self.app.get(
# url_for(
# 'api_03.view_class',
# view_class='place',
# search=
# '{"typeName":[{"operator":"equal",'
# '"values":'
# '["Boundary Mark", "Height", "Dimension"],'
# '"logicalOperator":"and"}]}')),
# self.app.get(
# url_for(
# 'api_03.view_class',
# view_class='place',
# search=
# '{"beginFrom":[{"operator":"lesserThan",'
# '"values":["2000-1-1"],'
# '"logicalOperator":"or"}]}')),
# self.app.get(
# url_for(
# 'api_03.query',
# entities=place.id,
# cidoc_classes='E18',
# view_classes='artifact',
# system_classes='person',
# format='lp',
# search=
# '{"entityDescription":[{"operator":"like",'
# '"values":["IS", "sam", "FrOdo"],'
# '"logicalOperator":"and"}]}'))]:
# rv = rv.get_json()
# assert 'No entity available' in rv['title']

rv = self.app.get(
url_for(
Expand Down

0 comments on commit 03b2cad

Please sign in to comment.