Beispiel #1
0
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")
Beispiel #2
0
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"
Beispiel #3
0
    def insert_record(self, date, record):
        if type(record) is str:
            record = parse_transaction(record, self.categories)

        if type(record) is not Transaction:
            raise TypeError("Supplied parameter is not a transaction")

        self.records(date).append(record)
Beispiel #4
0
    def records(self, date):
        if not os.path.exists(self.file(date)):
            return

        with open(self.file(date)) as f:
            for line in f:
                transaction = parse_transaction(line.strip(), self.categories)
                transaction.date = date
                yield transaction
Beispiel #5
0
def test_transaction_matching():
    cats = get_categories()
    t1 = parse_transaction("100, aldi", cats)
    t2 = parse_transaction("14,street_food", cats)
    t3 = parse_transaction("500,tax", cats)

    assert t1.is_aldi
    assert not t1.is_edeka
    assert t1.is_groceries
    assert t1.is_food

    assert t2.is_street_food
    assert not t2.is_groceries
    assert t2.is_food

    assert t3.is_tax
    assert not t3.is_food
    assert not t3.is_groceries
Beispiel #6
0
def records(cats, records_):
    recs = (tuple(line.split(";")) for line in records_.split("\n"))
    return [(parse_date(date), parse_transaction(trans, cats)) for date, trans in recs]
Beispiel #7
0
 def _rows_to_records(self, rows, date):
     return (parse_transaction(
         str(row[2].value) + "," + str(row[1].value), self.categories)
             for row in list(rows)[1:]
             if row[0].value and date.day == int(row[0].value))