Skip to content

Update tests for new Catalog.create() API and rename package to pyopds2#19

Merged
mekarpeles merged 6 commits intomainfrom
copilot/update-unit-tests-and-fix-errors
Nov 5, 2025
Merged

Update tests for new Catalog.create() API and rename package to pyopds2#19
mekarpeles merged 6 commits intomainfrom
copilot/update-unit-tests-and-fix-errors

Conversation

Copy link
Contributor

Copilot AI commented Nov 5, 2025

PR #18 failed to merge due to branch divergence. This PR implements the same changes in four staged commits against current main.

Changes

Commit 1: CI/CD

  • Added GitHub Actions workflow for linting (flake8) and testing (pytest) across Python 3.8-3.12

Commit 2: Test & API Fixes

  • Fixed Catalog.create() default metadata to Metadata(title="OPDS Catalog") (prevents Pydantic validation errors)
  • Rewrote test mocks to use new DataProvider.SearchResponse API with nested dataclass pattern
  • Updated all tests from helper functions to direct Catalog.create(response=...) calls

Commit 3: Linting

  • Removed unused imports, fixed whitespace violations, enforced line length limits

Commit 4: Package Rename

  • Renamed opds2pyopds2 throughout codebase and build config

Usage

from pyopds2 import Catalog
from pyopds2.provider import DataProvider, DataProviderRecord

class Book(DataProviderRecord):
    title: str
    author: str
    url: str
    
    def metadata(self):
        return Metadata(title=self.title, author=[Contributor(name=self.author)])
    
    def links(self):
        return [Link(href=self.url, type="application/epub+zip")]
    
    def images(self):
        return None

class MyProvider(DataProvider):
    @staticmethod
    def search(query, limit=50, offset=0, sort=None):
        records = [Book(title="1984", author="Orwell", url="...")]
        return DataProvider.SearchResponse(
            provider=MyProvider,
            query=query,
            limit=limit,
            offset=offset,
            sort=sort,
            records=records,
            total=len(records)
        )

# Create catalog from search
result = MyProvider.search("orwell")
catalog = Catalog.create(response=result, paginate=True)

All 27 tests passing with 91% coverage.

Original prompt

#18 failed to apply because it was started on a branch that diverged from main resulting in conflicts. Please refer to its diff/PR as #18 solves most of our problems.

Original prompt

In the last PR #17 we arrived at a great spec for providers and models, updating Catalog so that we can now generate a catalog via Catalog.create(DataProvider.search(...), paginate=True)

We got lazy and didn't update the unit tests, can you please do so and also fix any clear cases where there are either egregious lint violations or flat our errors in provider or models? Please do not refactor any code.

The code in #18

opds2/models.py: Fixed Catalog.create() to use Metadata(title="OPDS Catalog") as default instead of bare Metadata() to prevent Pydantic validation errors
opds2/models.py: Removed unused urlencode import
tests/test_catalog.py: Completely rewrote MockDataProvider to use new DataProvider.SearchResponse API with static methods returning nested dataclass
tests/test_integration.py: Updated all integration tests to use new Catalog.create(response=...) signature
tests/test_models.py: All tests continue to pass (no changes needed)
.github/workflows/test.yml: Added comprehensive CI pipeline
Runs on Python 3.8, 3.9, 3.10, 3.11, and 3.12
Flake8 linting for syntax errors and undefined names
Full pytest test suite with coverage reporting

class MockBook(DataProviderRecord):
title: str
author: str
url: str

def metadata(self) -> Metadata:
    return Metadata(
        title=self.title,
        author=[Contributor(name=self.author, role="author")]
    )

def links(self) -> List[Link]:
    return [Link(href=self.url, type="application/epub+zip")]

def images(self) -> Optional[List[Link]]:
    return None

class MockDataProvider(DataProvider):
@staticmethod
def search(query: str, limit: int = 50, offset: int = 0, sort: Optional[str] = None) -> DataProvider.SearchResponse:
records = [MockBook(title="1984", author="Orwell", url="...")]
return DataProvider.SearchResponse(
provider=MockDataProvider,
query=query,
limit=limit,
offset=offset,
sort=sort,
records=records,
total=len(records)
)

Create catalog from search

result = MockDataProvider.search("orwell")
catalog = Catalog.create(response=result, paginate=True)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Nov 5, 2025
Copilot AI and others added 4 commits November 5, 2025 22:51
Co-authored-by: mekarpeles <978325+mekarpeles@users.noreply.github.com>
Co-authored-by: mekarpeles <978325+mekarpeles@users.noreply.github.com>
Co-authored-by: mekarpeles <978325+mekarpeles@users.noreply.github.com>
Co-authored-by: mekarpeles <978325+mekarpeles@users.noreply.github.com>
Copilot AI changed the title [WIP] Update unit tests and fix lint violations in models Update tests for new Catalog.create() API and rename package to pyopds2 Nov 5, 2025
Copilot AI requested a review from mekarpeles November 5, 2025 23:01
@mekarpeles mekarpeles marked this pull request as ready for review November 5, 2025 23:04
@mekarpeles mekarpeles merged commit 3777f95 into main Nov 5, 2025
2 checks passed
@mekarpeles mekarpeles deleted the copilot/update-unit-tests-and-fix-errors branch November 5, 2025 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants