Skip to content

Commit

Permalink
Fixes pydantic models used in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrharpo committed Feb 7, 2024
1 parent 96cf684 commit b761584
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 14 additions & 2 deletions exhibits/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions ov_wag/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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

0 comments on commit b761584

Please sign in to comment.