def init_db(session): book1 = model.Book("Some Book", "Some Author", "Some Publisher", 1000) book2 = model.Book( "A Different Book", "A Different Author", "A Different Publisher", 1000 ) session.add(book1) session.add(book2) session.commit()
def test_book(): book = model.Book(title="A Book", author="An Author", publisher="A Publisher", pages=1000) assert book.title == "A Book" assert book.author == "An Author" assert book.publisher == "A Publisher" assert book.pages == 1000
def test_book_to_dict(): book_dict = model.Book(title="A Book", author="An Author", publisher="A Publisher", pages=1000).to_dict() assert book_dict["title"] == "A Book" assert book_dict["author"] == "An Author" assert book_dict["publisher"] == "A Publisher" assert book_dict["pages"] == 1000
def update(): validate(request.json, "BookSchema", "specs/book_put.yml") data = request.json book = model.Book( title=data["title"], author=data["author"], publisher=data["publisher"], pages=data["pages"], ) command = commands.UpdateBook(book=book) result = context.messagebus.handle(command) return dict(success=result), 201
def add(): validate(request.json, "BookSchema", "specs/book_add.yml") data = request.json book = model.Book( title=data["title"], author=data["author"], publisher=data["publisher"], pages=data["pages"], ) command = commands.AddBook(book=book) context.messagebus.handle(command) return dict(success=True), 200
def test_update_book(sqlite_session_factory): session = sqlite_session_factory() repo = book_repository.SqlAlchemyBookRepository(session) book = model.Book("A Book", "An Author", "A Publisher", 1000) repo.update(book)