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

Fix Issue Schema's page_count field #8

Merged
merged 3 commits into from
Jan 9, 2025
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
5 changes: 3 additions & 2 deletions grayven/schemas/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import re
from datetime import date
from decimal import Decimal
from enum import Enum
from typing import Annotated, Optional

Expand Down Expand Up @@ -64,7 +65,7 @@ class Story(BaseModel):
job_number: Annotated[Optional[str], BeforeValidator(blank_is_none)]
letters: Annotated[Optional[str], BeforeValidator(blank_is_none)]
notes: Annotated[Optional[str], BeforeValidator(blank_is_none)]
page_count: str
page_count: Optional[Decimal]
pencils: str
script: Annotated[Optional[str], BeforeValidator(blank_is_none)]
sequence_number: int
Expand All @@ -89,7 +90,7 @@ class BasicIssue(BaseModel):

api_url: HttpUrl
descriptor: str
page_count: str
page_count: Optional[Decimal]
price: str
publication_date: str
series: HttpUrl
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ docs = [
tests = [
"pytest >= 8.3.4",
"pytest-cov >= 6.0.0",
"pytest-httpx>=0.35.0",
"tox >= 4.23.2",
"tox-uv >= 1.16.2"
]
Expand Down
47 changes: 43 additions & 4 deletions tests/issue_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,51 @@
"""

from datetime import date
from decimal import Decimal

import pytest
from pytest_httpx import HTTPXMock

from grayven.exceptions import ServiceError
from grayven.grand_comics_database import GrandComicsDatabase
from grayven.schemas.issue import StoryType
from grayven.schemas.issue import Issue, StoryType


@pytest.fixture
def issue_no_page_json() -> dict[str, any]:
"""Simple fixture for issue with no page."""
return {
"api_url": "https://www.comics.org/api/issue/2698986/?format=json",
"series_name": "Cruel Kingdom (2025 series)",
"descriptor": "1",
"publication_date": "January 2025",
"price": "4.99 USD",
"page_count": None,
"editing": "",
"indicia_publisher": "Oni-Lion Forge Publishing Group, LLC",
"brand": "EC An Entertaining Comic; Oni Press [eye]",
"isbn": "",
"barcode": "64985600823700111",
"rating": "",
"on_sale_date": "2025-01-08",
"indicia_frequency": "",
"notes": "",
"variant_of": None,
"series": "https://www.comics.org/api/series/219801/?format=json",
"story_set": [],
"cover": "https://files1.comics.org//img/gcd/covers_by_id/1743/w400/1743127.jpg",
}


def test_issue_no_page(httpx_mock: HTTPXMock, issue_no_page_json: dict[str, any]) -> None:
"""Test issue with no page count."""
session = GrandComicsDatabase() # We don't want to cache these results
httpx_mock.add_response(json=issue_no_page_json)
result = session.get_issue(2698986)
assert isinstance(result, Issue)
assert result.page_count is None
assert result.descriptor == "1"
assert result.publication_date == "January 2025"


def test_issue(session: GrandComicsDatabase) -> None:
Expand All @@ -23,7 +62,7 @@ def test_issue(session: GrandComicsDatabase) -> None:
assert result.descriptor == "1 [Direct Sales - Carlos Pacheco / Jesus Merino Cover]"
assert result.publication_date == "July 2005"
assert result.price == "3.50 USD; 4.75 CAD"
assert result.page_count == "48.000"
assert result.page_count == Decimal("48")
assert (
result.editing
== "Peter J. Tomasi (credited as Peter Tomasi) (editor); Harvey Richards (credited) (assistant editor); Dan DiDio (credited) (executive editor); Paul Levitz (credited) (publisher)" # noqa: E501
Expand All @@ -42,7 +81,7 @@ def test_issue(session: GrandComicsDatabase) -> None:
assert result.story_set[0].title is None
assert result.story_set[0].feature == "Green Lantern"
assert result.story_set[0].sequence_number == 0
assert result.story_set[0].page_count == "1.000"
assert result.story_set[0].page_count == Decimal("1")
assert result.story_set[0].script is None
assert result.story_set[0].pencils == "Carlos Pacheco (credited) (signed as Pacheco [scratch])"
assert result.story_set[0].inks == "Jesús Merino (credited) (signed as Merino)"
Expand Down Expand Up @@ -77,7 +116,7 @@ def test_list_issues(session: GrandComicsDatabase) -> None:
assert result.descriptor == "1 [Direct Sales - Carlos Pacheco / Jesus Merino Cover]"
assert result.publication_date == "July 2005"
assert result.price == "3.50 USD; 4.75 CAD"
assert result.page_count == "48.000"
assert result.page_count == Decimal("48")
assert result.variant_of is None
assert str(result.series) == "https://www.comics.org/api/series/13519/?format=json"

Expand Down
Loading