Open
Conversation
Owner
Author
These changes ensure that the tests pass by providing all necessary data and maintaining the integrity constraints expected by the database. Diff: index 9c4ec41..c1d99bf 100644
--- a/models.py
+++ b/models.py
@@ -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 @@ 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..b847a71 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": "Publisher A"},
+ {"title": "Ready Player One", "author": "Ernest Cline", "publisher": "Publisher B"},
]
class TestMainApp:
@@ -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="Publisher C"))
deleted_book = delete_book(test_db, book.id)
assert deleted_book is not None
@@ -67,5 +67,6 @@ 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="Publisher D")) is None
assert delete_book(test_db, 999999) is None
+PR with fixes: #135 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a new
publisherfield to the API. It is deliberately incomplete in order to generate a test failure.