Skip to content

Conversation

@vikram-dagger
Copy link
Owner

No description provided.

vikram-dagger pushed a commit that referenced this pull request Aug 22, 2025
@vikram-dagger
Copy link
Owner Author

The following changes were made to ensure all tests passed:

  1. The BookIn and BookOut Pydantic models in models.py were updated to include the publisher field, required for the Book SQLAlchemy model.
  2. Test data in test_main.py was updated to include the publisher field for each book entry.
  3. Book repository functions in repositories.py were updated to correctly handle the publisher field in create and update operations.

Diff:

index 9c4ec41..37622ed 100644
--- a/models.py
+++ b/models.py
@@ -26,6 +26,7 @@ class BookIn(BaseModel):
 
     title: str
     author: str
+    publisher: str
 
 
 class BookOut(BaseModel):
@@ -34,5 +35,6 @@ class BookOut(BaseModel):
     id: int
     title: str
     author: str
+    publisher: str
 
     model_config = ConfigDict(from_attributes=True)
diff --git a/repositories.py b/repositories.py
index dc9ff88..4fa11e7 100644
--- a/repositories.py
+++ b/repositories.py
@@ -4,7 +4,7 @@ import models
 
 # 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..744151d 100644
--- a/test_main.py
+++ b/test_main.py
@@ -5,8 +5,8 @@ from sqlalchemy import create_engine, inspect
 
 # Test data constants
 TEST_BOOKS = [
-    {"title": "Carrie", "author": "Stephen King"},
-    {"title": "Ready Player One", "author": "Ernest Cline"},
+    {"title": "Carrie", "author": "Stephen King", "publisher": "Pocket Books"},
+    {"title": "Ready Player One", "author": "Ernest Cline", "publisher": "Crown Publishing Group"},
 ]
 
 class TestMainApp:
@@ -26,6 +26,7 @@ class TestBookRepository:
         book = create_book(test_db, BookIn(**TEST_BOOKS[0]))
         assert book.title == TEST_BOOKS[0]["title"]
         assert book.author == TEST_BOOKS[0]["author"]
+        assert book.publisher == TEST_BOOKS[0]["publisher"]
         assert book.id is not None
 
     def test_get_books(self, test_db):
@@ -34,7 +35,6 @@ class TestBookRepository:
         book2 = create_book(test_db, BookIn(**TEST_BOOKS[1]))
 
         books = get_books(test_db)
-        #assert len(books) >= 2
         assert any(b.id == book1.id for b in books)
         assert any(b.id == book2.id for b in books)
 
@@ -57,7 +57,7 @@ class TestBookRepository:
 
     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="Delete Publisher"))
         deleted_book = delete_book(test_db, book.id)
 
         assert deleted_book is not None
@@ -67,5 +67,5 @@ class TestBookRepository:
     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

PR with fixes: #117

@vikram-dagger vikram-dagger deleted the vikram-dagger-patch-7 branch August 22, 2025 06:48
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