def test_book_comparison(): book_1 = Book(code="UNIQUE_CODE_1", name="Book Name") book_2 = Book(code="UNIQUE_CODE_1", name="Book Name") book_3 = Book(code="UNIQUE_CODE_2", name="Book Name") assert book_1 == book_2 assert book_1 != book_3
def test_book_balance_is_sum_of_account_balances(): book = Book(code=uuid.uuid4().hex, name="New Book") account_1 = Account(name="Test Account 1", initial_balance=10) account_2 = Account(name="Test Account 2", initial_balance=20) book.register(account_1) book.register(account_2) assert book.balance == account_1.balance + account_2.balance
def test_can_add_book_with_with_mapping(session): book = Book(code=uuid.uuid4().hex, name="New Book") account = Account(name="Test Account") book.register(account) session.add(book) session.commit() account = session.query(Account).one() assert account.book == book
def test_can_add_book_with_mapping(session): book_code = uuid.uuid4().hex book = Book(code=book_code, name="New Book") session.add(book) session.commit() rows = list(session.execute('SELECT code, name FROM "books"')) assert rows == [(book_code, "New Book",)]
def book(): return Book(code=uuid.uuid4().hex, name="Test Book")
def test_can_register_account_in_book_only_once(account): book = Book(code=uuid.uuid4().hex, name="New Book") book.register(account) book.register(account) assert len(book.accounts) == 1
def test_can_register_account_in_book(account): book = Book(code=uuid.uuid4().hex, name="New Book") book.register(account) assert account in book.accounts
def test_new_book_has_no_accounts(): book = Book(code=uuid.uuid4().hex, name="New Book") assert book.accounts == set()
def test_new_book_has_no_balance(): book = Book(code=uuid.uuid4().hex, name="New Book") assert book.balance == 0