コード例 #1
0
def test_too_many_initiated_transfers(db_session, debtor):
    recipient_uri, recipient = acc_id(D_ID, C_ID)
    Debtor.get_instance(D_ID).running_transfers_count = 1
    db_session.add(
        RunningTransfer(
            debtor_id=D_ID,
            transfer_uuid=TEST_UUID,
            recipient=recipient,
            recipient_uri=recipient_uri,
            amount=1000,
            transfer_note_format='',
            transfer_note='',
        ))
    db_session.commit()
    assert len(RunningTransfer.query.all()) == 1
    assert p.get_debtor(D_ID).running_transfers_count == 1
    for i in range(1, 10):
        suffix = '{:0>4}'.format(i)
        uuid = f'123e4567-e89b-12d3-a456-42665544{suffix}',
        p.initiate_running_transfer(D_ID, uuid, *acc_id(D_ID, C_ID), 1000, '',
                                    '', 10)
    assert len(RunningTransfer.query.all()) == 10
    assert p.get_debtor(D_ID).running_transfers_count == 10
    with pytest.raises(p.TooManyRunningTransfers):
        p.initiate_running_transfer(D_ID,
                                    '123e4567-e89b-12d3-a456-426655440010',
                                    *acc_id(D_ID, C_ID), 1000, '', '', 10)
コード例 #2
0
def test_running_transfers(db_session, debtor):
    recipient_uri, recipient = acc_id(D_ID, C_ID)
    Debtor.get_instance(D_ID).running_transfers_count = 1
    db_session.add(
        RunningTransfer(
            debtor_id=D_ID,
            transfer_uuid=TEST_UUID,
            recipient=recipient,
            recipient_uri=recipient_uri,
            transfer_note_format='fmt',
            transfer_note='note',
            amount=1001,
        ))
    db_session.commit()
    assert p.get_debtor(D_ID).running_transfers_count == 1
    with pytest.raises(p.DebtorDoesNotExist):
        p.get_debtor_transfer_uuids(1234567890)
    uuids = p.get_debtor_transfer_uuids(D_ID)
    assert uuids == [TEST_UUID]

    assert p.get_running_transfer(1234567890, TEST_UUID) is None
    t = p.get_running_transfer(D_ID, TEST_UUID)
    assert t.debtor_id == D_ID
    assert t.transfer_uuid == TEST_UUID
    assert t.amount == 1001
    assert t.recipient == recipient
    assert t.recipient_uri == recipient_uri

    p.delete_running_transfer(D_ID, TEST_UUID)
    assert p.get_debtor(D_ID).running_transfers_count == 0
    assert p.get_running_transfer(D_ID, TEST_UUID) is None
コード例 #3
0
def test_deactivate_debtor(db_session, debtor):
    assert debtor.is_activated
    assert not debtor.is_deactivated
    p.deactivate_debtor(D_ID)
    debtor = p.get_debtor(D_ID)
    assert debtor.is_activated
    assert debtor.is_deactivated
    assert debtor.deactivation_date is not None

    p.deactivate_debtor(D_ID)
    debtor = p.get_debtor(D_ID)
    assert debtor.is_deactivated
    assert debtor.deactivation_date is not None

    p.deactivate_debtor(1234567890)
    assert p.get_debtor(1234567890) is None
コード例 #4
0
def debtor(db_session):
    debtor = Debtor(debtor_id=D_ID, status_flags=0)
    debtor.activate()
    db_session.add(debtor)
    db_session.commit()

    return p.get_debtor(D_ID)
コード例 #5
0
def test_account_change_signal_ineffectual_config(db_session, debtor,
                                                  current_ts):
    change_seqnum = 1
    change_ts = datetime.fromisoformat('2019-10-01T00:00:00+00:00')
    p.process_account_update_signal(
        debtor_id=D_ID,
        creditor_id=ROOT_CREDITOR_ID,
        last_change_seqnum=change_seqnum,
        last_change_ts=change_ts,
        principal=-9999,
        interest_rate=10.0,
        creation_date=date(2018, 10, 20),
        last_config_ts=TS0,
        last_config_seqnum=0,
        config_data='',
        account_id='0',
        transfer_note_max_bytes=100,
        negligible_amount=0.0,
        config_flags=DEFAULT_CONFIG_FLAGS,
        ts=current_ts,
        ttl=1000000,
    )
    d = p.get_debtor(D_ID)
    assert d.balance == -9999
    assert d.account_id == '0'
    assert d.transfer_note_max_bytes == 100
    assert d.has_server_account
    assert d.account_creation_date == date(2018, 10, 20)
    assert d.account_last_change_seqnum == change_seqnum
    assert d.account_last_change_ts == change_ts
    assert not d.is_config_effectual
コード例 #6
0
def debtor(db_session):
    debtor = m.Debtor(debtor_id=123, status_flags=0)
    debtor.activate()
    db_session.add(debtor)
    db_session.commit()

    return p.get_debtor(123)
コード例 #7
0
def test_process_account_update_signal_old_ts(debtor, current_ts):
    account_last_heartbeat_ts = debtor.account_last_heartbeat_ts
    change_seqnum = 1
    change_ts = datetime.fromisoformat('2019-10-01T00:00:00+00:00')
    p.process_account_update_signal(
        debtor_id=D_ID,
        creditor_id=ROOT_CREDITOR_ID,
        last_change_seqnum=change_seqnum,
        last_change_ts=change_ts,
        principal=-9999,
        interest_rate=10.0,
        creation_date=date(2018, 10, 20),
        last_config_ts=TS0,
        last_config_seqnum=0,
        config_data='',
        account_id='0',
        transfer_note_max_bytes=100,
        negligible_amount=HUGE_NEGLIGIBLE_AMOUNT,
        config_flags=DEFAULT_CONFIG_FLAGS,
        ts=current_ts - timedelta(days=1),
        ttl=10000,
    )
    d = p.get_debtor(D_ID)
    assert d.balance == 0
    assert d.account_last_heartbeat_ts == account_last_heartbeat_ts

    p.process_account_update_signal(
        debtor_id=D_ID,
        creditor_id=ROOT_CREDITOR_ID,
        last_change_seqnum=0,
        last_change_ts=TS0,
        principal=-9999,
        interest_rate=10.0,
        creation_date=DATE0,
        last_config_ts=TS0,
        last_config_seqnum=0,
        config_data='',
        account_id='0',
        transfer_note_max_bytes=100,
        negligible_amount=HUGE_NEGLIGIBLE_AMOUNT,
        config_flags=DEFAULT_CONFIG_FLAGS,
        ts=current_ts,
        ttl=1000000,
    )
    d = p.get_debtor(D_ID)
    assert d.balance == 0
    assert d.account_last_heartbeat_ts == current_ts
コード例 #8
0
def test_redirect_to_latest_info(client, debtor):
    r = client.get('/debtors/123/public')
    assert r.status_code == 404

    request = {
        'configData': '{"info": {"iri": "https://example.com/"}}',
        'latestUpdateId': 2
    }
    r = client.patch('/debtors/123/config', json=request)
    assert r.status_code == 200

    debtor = p.get_debtor(123)
    current_ts = datetime.now(tz=timezone.utc)

    p.process_account_update_signal(
        debtor_id=debtor.debtor_id,
        creditor_id=p.ROOT_CREDITOR_ID,
        creation_date=date(2020, 1, 1),
        last_change_ts=current_ts,
        last_change_seqnum=1,
        principal=0,
        interest_rate=0.0,
        last_config_ts=debtor.last_config_ts,
        last_config_seqnum=debtor.last_config_seqnum,
        negligible_amount=p.HUGE_NEGLIGIBLE_AMOUNT,
        config_data='INCORRECT CONFIG DATA',
        config_flags=debtor.config_flags,
        account_id='',
        transfer_note_max_bytes=0,
        ts=current_ts,
        ttl=10000000,
    )
    r = client.get('/debtors/123/public')
    assert r.status_code == 404

    p.process_account_update_signal(
        debtor_id=debtor.debtor_id,
        creditor_id=p.ROOT_CREDITOR_ID,
        creation_date=date(2020, 1, 1),
        last_change_ts=current_ts,
        last_change_seqnum=2,
        principal=0,
        interest_rate=0.0,
        last_config_ts=debtor.last_config_ts,
        last_config_seqnum=debtor.last_config_seqnum,
        negligible_amount=p.HUGE_NEGLIGIBLE_AMOUNT,
        config_data=debtor.config_data,
        config_flags=debtor.config_flags,
        account_id='',
        transfer_note_max_bytes=0,
        ts=current_ts,
        ttl=10000000,
    )
    r = client.get('/debtors/123/public')
    assert r.status_code == 302
    assert r.headers['Location'] == 'https://example.com/'
    assert r.headers['Cache-Control'] == 'max-age=86400'