Skip to content

Commit

Permalink
implement endpoint with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardKoschicek committed Oct 23, 2023
1 parent 4f190bd commit d3da02b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
1 change: 1 addition & 0 deletions config/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@

# Used to connect to password protected Vocabs systems
VOCABS_PASS = ''
API_VERSIONS = ['0.3']
30 changes: 16 additions & 14 deletions openatlas/api/endpoints/content.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from typing import Union

from flask import Response, g, jsonify
from flask import Response, g
from flask_restful import Resource, marshal

from openatlas import app
from openatlas.api.resources.model_mapper import get_overview_counts
from openatlas.api.resources.parser import language
from openatlas.api.resources.parser import language, default
from openatlas.api.resources.resolve_endpoints import download
from openatlas.api.resources.templates import (
class_overview_template, content_template, overview_template)
class_overview_template, content_template, overview_template,
backend_details_template)
from openatlas.models.content import get_translation


Expand All @@ -31,22 +32,23 @@ def get() -> Union[tuple[Resource, int], Response]:
class GetBackendDetails(Resource):
@staticmethod
def get() -> Union[tuple[Resource, int], Response]:
parser = language.parse_args()
lang = parser['lang']
content = {
parser = default.parse_args()
details = {
'version': app.config['VERSION'],
'siteName': get_translation('site_name_for_frontend', lang),
'imageProcessing': g.settings['image_processing'],
'imageSizes': app.config['IMAGE_SIZE'],
'apiVersions': app.config['API_VERSIONS'],
'siteName': g.settings['site_name'],
'imageProcessing': {
'enabled': g.settings['image_processing'],
'availableImageSizes':
app.config['IMAGE_SIZE']
if g.settings['image_processing'] else None},
'IIIF': {
'enabled': app.config['IIIF']['enabled'],
'url': app.config['IIIF']['url'],
'version': app.config['IIIF']['version']}
}
'version': app.config['IIIF']['version']}}
if parser['download']:
download(content, content_template(), 'content')
# return marshal(content, content_template()), 200
return content
download(details, backend_details_template(), 'content')
return marshal(details, backend_details_template()), 200


class ClassMapping(Resource):
Expand Down
16 changes: 16 additions & 0 deletions openatlas/api/resources/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,22 @@ def content_template() -> dict[str, Type[String]]:
'imageSizes': fields.Raw}


def backend_details_template() -> dict[str, Type[String]]:
image_processing = {
'enabled': fields.String,
'availableImageSizes': fields.String}
iiif = {
'enabled': fields.String,
'url': fields.String,
'version': fields.String}
return {
'version': fields.String,
'apiVersions': fields.Raw,
'siteName': fields.String,
'imageProcessing': fields.Nested(image_processing),
'IIIF': fields.Nested(iiif)}


def licensed_file_template(entities: list[Entity]) -> dict[str, Any]:
file = {
'display': fields.String,
Expand Down
3 changes: 3 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def test_api(self) -> None:
rv = self.app.get(url_for('api_03.content')).get_json()
assert bool(rv['intro'] == 'This is English')

rv = self.app.get(url_for('api_03.backend_detail')).get_json()
assert bool(rv['version'] == app.config['VERSION'])

rv = self.app.get(url_for('api_03.system_class_count')).get_json()
assert bool(rv['person'])

Expand Down

0 comments on commit d3da02b

Please sign in to comment.