From 5c4ce4903e7b305bb7df9c03f923577a762e534e Mon Sep 17 00:00:00 2001 From: Dagger Agent Date: Tue, 2 Sep 2025 11:55:07 +0000 Subject: [PATCH] Fixes PR #132 --- models.py | 3 ++- repositories.py | 3 ++- test_main.py | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/models.py b/models.py index 0e44d72..c1d99bf 100644 --- a/models.py +++ b/models.py @@ -18,7 +18,7 @@ class Book(Base): id: Mapped[int] = mapped_column(primary_key=True, index=True) title: Mapped[str] = mapped_column(String(255), index=True) author: Mapped[str] = mapped_column(String(255)) - publisher: Mapped[str] = mapped_column(String(255), nullable-False) + publisher: Mapped[str] = mapped_column(String(255), nullable=False) # Pydantic models class BookIn(BaseModel): @@ -26,6 +26,7 @@ class BookIn(BaseModel): title: str author: str + publisher: str class BookOut(BaseModel): diff --git a/repositories.py b/repositories.py index dc9ff88..4fa11e7 100644 --- a/repositories.py +++ b/repositories.py @@ -4,7 +4,7 @@ # Create a new book def create_book(db: Session, book: models.BookIn): - db_book = models.Book(title=book.title, author=book.author) + db_book = models.Book(title=book.title, author=book.author, publisher=book.publisher) db.add(db_book) db.commit() db.refresh(db_book) @@ -27,6 +27,7 @@ def update_book(db: Session, book_id: int, book: models.BookIn): if db_book: db_book.title = book.title db_book.author = book.author + db_book.publisher = book.publisher db.commit() db.refresh(db_book) return db_book diff --git a/test_main.py b/test_main.py index 3fea397..1f1a4a1 100644 --- a/test_main.py +++ b/test_main.py @@ -5,8 +5,8 @@ # Test data constants TEST_BOOKS = [ - {"title": "Carrie", "author": "Stephen King"}, - {"title": "Ready Player One", "author": "Ernest Cline"}, + {"title": "Carrie", "author": "Stephen King", "publisher": "Viking Press"}, + {"title": "Ready Player One", "author": "Ernest Cline", "publisher": "Crown Publishing Group"}, ] class TestMainApp: @@ -57,7 +57,7 @@ def test_update_book(self, test_db): def test_delete_book(self, test_db): """Test deleting a book""" - book = create_book(test_db, BookIn(title="To Delete", author="Author")) + book = create_book(test_db, BookIn(title="To Delete", author="Author", publisher="Test Publisher")) deleted_book = delete_book(test_db, book.id) assert deleted_book is not None @@ -67,5 +67,5 @@ def test_delete_book(self, test_db): def test_nonexistent_operations(self, test_db): """Test operations on nonexistent books""" assert get_book(test_db, 999999) is None - assert update_book(test_db, 999999, BookIn(title="Test", author="Test")) is None + assert update_book(test_db, 999999, BookIn(title="Test", author="Test", publisher="Test Publisher")) is None assert delete_book(test_db, 999999) is None