def test_insert_transaction_object(): mb = MemoryBackend(get_categories()) mb.insert_record(dt(10, 2), parse_transaction("149, groceries", get_categories())) assert mb.records(dt(10, 2))[0].value._cents == 14900 assert mb.records(dt(10, 2))[0].description == "groceries"
def test_insert_record(): import shutil shutil.copytree("./tests/resources/finances", "./finances_copy") be = backend("./finances_copy") be.insert_record( transaction=parse_transaction("1000, aldi", get_categories()), date=dt(day=3, month=1), ) be.insert_record( transaction=parse_transaction("1000, aldi", get_categories()), date=dt(day=30, month=3), ) jan_expected = [ ("street_food", 34), ("sports", 467), ("furniture", 43), ("aldi", 1000), ] mar_expected = [("aldi", 1000)] assert jan_expected == list_records(be, dt(day=3, month=1)) assert mar_expected == list_records(be, dt(day=30, month=3)) shutil.rmtree("./finances_copy")
def test_list_records(): be = backend() records = list_records(be, dt(day=3, month=1)) expected = [("street_food", 34), ("sports", 467), ("furniture", 43)] assert records == expected assert not list(be.records(dt(day=1, month=12)))
def test_open_xlsx_account(): account = open_account("./tests/resources/finances") records = list_records(account, dt(day=3, month=1)) expected = [("street_food", 34), ("sports", 467), ("furniture", 43)] assert records == expected assert not list(account.records(dt(day=1, month=12)))
def test_parse_string(): mb = MemoryBackend(get_categories()) mb.insert_record(dt(10, 2), "10, food") assert mb.records(dt(10, 2))[0].value._cents == 1000 assert mb.records(dt(10, 2))[0].description == "food"
def test_invalid_type(): mb = MemoryBackend(get_categories()) with pytest.raises(TypeError): mb.insert_record(dt(10, 2), (100, "food"))