diff --git a/exhibits/models.py b/exhibits/models.py index 169f7aa..a1c9b61 100644 --- a/exhibits/models.py +++ b/exhibits/models.py @@ -80,14 +80,26 @@ class ImageApiSchema(BaseModel): alt: str -class ExhibitPageApiSchema(BaseModel): +class AuthorAPISchema(BaseModel): + """API schema for Author""" + + id: int + name: str + image: ImageApiSchema + + +class ExhibitsApiSchema(BaseModel): id: int title: str - body: list[str] cover_image: ImageApiSchema cover_thumb: ImageApiSchema hero_image: ImageApiSchema hero_thumb: ImageApiSchema + authors: list[AuthorAPISchema] + + +class ExhibitPageApiSchema(ExhibitsApiSchema): + body: list[str] class ExhibitPage(HeadlessMixin, Page): diff --git a/ov_wag/tests/test_api.py b/ov_wag/tests/test_api.py index 1a871e8..1fe0953 100644 --- a/ov_wag/tests/test_api.py +++ b/ov_wag/tests/test_api.py @@ -3,7 +3,7 @@ from rest_framework.test import APITestCase from wagtail.models import Site -from exhibits.models import ExhibitPageApiSchema +from exhibits.models import ExhibitPageApiSchema, ExhibitsApiSchema from exhibits.tests.factories import ExhibitPageFactory @@ -52,13 +52,13 @@ def test_exhibit_api_schema_multiple(self): """ GET /api/v2/exhibit for Exhibit pages - Compare response against ExhibitSchema + Compare response against ExhibitsAPISchema """ ExhibitPageFactory.create(parent=self.__home_page()) response = self.client.get('/api/v2/exhibits/', format='json') json = response.json() for item in json['items']: - self.assert_valid_schema(item) + assert ExhibitsApiSchema(**item) def __home_page(self): return Site.objects.filter(is_default_site=True).first().root_page