Пример #1
0
def test_extract_with_zeitraum(tmp_file):
    tmp_file.write_text(
        _format(
            '''
            "Kreditkarte:";"{card_number} Kreditkarte";

            "Zeitraum:";"seit der letzten Abrechnung";
            "Saldo:";"5000.01 EUR";
            "Datum:";"30.01.2018";

            {header};
            "Ja";"15.01.2018";"15.01.2018";"REWE Filiale Muenchen";"-10,80";"";
            ''',  # NOQA
            dict(card_number=CARD_NUMBER, header=HEADER),
        ))

    importer = CreditImporter(CARD_NUMBER,
                              'Assets:DKB:Credit',
                              file_encoding='utf-8')

    assert not importer._date_from
    assert not importer._date_to
    assert not importer._balance_amount

    with tmp_file.open() as fd:
        directives = importer.extract(fd)

    assert directives
    assert not importer._date_from
    assert not importer._date_to
    assert importer._balance_date == datetime.date(2018, 1, 31)
Пример #2
0
def test_emits_closing_balance_directive(tmp_file):
    tmp_file.write_text(
        _format(
            '''
            "Kreditkarte:";"{card_number} Kreditkarte";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Saldo:";"5000.01 EUR";
            "Datum:";"30.01.2018";

            {header};
            "Ja";"15.01.2018";"15.01.2018";"REWE Filiale Muenchen";"-10,80";"";
            ''',  # NOQA
            dict(card_number=CARD_NUMBER, header=HEADER),
        ))

    importer = CreditImporter(CARD_NUMBER,
                              'Assets:DKB:Credit',
                              file_encoding='utf-8')

    with tmp_file.open() as fd:
        directives = importer.extract(fd)

    assert len(directives) == 2
    assert isinstance(directives[1], Balance)
    assert directives[1].date == datetime.date(2018, 1, 31)
    assert directives[1].amount == Amount(Decimal('5000.01'), currency='EUR')
Пример #3
0
def test_extract_no_transactions(tmp_file):
    importer = CreditImporter(CARD_NUMBER, 'Assets:DKB:Credit')

    tmp_file.write_text(
        _format(
            '''
            "Kreditkarte:";"{card_number} Kreditkarte";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Saldo:";"5000.01 EUR";
            "Datum:";"30.01.2018";

            {header};
            ''',
            dict(card_number=CARD_NUMBER, header=HEADER),
        ))

    with tmp_file.open() as fd:
        directives = importer.extract(fd)

    assert len(directives) == 1
    assert isinstance(directives[0], Balance)
    assert directives[0].date == datetime.date(2018, 1, 31)
    assert directives[0].amount == Amount(Decimal('5000.01'), currency='EUR')
Пример #4
0
def test_extract_transactions(tmp_file):
    tmp_file.write_text(
        _format(
            '''
            "Kreditkarte:";"{card_number} Kreditkarte";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Saldo:";"5000.01 EUR";
            "Datum:";"30.01.2018";

            {header};
            "Ja";"15.01.2018";"15.01.2018";"REWE Filiale Muenchen";"-10,80";"";
            ''',  # NOQA
            dict(card_number=CARD_NUMBER, header=HEADER),
        ))

    importer = CreditImporter(CARD_NUMBER,
                              'Assets:DKB:Credit',
                              file_encoding='utf-8')

    with tmp_file.open() as fd:
        directives = importer.extract(fd)

    assert len(directives) == 2
    assert directives[0].date == datetime.date(2018, 1, 15)

    assert len(directives[0].postings) == 1
    assert directives[0].postings[0].account == 'Assets:DKB:Credit'
    assert directives[0].postings[0].units.currency == 'EUR'
    assert directives[0].postings[0].units.number == Decimal('-10.80')
Пример #5
0
def test_extract_no_transactions(tmp_file):
    importer = CreditImporter(Constants.card_number.value, 'Assets:DKB:Credit')

    tmp_file.write(
        _format(
            '''
            "Kreditkarte:";"{card_number} Kreditkarte";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Saldo:";"5000.01 EUR";
            "Datum:";"30.01.2018";

            {header};
            ''',
            dict(
                card_number=Constants.card_number.value,
                header=Constants.header.value,
            ),
        )
    )

    with open(str(tmp_file.realpath())) as fd:
        transactions = importer.extract(fd)

    assert len(transactions) == 1
    assert isinstance(transactions[0], Balance)
    assert transactions[0].date == datetime.date(2018, 1, 31)
    assert transactions[0].amount == Amount(Decimal('5000.01'), currency='EUR')
Пример #6
0
def test_emits_closing_balance_directive(tmp_file):
    tmp_file.write(
        _format(
            '''
            "Kreditkarte:";"{card_number} Kreditkarte";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Saldo:";"5000.01 EUR";
            "Datum:";"30.01.2018";

            {header};
            "Ja";"15.01.2018";"15.01.2018";"REWE Filiale Muenchen";"-10,80";"";
            ''',  # NOQA
            dict(
                card_number=Constants.card_number.value,
                header=Constants.header.value,
            ),
        )
    )

    importer = CreditImporter(
        Constants.card_number.value, 'Assets:DKB:Credit', file_encoding='utf-8'
    )

    with open(str(tmp_file.realpath())) as fd:
        transactions = importer.extract(fd)

    assert len(transactions) == 2
    assert isinstance(transactions[1], Balance)
    assert transactions[1].date == datetime.date(2018, 1, 31)
    assert transactions[1].amount == Amount(Decimal('5000.01'), currency='EUR')
Пример #7
0
def test_extract_transactions(tmp_file):
    tmp_file.write(
        _format(
            '''
            "Kreditkarte:";"{card_number} Kreditkarte";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Saldo:";"5000.01 EUR";
            "Datum:";"30.01.2018";

            {header};
            "Ja";"15.01.2018";"15.01.2018";"REWE Filiale Muenchen";"-10,80";"";
            ''',  # NOQA
            dict(
                card_number=Constants.card_number.value,
                header=Constants.header.value,
            ),
        )
    )

    importer = CreditImporter(
        Constants.card_number.value, 'Assets:DKB:Credit', file_encoding='utf-8'
    )

    with open(str(tmp_file.realpath())) as fd:
        transactions = importer.extract(fd)

    assert len(transactions) == 2
    assert transactions[0].date == datetime.date(2018, 1, 15)

    assert len(transactions[0].postings) == 1
    assert transactions[0].postings[0].account == 'Assets:DKB:Credit'
    assert transactions[0].postings[0].units.currency == 'EUR'
    assert transactions[0].postings[0].units.number == Decimal('-10.80')
Пример #8
0
    def test_extract_sets_timestamps(self):
        with open(self.filename, 'wb') as fd:
            fd.write(
                _format(
                    '''
                "Kreditkarte:";"{card_number} Kreditkarte";

                "Von:";"01.01.2018";
                "Bis:";"31.01.2018";
                "Saldo:";"5.000,01 EUR";
                "Datum:";"15.02.2018";

                {header};
                "Ja";"15.01.2018";"15.01.2018";"REWE Filiale Muenchen";"-10,80";"";
            ''', dict(card_number=self.card_number, header=HEADER)))  # NOQA

        importer = CreditImporter(self.card_number,
                                  'Assets:DKB:Credit',
                                  file_encoding='utf-8')

        self.assertFalse(importer._date_from)
        self.assertFalse(importer._date_to)
        self.assertFalse(importer._balance)

        with open(self.filename) as fd:
            transactions = importer.extract(fd)

        self.assertTrue(transactions)
        self.assertEqual(importer._date_from, datetime.date(2018, 1, 1))
        self.assertEqual(importer._date_to, datetime.date(2018, 1, 31))
        self.assertEqual(importer._balance, Decimal('5000.01'))
Пример #9
0
    def test_extract_transactions(self):
        with open(self.filename, 'wb') as fd:
            fd.write(
                _format(
                    '''
                "Kreditkarte:";"{card_number} Kreditkarte";

                "Von:";"01.01.2018";
                "Bis:";"31.01.2018";
                "Saldo:";"5.000,01 EUR";
                "Datum:";"15.02.2018";

                {header};
                "Ja";"15.01.2018";"15.01.2018";"REWE Filiale Muenchen";"-10,80";"";
            ''', dict(card_number=self.card_number, header=HEADER)))  # NOQA

        importer = CreditImporter(self.card_number,
                                  'Assets:DKB:Credit',
                                  file_encoding='utf-8')

        with open(self.filename) as fd:
            transactions = importer.extract(fd)

        self.assertEqual(len(transactions), 1)
        self.assertEqual(transactions[0].date, datetime.date(2018, 1, 15))

        self.assertEqual(len(transactions[0].postings), 1)
        self.assertEqual(transactions[0].postings[0].account,
                         'Assets:DKB:Credit')
        self.assertEqual(transactions[0].postings[0].units.currency, 'EUR')
        self.assertEqual(transactions[0].postings[0].units.number,
                         Decimal('-10.80'))
