def seed(dbpath=DBPATH): ORM.dbpath = dbpath word = Word(books_pk=1, word="Testing", word_count=50) word.save() book = Book(title="A good book", text_content="Once upon a time...", author="Kevin Johnson") book.save()
def init_test_database(): db.create_all() book_title = 'Test book' test_book = Book(title=book_title) db.session.add(test_book) db.session.commit() yield db db.drop_all()
def __init__(self, title, authors, isbn, price): Book.__init__(self, title, authors, isbn, price) self.set_price(self.price) self.TYPE = "Usado"
def __init__(self,title,authors,isbn,price): Book.__init__(self,title,authors,isbn,price) self.TYPE = "Exclusivo"
#! /usr/bin/env python3 import os from app.orm import ORM from app import controller from app.book import Book DIR = os.path.dirname(__file__) DBFILENAME = 'books_words.db' DBPATH = os.path.join(DIR, 'data', DBFILENAME) DIRNAME = os.path.dirname(__file__) CSVFILENAME = 'mobydick.1.txt' CSVPATH = os.path.join(DIRNAME, CSVFILENAME) import os # # from app.orm import ORM # # from app import controller # # child classes default to ORM'm dbpath if it is not set ORM.dbpath = DBPATH # controller.run() b = Book(title="Moby Dick", author="Moby Dicks Author") b.from_title("A good book") b.load_text() b.generate_counts() b.generate_counts()
def test_to_json_returns_book_in_json_given_new_book(): new_book = Book(title='Spanking new test book') assert new_book.to_json().get('title') == 'Spanking new test book'
def test_from_json_return_book(): with pytest.raises(ValueError, match='Please provide a title'): Book.from_json({})