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:";"5000.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._date_balance, datetime.date(2018, 2, 15))
    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:";"5000.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), 2)
        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'))
    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:";"15.02.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, 2, 15))
        self.assertEqual(transactions[0].amount,
                         Amount(Decimal('5000.01'), currency='EUR'))
Exemple #4
0
    def test_identify_correct(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.assertTrue(importer.identify(fd))
def test_identify_correct(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:
        assert importer.identify(fd)
Exemple #6
0
def test_multiple_headers(tmp_file):
    importer = CreditImporter(Constants.card_number.value, 'Assets:DKB:Credit')

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

    # previous header format
    tmp_file.write(
        _format(
            '''
            "Kreditkarte:";"{card_number} Kreditkarte";

            {common}

            ''',
            dict(card_number=Constants.card_number.value, common=common),
        )
    )

    with open(str(tmp_file.realpath())) as fd:
        assert importer.identify(fd)

    # latest header format
    tmp_file.write(
        _format(
            '''
            "Kreditkarte:";"{card_number}";

            {common}

            ''',
            dict(card_number=Constants.card_number.value, common=common),
        )
    )

    with open(str(tmp_file.realpath())) as fd:
        assert importer.identify(fd)
    def test_multiple_headers(self):
        importer = CreditImporter(self.card_number, 'Assets:DKB:Credit')

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

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

                    {common}

                    ''',
                    dict(card_number=self.card_number, common=common),
                ))

        with open(self.filename) as fd:
            self.assertTrue(importer.identify(fd))

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

                    {common}

                    ''',
                    dict(card_number=self.card_number, common=common),
                ))

        with open(self.filename) as fd:
            self.assertTrue(importer.identify(fd))
Exemple #8
0
    def test_identify_invalid_iban(self):
        other_iban = '5678********1234'

        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)))

        importer = CreditImporter(other_iban, 'Assets:DKB:Credit')

        with open(self.filename) as fd:
            self.assertFalse(importer.identify(fd))
def test_identify_invalid_iban(tmp_file):
    other_iban = '5678********1234'

    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),
        ))

    importer = CreditImporter(other_iban, 'Assets:DKB:Credit')

    with tmp_file.open() as fd:
        assert not importer.identify(fd)
def test_multiple_headers(tmp_file):
    importer = CreditImporter(CARD_NUMBER, 'Assets:DKB:Credit')

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

    # previous header format
    tmp_file.write_text(
        _format(
            '''
            "Kreditkarte:";"{card_number} Kreditkarte";

            {common}

            ''',
            dict(card_number=CARD_NUMBER, common=common),
        ))

    with tmp_file.open() as fd:
        assert importer.identify(fd)

    # latest header format
    tmp_file.write_text(
        _format(
            '''
            "Kreditkarte:";"{card_number}";

            {common}

            ''',
            dict(card_number=CARD_NUMBER, common=common),
        ))

    with tmp_file.open() as fd:
        assert importer.identify(fd)
def test_file_date_is_set_correctly(tmp_file):
    tmp_file.write_text(
        _format(
            '''
            "Kreditkarte:";"{card_number} Kreditkarte";

            "Von:";"01.01.2016";
            "Bis:";"31.01.2016";
            "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:
        assert importer.file_date(fd) == datetime.date(2016, 1, 31)
Exemple #12
0
def test_identify_correct(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:
        assert importer.identify(fd)
Exemple #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)