Exemplo n.º 1
0
    def test_extract_transactions(self):
        with open(self.filename, 'wb') as fd:
            fd.write(
                _format(
                    '''
                "Kontonummer:";"{iban} / Girokonto";

                "Von:";"01.01.2018";
                "Bis:";"31.01.2018";
                "Kontostand vom 31.01.2017:";"5.000,01 EUR";

                {header};
                "16.01.2018";"16.01.2018";"Lastschrift";"REWE Filialen Voll";"REWE SAGT DANKE.";"DE00000000000000000000";"AAAAAAAA";"-15,37";"000000000000000000    ";"0000000000000000000000";"";
            ''', dict(iban=self.iban, header=HEADER)))  # NOQA

        importer = ECImporter(self.iban,
                              'Assets:DKB:EC',
                              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, 16))

        self.assertEqual(len(transactions[0].postings), 1)
        self.assertEqual(transactions[0].postings[0].account, 'Assets:DKB:EC')
        self.assertEqual(transactions[0].postings[0].units.currency, 'EUR')
        self.assertEqual(transactions[0].postings[0].units.number,
                         Decimal('-15.37'))
Exemplo n.º 2
0
    def test_tagessaldo_emits_balance_directive(self):
        with open(self.filename, 'wb') as fd:
            fd.write(
                _format(
                    '''
                "Kontonummer:";"{iban} / Girokonto";

                "Von:";"01.01.2018";
                "Bis:";"31.01.2018";
                "Kontostand vom 31.01.2017:";"5.000,01 EUR";

                {header};
                "20.01.2018";"";"";"";"Tagessaldo";"";"";"2.500,01";
            ''', dict(iban=self.iban, header=HEADER)))  # NOQA
        importer = ECImporter(self.iban,
                              'Assets:DKB:EC',
                              file_encoding='utf-8')

        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, 20))
        self.assertEqual(transactions[0].amount,
                         Amount(Decimal('2500.01'), currency='EUR'))
Exemplo n.º 3
0
def test_extract_sets_timestamps(tmp_file):
    tmp_file.write(
        _format(
            '''
            "Kontonummer:";"{iban} / Girokonto";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Kontostand vom 31.01.2018:";"5.000,01 EUR";

            {header};
            "16.01.2018";"16.01.2018";"Lastschrift";"REWE Filialen Voll";"REWE SAGT DANKE.";"DE00000000000000000000";"AAAAAAAA";"-15,37";"000000000000000000    ";"0000000000000000000000";"";
            ''',  # NOQA
            dict(iban=Constants.iban.value, header=Constants.header.value),
        ))

    importer = ECImporter(Constants.iban.value,
                          'Assets:DKB:EC',
                          file_encoding='utf-8')

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

    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_amount == Amount(Decimal('5000.01'),
                                              currency='EUR')
    assert importer._balance_date == datetime.date(2018, 2, 1)
Exemplo n.º 4
0
def test_extract_transactions(tmp_file):
    tmp_file.write(
        _format(
            '''
            "Kontonummer:";"{iban} / Girokonto";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Kontostand vom 31.01.2018:";"5.000,01 EUR";

            {header};
            "16.01.2018";"16.01.2018";"Lastschrift";"REWE Filialen Voll";"REWE SAGT DANKE.";"DE00000000000000000000";"AAAAAAAA";"-15,37";"000000000000000000    ";"0000000000000000000000";"";
            ''',  # NOQA
            dict(iban=Constants.iban.value, header=Constants.header.value),
        ))

    importer = ECImporter(Constants.iban.value,
                          'Assets:DKB:EC',
                          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, 16)
    assert transactions[0].payee == 'REWE Filialen Voll'
    assert transactions[0].narration == 'Lastschrift REWE SAGT DANKE.'

    assert len(transactions[0].postings) == 1
    assert transactions[0].postings[0].account == 'Assets:DKB:EC'
    assert transactions[0].postings[0].units.currency == 'EUR'
    assert transactions[0].postings[0].units.number == Decimal('-15.37')
