Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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",)]
Exemplo n.º 5
0
def book():
    return Book(code=uuid.uuid4().hex, name="Test Book")
Exemplo n.º 6
0
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
Exemplo n.º 7
0
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
Exemplo n.º 8
0
def test_new_book_has_no_accounts():
    book = Book(code=uuid.uuid4().hex, name="New Book")
    assert book.accounts == set()
Exemplo n.º 9
0
def test_new_book_has_no_balance():
    book = Book(code=uuid.uuid4().hex, name="New Book")
    assert book.balance == 0