diff --git a/openatlas/api/resources/resolve_endpoints.py b/openatlas/api/resources/resolve_endpoints.py index 2102e88fa..a853cc2c6 100644 --- a/openatlas/api/resources/resolve_endpoints.py +++ b/openatlas/api/resources/resolve_endpoints.py @@ -104,9 +104,9 @@ def resolve_entity( parser: dict[str, Any]) \ -> Union[Response, dict[str, Any], tuple[Any, int]]: if parser['export'] == 'csv': - export_entities_csv(entity, entity.name) + return export_entities_csv(entity, entity.name) if parser['export'] == 'csvNetwork': - export_csv_for_network_analysis([entity], parser) + return export_csv_for_network_analysis([entity], parser) result = get_entity_formatted(entity, parser) if parser['format'] in app.config['RDF_FORMATS']: # pragma: nocover return Response( diff --git a/tests/test_api.py b/tests/test_api.py index d97f3b0be..8fded4bd4 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -99,19 +99,25 @@ def test_api(self) -> None: assert self.get_geom_properties(rv, 'objectName') assert self.get_geom_properties(rv, 'shapeType') - for rv in [ - self.app.get( - url_for('api_03.export_database', format_='xml')), - self.app.get( - url_for('api_03.export_database', format_='json')), - self.app.get( - url_for('api_03.export_database', format_='csv'))]: - assert b'Shire' in rv.data + rv = self.app.get( + url_for('api_03.export_database', format_='xml')) + assert b'Shire' in rv.data + assert 'application/xml' in rv.headers.get('Content-Type') + + rv = self.app.get( + url_for('api_03.export_database', format_='json')) + assert b'Shire' in rv.data + assert 'application/json' in rv.headers.get('Content-Type') + + rv = self.app.get(url_for('api_03.export_database', format_='csv')) + assert b'Shire' in rv.data + assert 'application/zip' in rv.headers.get('Content-Type') # ---Entity Endpoints--- # Test Entity rv = self.app.get( url_for('api_03.entity', id_=place.id, download=True)) + assert 'application/json' in rv.headers.get('Content-Type') rv = rv.get_json()['features'][0] assert self.get_bool(rv, '@id') assert self.get_bool(rv, 'type', 'Feature') @@ -159,6 +165,7 @@ def test_api(self) -> None: # Test entity in GeoJSON format rv = self.app.get(url_for( 'api_03.entity', id_=place.id, format='geojson')) + assert 'application/json' in rv.headers.get('Content-Type') rv = rv.get_json()['features'][0] assert self.get_bool(rv['geometry'], 'type') assert self.get_bool(rv['geometry'], 'coordinates') @@ -176,6 +183,7 @@ def test_api(self) -> None: rv = self.app.get(url_for( 'api_03.entity', id_=place.id, format='geojson-v2')) + assert 'application/json' in rv.headers.get('Content-Type') rv = rv.get_json()['features'][0] assert self.get_bool(rv['geometry'], 'type') assert self.get_bool( @@ -195,6 +203,7 @@ def test_api(self) -> None: # Test entity in Linked Open Usable Data rv = self.app.get( url_for('api_03.entity', id_=place.id, format='loud')) + assert 'application/json' in rv.headers.get('Content-Type') rv = rv.get_json() assert bool(rv['type'] == 'PhysicalThing') assert bool(rv['_label'] == 'Shire') @@ -228,15 +237,19 @@ def test_api(self) -> None: for rv in [ self.app.get( url_for('api_03.entity', id_=place.id, export='csv')), - self.app.get(url_for( - 'api_03.entity', id_=place.id, export='csvNetwork')), self.app.get(url_for( 'api_03.query', entities=location.id, cidoc_classes='E18', view_classes='artifact', system_classes='person', - export='csv')), + export='csv'))]: + assert b'Shire' in rv.data + assert 'text/csv' in rv.headers.get('Content-Type') + + for rv in [ + self.app.get(url_for( + 'api_03.entity', id_=place.id, export='csvNetwork')), self.app.get(url_for( 'api_03.query', entities=location.id, @@ -245,6 +258,7 @@ def test_api(self) -> None: system_classes='person', export='csvNetwork'))]: assert b'Shire' in rv.data + assert 'application/zip' in rv.headers.get('Content-Type') # Test Entities endpoints for rv in [ @@ -296,6 +310,7 @@ def test_api(self) -> None: column='system_class', download=True, actor=place.id))]: + assert 'application/json' in rv.headers.get('Content-Type') rv = rv.get_json() rv_results = rv['results'][0]['features'][0] rv_page = rv['pagination'] @@ -675,6 +690,7 @@ def test_api(self) -> None: self.app.get(url_for('api_03.subunits', id_=place.id)), self.app.get( url_for('api_03.subunits', id_=place.id, download=True))]: + assert 'application/json' in rv.headers.get('Content-Type') rv = rv.get_json()[str(place.id)] for item in rv: if item['id'] == place.id: @@ -739,6 +755,7 @@ def test_api(self) -> None: centroid=True, limit=0))]: assert b'(autogenerated)' in rv.data + assert 'application/json' in rv.headers.get('Content-Type') # Test Error Handling for rv in [