def test_attributes(self): title = fake.sentence() book = Book.create(title=title) assert book.title == title assert hasattr(book, 'isbn') assert hasattr(book, 'author') assert hasattr(book, 'id') assert isinstance(book.id, int) assert isinstance(book.date_created, dt.datetime)
def test_post_with_no_author(self, wt): url = url_for('books.BookList:post') title = fake.bs() res = wt.post_json(url, { 'title': title } ) assert res.status_code == http.CREATED book = Book.get_latest() assert book.title == title assert book.author is None
def test_post_creates_book(self, wt): author = AuthorFactory() old_count = Book.query.count() url = url_for('books.BookList:post') title = fake.bs() res = wt.post_json(url, {'title': title, 'author_id': author.id}) assert res.status_code == http.CREATED data = res.json['result'] assert data['title'] == title assert res.json['message'] == 'Successfully created new book' assert Book.query.count() == old_count + 1 latest = Book.get_latest() assert latest.title == title assert latest.author == author
def test_post_with_author_name(self, wt): author = AuthorFactory() url = url_for('books.BookList:post') title = fake.bs() res = wt.post_json(url, { 'title': title, 'author_first': author.first, 'author_last': author.last, } ) assert res.status_code == http.CREATED book = Book.get_latest() assert book.title == title latest_book_author = book.author assert author == latest_book_author