diff --git a/openatlas/api/resources/error.py b/openatlas/api/resources/error.py index 5022e79e8..fdb669cc5 100644 --- a/openatlas/api/resources/error.py +++ b/openatlas/api/resources/error.py @@ -38,10 +38,6 @@ class LogicalOperatorError(Exception): pass -class NoEntityAvailable(Exception): - pass - - class NoLicenseError(Exception): pass diff --git a/openatlas/api/resources/resolve_endpoints.py b/openatlas/api/resources/resolve_endpoints.py index 56e8169bd..d4df07f1c 100644 --- a/openatlas/api/resources/resolve_endpoints.py +++ b/openatlas/api/resources/resolve_endpoints.py @@ -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 @@ -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), @@ -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, diff --git a/openatlas/views/error.py b/openatlas/views/error.py index 651eabe98..dbad2a7c6 100644 --- a/openatlas/views/error.py +++ b/openatlas/views/error.py @@ -10,7 +10,7 @@ InvalidSystemClassError, InvalidViewClassError, InvalidLimitError, InvalidSearchSyntax, ValueNotIntegerError, NoSearchStringError, NotAPlaceError, QueryEmptyError, NotATypeError, TypeIDError, - LastEntityError, NoEntityAvailable, DisplayFileNotFoundError) + LastEntityError, DisplayFileNotFoundError) @app.errorhandler(400) @@ -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({ diff --git a/tests/test_api.py b/tests/test_api.py index 70a6b16df..ed2e473b6 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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, @@ -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(