def test_add_new_entry_with_negative_amount_to_account(account): entry = Entry("First entry in account", 10) account.register(entry) negative_entry = Entry("Second entry in account", -5) account.register(negative_entry) assert negative_entry in account.entries
def test_entries_mapper_can_load_lines(session): session.execute( """INSERT INTO entries (description, amount, date) VALUES ("First Entry", 10, "2020-04-27"), ("Second Entry", 10.42, "2020-04-27"), ("Third Entry", 20.02, "2020-04-27");""" ) expected = [ Entry("First Entry", Decimal("10"), datetime.date(2020, 4, 27)), Entry("Second Entry", Decimal("10.42"), datetime.date(2020, 4, 27)), Entry("Third Entry", Decimal("20.02"), datetime.date(2020, 4, 27)), ] assert session.query(Entry).all() == expected
def test_entry_mapper_can_save_lines(session): new_entry = Entry("Test Entry", 10) session.add(new_entry) session.commit() rows = list(session.execute('SELECT description, amount FROM "entries"')) assert rows == [("Test Entry", 10)]
def test_entry_is_stored_with_its_account(session): account = Account("Test Account") entry = Entry("First Entry", Decimal("10"), datetime.date(2020, 4, 27)) account.register(entry) session.add(account) session.commit() selected_entry = session.query(Entry).one() assert selected_entry.account == account
def test_raise_invalid_entry_if_account_balance_may_be_negative(account): entry = Entry("First entry in account", -10) with pytest.raises(InvalidEntry): account.register(entry)
def test_add_new_entry_with_date(account): entry = Entry("First entry in account", 10, datetime.date(2020, 7, 28)) account.register(entry) assert entry.date == datetime.date(2020, 7, 28)
def test_add_new_entry_with_no_date_defaults_to_today(account): entry = Entry("First entry in account", 10) account.register(entry) assert entry.date == datetime.date.today()
def test_add_new_entry_to_account(account): entry = Entry("First entry in account", 10) account.register(entry) assert entry in account.entries
def test_register_entry_increase_account_balance(account): entry = Entry("First entry in account", 10) account.register(entry) assert account.balance == 10