Exemplo n.º 5
0
def test_tagessaldo_with_empty_balance_does_not_crash(tmp_file):
    tmp_file.write(
        _format(
            '''
            "Kontonummer:";"{iban} / Girokonto";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Kontostand vom 31.01.2018:";"5.000,01 EUR";

            {header};
            "20.01.2018";"";"";"";"Tagessaldo";"";"";"";
            ''',
            dict(iban=Constants.iban.value, header=Constants.header.value),
        ))

    importer = ECImporter(Constants.iban.value,
                          'Assets:DKB:EC',
                          file_encoding='utf-8')

    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, 2, 1)
    assert transactions[0].amount == Amount(Decimal('5000.01'), currency='EUR')
Exemplo n.º 6
0
def test_mismatching_dates_in_meta(tmp_file):
    tmp_file.write_text(
        _format(
            '''
            "Kontonummer:";"{iban} / Girokonto";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Kontostand vom 31.01.2019:";"5.000,01 EUR";

            {header};
            "16.01.2018";"16.01.2018";"Lastschrift";"REWE Filialen Voll";"REWE SAGT DANKE.";"DE00000000000000000000";"AAAAAAAA";"-15,37";"000000000000000000    ";"0000000000000000000000";"";
            ''',  # NOQA
            dict(iban=IBAN, header=HEADER),
        )
    )

    importer = ECImporter(IBAN, 'Assets:DKB:EC', 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(2019, 2, 1)
    assert directives[1].amount == Amount(Decimal('5000.01'), currency='EUR')
Exemplo n.º 7
0
def test_tagessaldo_with_empty_balance_does_not_crash(tmp_file):
    tmp_file.write_text(
        _format(
            '''
            "Kontonummer:";"{iban} / Girokonto";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Kontostand vom 31.01.2018:";"5.000,01 EUR";

            {header};
            "20.01.2018";"";"";"";"Tagessaldo";"";"";"";
            ''',
            dict(iban=IBAN, header=HEADER),
        )
    )

    importer = ECImporter(IBAN, 'Assets:DKB:EC', file_encoding='utf-8')

    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, 2, 1)
    assert directives[0].amount == Amount(Decimal('5000.01'), currency='EUR')
Exemplo n.º 8
0
def test_mismatching_dates_in_meta(tmp_file):
    tmp_file.write(
        _format(
            '''
            "Kontonummer:";"{iban} / Girokonto";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Kontostand vom 31.01.2019:";"5.000,01 EUR";

            {header};
            "16.01.2018";"16.01.2018";"Lastschrift";"REWE Filialen Voll";"REWE SAGT DANKE.";"DE00000000000000000000";"AAAAAAAA";"-15,37";"000000000000000000    ";"0000000000000000000000";"";
            ''',  # NOQA
            dict(iban=Constants.iban.value, header=Constants.header.value),
        ))

    importer = ECImporter(Constants.iban.value,
                          'Assets:DKB:EC',
                          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(2019, 2, 1)
    assert transactions[1].amount == Amount(Decimal('5000.01'), currency='EUR')
Exemplo n.º 9
0
def test_extract_no_transactions(tmp_file):
    importer = ECImporter(IBAN, 'Assets:DKB:EC')

    tmp_file.write_text(
        _format(
            '''
            "Kontonummer:";"{iban} / Girokonto";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Kontostand vom 31.01.2018:";"5.000,01 EUR";

            {header};
            ''',
            dict(iban=IBAN, 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, 2, 1)
    assert directives[0].amount == Amount(Decimal('5000.01'), currency='EUR')
Exemplo n.º 10
0
    def test_extract_sets_timestamps(self):
        with open(self.filename, 'wb') as fd:
            fd.write(
                _format(
                    '''
                "Kontonummer:";"{iban} / Girokonto";

                "Von:";"01.01.2018";
                "Bis:";"31.01.2018";
                "Kontostand vom 31.01.2017:";"5.000,01 EUR";

                {header};
                "16.01.2018";"16.01.2018";"Lastschrift";"REWE Filialen Voll";"REWE SAGT DANKE.";"DE00000000000000000000";"AAAAAAAA";"-15,37";"000000000000000000    ";"0000000000000000000000";"";
            ''', dict(iban=self.iban, header=HEADER)))  # NOQA

        importer = ECImporter(self.iban,
                              'Assets:DKB:EC',
                              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'))
Exemplo n.º 11
0
    def test_tagessaldo_emits_balance_directive(self):
        with open(self.filename, 'wb') as fd:
            fd.write(
                _format(
                    '''
                "Kontonummer:";"{iban} / Girokonto";

                "Von:";"01.01.2018";
                "Bis:";"31.01.2018";
                "Kontostand vom 31.01.2017:";"5.000,01 EUR";

                {header};
                "16.01.2018";"16.01.2018";"Lastschrift";"REWE Filialen Voll";"REWE SAGT DANKE.";"DE00000000000000000000";"AAAAAAAA";"-15,37";"000000000000000000    ";"0000000000000000000000";"";
                "20.01.2018";"";"";"";"Tagessaldo";"";"";"2.500,01";
            ''', dict(iban=self.iban, header=HEADER)))  # NOQA
        importer = ECImporter(self.iban,
                              'Assets:DKB:EC',
                              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)
Exemplo n.º 12
0
    def test_identify_with_exotic_account_name(self):
        importer = ECImporter(self.iban, 'Assets:DKB:EC')

        with open(self.filename, 'wb') as fd:
            fd.write(_format('''
                "Kontonummer:";"{iban} / Girökóntô, Γιροκοντώ, 預金, حساب البنك";

                "Von:";"01.01.2018";
                "Bis:";"31.01.2018";
                "Kontostand vom 31.01.2018:";"5.000,01 EUR";

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

        with open(self.filename) as fd:
            self.assertTrue(importer.identify(fd))
Exemplo n.º 13
0
    def test_identify_with_formatted_iban(self):
        importer = ECImporter(self.formatted_iban, 'Assets:DKB:EC')

        with open(self.filename, 'wb') as fd:
            fd.write(_format('''
                "Kontonummer:";"{iban} / Girokonto";

                "Von:";"01.01.2018";
                "Bis:";"31.01.2018";
                "Kontostand vom 31.01.2018:";"5.000,01 EUR";

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

        with open(self.filename) as fd:
            self.assertTrue(importer.identify(fd))
Exemplo n.º 14
0
    def test_extract_no_transactions(self):
        importer = ECImporter(self.iban, 'Assets:DKB:EC')

        with open(self.filename, 'wb') as fd:
            fd.write(
                _format(
                    '''
                "Kontonummer:";"{iban} / Girokonto";

                "Von:";"01.01.2018";
                "Bis:";"31.01.2018";
                "Kontostand vom 31.01.2017:";"5.000,01 EUR";

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

        with open(self.filename) as fd:
            self.assertFalse(importer.extract(fd))
Exemplo n.º 15
0
    def test_file_date(self):
        with open(self.filename, 'wb') as fd:
            fd.write(_format('''
                "Kontonummer:";"{iban} / Girokonto";

                "Von:";"01.01.2018";
                "Bis:";"31.01.2018";
                "Kontostand vom 31.01.2018:";"5.000,01 EUR";

                {header};
                "20.01.2018";"";"";"";"Tagessaldo";"";"";"2.500,01";
            ''', dict(iban=self.iban, header=HEADER)))  # NOQA
        importer = ECImporter(self.iban, 'Assets:DKB:EC',
                              file_encoding='utf-8')

        with open(self.filename) as fd:
            self.assertEqual(importer.file_date(fd),
                             datetime.date(2018, 1, 31))
Exemplo n.º 16
0
def test_identify_with_formatted_iban(tmp_file):
    importer = ECImporter(Constants.formatted_iban.value, 'Assets:DKB:EC')

    tmp_file.write(
        _format(
            '''
            "Kontonummer:";"{iban} / Girokonto";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Kontostand vom 31.01.2018:";"5.000,01 EUR";

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

    with open(str(tmp_file.realpath())) as fd:
        assert importer.identify(fd)
Exemplo n.º 17
0
def test_identify_with_exotic_account_name(tmp_file):
    importer = ECImporter(Constants.iban.value, 'Assets:DKB:EC')

    tmp_file.write(
        _format(
            '''
            "Kontonummer:";"{iban} / Girökóntô, Γιροκοντώ, 預金, حساب البنك";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Kontostand vom 31.01.2018:";"5.000,01 EUR";

            {header};
            ''',  # NOQA
            dict(iban=Constants.iban.value, header=Constants.header.value),
        ))

    with open(str(tmp_file.realpath())) as fd:
        assert importer.identify(fd)
Exemplo n.º 18
0
def test_identify_with_nonstandard_account_name(tmp_file):
    importer = ECImporter(IBAN, 'Assets:DKB:EC')

    tmp_file.write_text(
        _format(
            '''
            "Kontonummer:";"{iban} / My Custom Named Account";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Kontostand vom 31.01.2018:";"5.000,01 EUR";

            {header};
            ''',
            dict(iban=IBAN, header=HEADER),
        )
    )

    with tmp_file.open() as fd:
        assert importer.identify(fd)
Exemplo n.º 19
0
def test_identify_with_exotic_account_name(tmp_file):
    importer = ECImporter(IBAN, 'Assets:DKB:EC')

    tmp_file.write_text(
        _format(
            '''
            "Kontonummer:";"{iban} / Girökóntô, Γιροκοντώ, 預金, حساب البنك";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Kontostand vom 31.01.2018:";"5.000,01 EUR";

            {header};
            ''',  # NOQA
            dict(iban=IBAN, header=HEADER),
        )
    )

    with tmp_file.open() as fd:
        assert importer.identify(fd)
Exemplo n.º 20
0
def test_identify_with_formatted_iban(tmp_file):
    importer = ECImporter(FORMATTED_IBAN, 'Assets:DKB:EC')

    tmp_file.write_text(
        _format(
            '''
            "Kontonummer:";"{iban} / Girokonto";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Kontostand vom 31.01.2018:";"5.000,01 EUR";

            {header};
            ''',
            dict(iban=IBAN, header=HEADER),
        )
    )

    with tmp_file.open() as fd:
        assert importer.identify(fd)
Exemplo n.º 21
0
def test_extract_transactions(tmp_file):
    tmp_file.write_text(
        _format(
            '''
            "Kontonummer:";"{iban} / Girokonto";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Kontostand vom 31.01.2018:";"5.000,01 EUR";

            {header};
            "16.01.2018";"16.01.2018";"Lastschrift";"REWE Filialen Voll";"REWE SAGT DANKE.";"DE00000000000000000000";"AAAAAAAA";"-15,37";"000000000000000000    ";"0000000000000000000000";"";
            "06.05.2020";"06.05.2020";"Gutschrift";"From Someone";"";"DE88700222000012345678";"FDDODEMMXXX";"1,00";"";"";"NOTPROVIDED";
            ''',  # NOQA
            dict(iban=IBAN, header=HEADER),
        )
    )

    importer = ECImporter(IBAN, 'Assets:DKB:EC', file_encoding='utf-8')

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

    assert len(directives) == 3
    assert directives[0].date == datetime.date(2018, 1, 16)
    assert directives[0].payee == 'REWE Filialen Voll'
    assert directives[0].narration == 'Lastschrift REWE SAGT DANKE.'

    assert len(directives[0].postings) == 1
    assert directives[0].postings[0].account == 'Assets:DKB:EC'
    assert directives[0].postings[0].units.currency == 'EUR'
    assert directives[0].postings[0].units.number == Decimal('-15.37')

    assert directives[1].date == datetime.date(2020, 5, 6)
    assert directives[1].payee == 'From Someone'
    assert directives[1].narration == 'Gutschrift DE88700222000012345678'

    assert len(directives[1].postings) == 1
    assert directives[1].postings[0].account == 'Assets:DKB:EC'
    assert directives[1].postings[0].units.currency == 'EUR'
    assert directives[1].postings[0].units.number == Decimal('1.00')
Exemplo n.º 22
0
def test_file_date_is_set_correctly(tmp_file):
    tmp_file.write_text(
        _format(
            '''
            "Kontonummer:";"{iban} / Girokonto";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Kontostand vom 31.01.2018:";"5.000,01 EUR";

            {header};
            "20.01.2018";"";"";"";"Tagessaldo";"";"";"2.500,01";
            ''',
            dict(iban=IBAN, header=HEADER),
        )
    )

    importer = ECImporter(IBAN, 'Assets:DKB:EC', file_encoding='utf-8')

    with tmp_file.open() as fd:
        assert importer.file_date(fd) == datetime.date(2018, 1, 31)
Exemplo n.º 23
0
def test_file_date(tmp_file):
    tmp_file.write(
        _format(
            '''
            "Kontonummer:";"{iban} / Girokonto";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Kontostand vom 31.01.2018:";"5.000,01 EUR";

            {header};
            "20.01.2018";"";"";"";"Tagessaldo";"";"";"2.500,01";
            ''',
            dict(iban=Constants.iban.value, header=Constants.header.value),
        ))

    importer = ECImporter(Constants.iban.value,
                          'Assets:DKB:EC',
                          file_encoding='utf-8')

    with open(str(tmp_file.realpath())) as fd:
        assert importer.file_date(fd) == datetime.date(2018, 1, 31)
Exemplo n.º 24
0
    def test_extract_no_transactions(self):
        importer = ECImporter(self.iban, 'Assets:DKB:EC')

        with open(self.filename, 'wb') as fd:
            fd.write(_format('''
                "Kontonummer:";"{iban} / Girokonto";

                "Von:";"01.01.2018";
                "Bis:";"31.01.2018";
                "Kontostand vom 31.01.2018:";"5.000,01 EUR";

                {header};
            ''', dict(iban=self.iban, 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'))
Exemplo n.º 25
0
def test_identify_invalid_iban(tmp_file):
    other_iban = 'DE00000000000000000000'

    tmp_file.write_text(
        _format(
            '''
            "Kontonummer:";"{iban} / Girokonto";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Kontostand vom 31.01.2018:";"5.000,01 EUR";

            {header};
            ''',
            dict(iban=IBAN, header=HEADER),
        )
    )

    importer = ECImporter(other_iban, 'Assets:DKB:EC')

    with tmp_file.open() as fd:
        assert not importer.identify(fd)
Exemplo n.º 26
0
    def test_emits_closing_balance_directive(self):
        with open(self.filename, 'wb') as fd:
            fd.write(_format('''
                "Kontonummer:";"{iban} / Girokonto";

                "Von:";"01.01.2018";
                "Bis:";"31.01.2018";
                "Kontostand vom 31.01.2017:";"5.000,01 EUR";

                {header};
                "16.01.2018";"16.01.2018";"Lastschrift";"REWE Filialen Voll";"REWE SAGT DANKE.";"DE00000000000000000000";"AAAAAAAA";"-15,37";"000000000000000000    ";"0000000000000000000000";"";
            ''', dict(iban=self.iban, header=HEADER)))  # NOQA
        importer = ECImporter(self.iban, 'Assets:DKB:EC',
                              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'))
Exemplo n.º 27
0
def test_extract_no_transactions(tmp_file):
    importer = ECImporter(Constants.iban.value, 'Assets:DKB:EC')

    tmp_file.write(
        _format(
            '''
            "Kontonummer:";"{iban} / Girokonto";

            "Von:";"01.01.2018";
            "Bis:";"31.01.2018";
            "Kontostand vom 31.01.2018:";"5.000,01 EUR";

            {header};
            ''',
            dict(iban=Constants.iban.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, 2, 1)
    assert transactions[0].amount == Amount(Decimal('5000.01'), currency='EUR')