Skip to content
test.py 3.2 KiB
Newer Older
# -*- coding: utf-8 -*-

# Copyright(C) 2010-2011 Romain Bignon, Florent Fourcot
#
# This file is part of a weboob module.
# This weboob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This weboob module is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public License
# along with this weboob module. If not, see <http://www.gnu.org/licenses/>.
from weboob.tools.test import BackendTest
from weboob.capabilities.bank import Account, Transaction
Florent's avatar
Florent committed
from datetime import timedelta
Florent's avatar
Florent committed
import random
class INGTest(BackendTest):
Florent's avatar
Florent committed
    MODULE = 'ing'
Florent's avatar
Florent committed
    def test_accounts(self):
        l = list(self.backend.iter_accounts())
Florent's avatar
Florent committed
        for account in l:
Florent's avatar
Florent committed
            # Test if get_account works
            _id = self.backend.get_account(account.id)
            self.assertTrue(_id.id == account.id)
            # Methods can use Account objects or id. Try one of them
            id_or_account = random.choice([account, account.id])
            history = list(self.backend.iter_history(id_or_account))

            deferred_cards_only = self.backend.browser.only_deferred_cards.get(account._id)
            if deferred_cards_only:
                self.assertTrue(
                    all([transaction.type != Transaction.TYPE_CARD for transaction in history]),
                    "deferred_cards_only should not be true"
                )

            if account.type == Account.TYPE_CHECKING or account.type == Account.TYPE_SAVINGS:
Florent's avatar
Florent committed
                self.assertTrue(len(history) > 0)
David Kremer's avatar
David Kremer committed
                date = history[0].date
                for elem in history[1:]:
                    # check that all the transactions in the history are no
                    # more than 7 days older than the first fetched transaction
                    self.assertTrue(
                        date + timedelta(days=7) >= elem.date,
                        "there's a serious time gap here"
David Kremer's avatar
David Kremer committed
                    )
Florent's avatar
Florent committed
                    date = elem.date
                # recipients = list(self.backend.iter_transfer_recipients(id_or_account))
                # elf.assertTrue(len(recipients) > 0)
Florent's avatar
Florent committed
            elif account.type == Account.TYPE_MARKET:
Florent's avatar
Florent committed
                invest = list(self.backend.iter_investment(id_or_account))
                self.backend.iter_history(id_or_account)  # can be empty. Only try to call it
Florent's avatar
Florent committed
                self.assertTrue(len(invest) > 0)

    def test_subscriptions(self):
        l = list(self.backend.iter_subscription())
        for sub in l:
Florent's avatar
Florent committed
            _id = self.backend.get_subscription(sub.id)
            self.assertTrue(_id.id == sub.id)
            bills = list(self.backend.iter_documents(sub))
Florent's avatar
Florent committed
            self.assertTrue(len(bills) > 0)
            _id = self.backend.get_document(bills[0].id)
Florent's avatar
Florent committed
            self.assertTrue(_id.id == bills[0].id)
            self.backend.download_document(bills[0].id)