Пример #10
0
    def test_emits_closing_balance_directive(self):
        with open(self.filename, 'wb') as fd:
            fd.write(
                _format(
                    '''
                    "Kreditkarte:";"{card_number} Kreditkarte";

                    "Von:";"01.01.2018";
                    "Bis:";"31.01.2018";
                    "Saldo:";"5000.01 EUR";
                    "Datum:";"30.01.2018";

                    {header};
                    "Ja";"15.01.2018";"15.01.2018";"REWE Filiale Muenchen";"-10,80";"";
                    ''',  # NOQA
                    dict(card_number=self.card_number, header=HEADER),
                ))
        importer = CreditImporter(self.card_number,
                                  'Assets:DKB:Credit',
                                  file_encoding='utf-8')

        with open(self.filename) as fd:
            transactions = importer.extract(fd)

        self.assertEqual(len(transactions), 2)
        self.assertTrue(isinstance(transactions[1], Balance))
        self.assertEqual(transactions[1].date, datetime.date(2018, 1, 31))
        self.assertEqual(transactions[1].amount,
                         Amount(Decimal('5000.01'), currency='EUR'))
Пример #11
0
    def test_extract_no_transactions(self):
        importer = CreditImporter(self.card_number, 'Assets:DKB:Credit')

        with open(self.filename, 'wb') as fd:
            fd.write(
                _format(
                    '''
                    "Kreditkarte:";"{card_number} Kreditkarte";

                    "Von:";"01.01.2018";
                    "Bis:";"31.01.2018";
                    "Saldo:";"5000.01 EUR";
                    "Datum:";"30.01.2018";

                    {header};
                    ''',
                    dict(card_number=self.card_number, header=HEADER),
                ))

        with open(self.filename) as fd:
            transactions = importer.extract(fd)

        self.assertEqual(len(transactions), 1)
        self.assertTrue(isinstance(transactions[0], Balance))
        self.assertEqual(transactions[0].date, datetime.date(2018, 1, 31))
        self.assertEqual(transactions[0].amount,
                         Amount(Decimal('5000.01'), currency='EUR'))
Пример #12
0
    def test_extract_no_transactions(self):
        importer = CreditImporter(self.card_number, 'Assets:DKB:Credit')

        with open(self.filename, 'wb') as fd:
            fd.write(
                _format(
                    '''
                "Kreditkarte:";"{card_number} Kreditkarte";

                "Von:";"01.01.2018";
                "Bis:";"31.01.2018";
                "Saldo:";"5.000,01 EUR";
                "Datum:";"15.02.2018";

                {header};
            ''', dict(card_number=self.card_number, header=HEADER)))

        with open(self.filename) as fd:
            self.assertFalse(importer.extract(fd))
Пример #13
0
def test_extract_sets_timestamps(tmp_file):
    tmp_file.write(
        _format(
            '''
            "Kreditkarte:";"{card_number} Kreditkarte";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Saldo:";"5000.01 EUR";
            "Datum:";"30.01.2018";

            {header};
            "Ja";"15.01.2018";"15.01.2018";"REWE Filiale Muenchen";"-10,80";"";
            ''',  # NOQA
            dict(
                card_number=Constants.card_number.value,
                header=Constants.header.value,
            ),
        )
    )

    importer = CreditImporter(
        Constants.card_number.value, 'Assets:DKB:Credit', file_encoding='utf-8'
    )

    assert not importer._date_from
    assert not importer._date_to
    assert not importer._balance_amount

    with open(str(tmp_file.realpath())) as fd:
        transactions = importer.extract(fd)

    assert transactions
    assert importer._date_from == datetime.date(2018, 1, 1)
    assert importer._date_to == datetime.date(2018, 1, 31)
    assert importer._balance_date == datetime.date(2018, 1, 31)