Exemplo n.º 1
0
def test_ivalid_transfer():
    t, b = accounts.transfer(1, 2, 50)
    assert (t, b) == (False, None)

    accounts.create_account(1, 100)
    t, b = accounts.transfer(1, 2, 50)
    assert (t, b) == (False, None)
    assert accounts.get_balance(1) == 100

    accounts.create_account(2, 100)
    t, b = accounts.transfer(1, 2, 150)
    assert (t, b) == (False, {1: 100, 2: 100})
    assert accounts.get_balance(1) == 100
    assert accounts.get_balance(2) == 100
Exemplo n.º 2
0
def test_positive():
    accounts.create_account(1, 100)
    accounts.create_account(2, 200)
    result = accounts.transfer(1, 2, 50)
    assert result == (True, {1: 50, 2: 250})
    assert accounts.get_balance(1) == 50
    assert accounts.get_balance(2) == 250
Exemplo n.º 3
0
def transfer(request, acc1, acc2, amount):
    if acc1 == acc2:
        return json_response({'error': 'same-accounts'}, 400)

    transfered, balance = accounts.transfer(acc1, acc2, amount)
    if transfered:
        return {'result': balance}
    elif balance:
        return json_response({
            'result': balance,
            'error': 'insufficient-funds'
        }, 409)
    else:
        return json_response({'error': 'unknown-account'}, 400)
Exemplo n.º 4
0
 def worker():
     for _ in range(1000):
         acc1 = random.randint(0, 999)
         acc2 = random.randint(0, 999)
         accounts.transfer(acc1, acc2, 1)
Exemplo n.º 5
0
def do_transaction():
    accounts.transfer(1, 2, 0)