Esempio n. 1
0
def test_last_from_id(transactions_json):
    client = FioBank('...')

    options = {'return_value': transactions_json}
    with mock.patch.object(client, '_request', **options) as stub:
        client.last(from_id=308)
        stub.assert_has_calls([
            mock.call('set-last-id', from_id=308),
            mock.call('last'),
        ])
Esempio n. 2
0
def test_last_from_date(transactions_json, test_input):
    client = FioBank('...')

    options = {'return_value': transactions_json}
    with mock.patch.object(client, '_request', **options) as stub:
        client.last(from_date=test_input)
        stub.assert_has_calls([
            mock.call('set-last-date', from_date=date(2016, 8, 30)),
            mock.call('last'),
        ])
Esempio n. 3
0
def test_last_from_date(transactions_json, test_input):
    client = FioBank('...')

    options = {'return_value': transactions_json}
    with mock.patch.object(client, '_request', **options) as stub:
        client.last(from_date=test_input)
        stub.assert_has_calls([
            mock.call('set-last-date', from_date=date(2016, 8, 30)),
            mock.call('last'),
        ])
Esempio n. 4
0
def test_last_from_id(transactions_json):
    client = FioBank('...')

    options = {'return_value': transactions_json}
    with mock.patch.object(client, '_request', **options) as stub:
        client.last(from_id=308)
        stub.assert_has_calls([
            mock.call('set-last-id', from_id=308),
            mock.call('last'),
        ])
Esempio n. 5
0
def test_last_conflicting_params():
    client = FioBank('...')
    with pytest.raises(ValueError):
        client.last(from_id=308, from_date=date(2016, 8, 30))
Esempio n. 6
0
def test_last_conflicting_params():
    client = FioBank('...')
    with pytest.raises(ValueError):
        client.last(from_id=308, from_date=date(2016, 8, 30))
for token in settings.BANK_TOKENS:
    client = FioBank(token=token)
    info = client.info()
    curr,created = Currency.objects.get_or_create(symbol=info.get('currency'))
    if created:
        curr.name = curr.symbol
        curr.save()
    my,created = BankAccount.objects.get_or_create(account_number=info['account_number'], bank_code=info['bank_code'])
    if created:
        my.currency = curr
        my.save()
    logger.info('Processing account %s...' % my)
    try:
        from_id = BankTransaction.objects.filter(my_account=my).latest('date').tid
        sleep(30) # to avoid HTTP 409 - "Conflict" response
        trans = client.last(from_id=from_id)
    except ObjectDoesNotExist:
        sleep(30) # to avoid HTTP 409 - "Conflict" response
        trans = client.last(from_date=FIRST_DATE)

    for tran in trans:
        tid =  tran.get('transaction_id')
        if BankTransaction.objects.filter(tid=tid).exists():
            logger.warning('Transaction %s already here.'%tid)
            continue

        if 'account_number' not in tran or ( 'bank_code' not in  tran and 'bic' not in tran ):
            continue

        acc,created = BankAccount.objects.get_or_create(account_number=tran['account_number'], bank_code=tran['bic'] if 'bic' in tran else tran['bank_code'])
        if created: