Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 Fixes pydantic models for tests #153

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading