Exemplo n.º 1
0
def test_refund_payment_handles_error(mock_pay_bill, mock_send_op_result):
    request_id = 'testid'
    task_info = dict(request_id=request_id, )
    save_task_info(task_info)
    runner = CliRunner()
    with pytest.raises(Exception):
        pay_bill(request_id, 'internet_telmex', '2424240024')
    result = runner.invoke(change_status, [request_id, 'failed'])
    get_task_info(dict(request_id=request_id))
    assert result.output == 'connection error try again\n'
Exemplo n.º 2
0
def test_save_task_info():
    task_id = str(uuid4())
    task_info = dict(
        task_id=task_id,
        task_name='arcusd.tasks.mytask',
    )
    tasks.save_task_info(task_info)
    db_task_info = tasks.get_task_info({'task_id': task_id})
    assert db_task_info['task_id'] == task_id
Exemplo n.º 3
0
def test_command_change_status_already_exists(mock_pay_bill,
                                              mock_send_op_result):
    request_id = 'testingId2'
    task_info = dict(request_id=request_id, op_info=dict(status='success'))
    save_task_info(task_info)
    runner = CliRunner()
    result = runner.invoke(change_status, [request_id, 'failed'])
    assert result.exit_code == 0
    transaction = get_task_info(dict(request_id=request_id))
    assert transaction['op_info']['status'] == 'failed'
Exemplo n.º 4
0
def test_set_status_failed_creates_op_info(mock_pay_bill, mock_send_op_result):
    request_id = 'request-id2'
    task_info = dict(request_id=request_id, )
    save_task_info(task_info)
    runner = CliRunner()
    with pytest.raises(Exception):
        pay_bill(request_id, 'internet_telmex', '2424240024')
    result = runner.invoke(change_status, [request_id, 'failed'])
    assert result.exit_code == 0
    transaction = get_task_info(dict(request_id=request_id))
    assert transaction['op_info'] is not None
    assert transaction['op_info']['status'] == 'failed'
    assert mock_send_op_result.called
Exemplo n.º 5
0
def test_success_and_create_op_info(mock_pay_bill, mock_send_op_result):
    request_id = 'idtest'
    task_info = dict(request_id=request_id, )
    save_task_info(task_info)
    runner = CliRunner()
    with pytest.raises(Exception):
        pay_bill(request_id, 'internet_telmex', '2424240024')
    result = runner.invoke(change_status, [request_id, 'success'],
                           input='arcus-id\n100')
    assert result.exit_code == 0
    transaction = get_task_info(dict(request_id=request_id))
    assert transaction['op_info']['operation']['amount'] == 100
    assert transaction['op_info']['operation']['id'] == 'arcus-id'
Exemplo n.º 6
0
def test_task_before_run():
    request_id = 'abcedfg'
    task_id = '123456789'
    task = Mock()
    task.request.origin = 'test-origin'
    task.request.args = None
    task.request.kwargs = {
        'a': 'a',
        'b': 1,
        'request_id': request_id,
    }
    task.request.retries = 0
    task_before_run(task_id, task)
    task_info = get_task_info({'request_id': request_id})
    assert task_info['request_id'] == request_id
Exemplo n.º 7
0
def test_update_task_info():
    task_id = str(uuid4())
    task_info1 = dict(
        task_id=task_id,
        task_name='arcusd.tasks.mytask',
    )
    tasks.save_task_info(task_info1)
    task_info2 = dict(task_result='task_result',
                      op_info={
                          'prop1': 123234,
                          'prop2': 'abcdf'
                      })
    tasks.update_task_info({'task_id': task_id}, task_info2)
    db_task_info = tasks.get_task_info({'task_id': task_id})
    assert db_task_info['task_id'] == task_info1['task_id']
    assert db_task_info['task_name'] == task_info1['task_name']
    assert db_task_info['task_result'] == task_info2['task_result']
    assert db_task_info['op_info']['prop1'] == task_info2['op_info']['prop1']
    assert db_task_info['op_info']['prop2'] == task_info2['op_info']['prop2']
Exemplo n.º 8
0
def test_task_after_run():
    request_id = 'abcedfg'
    task_id = '123456789'
    task = Mock()
    task.request.origin = 'test-origin'
    task.request.args = None
    task.request.kwargs = {
        'a': 'a',
        'b': 1,
        'request_id': request_id,
    }
    task.request.retries = 0
    task.request.state = 'SUCCESS'
    task.request.eta = None
    op_info = OpInfo(request_id, OperationType.topup, OperationStatus.success)
    task_after_run(task_id, task, op_info, 'SUCCESS')
    task_info = get_task_info({'request_id': request_id})
    assert task_info['request_id'] == request_id
    assert 'task_state' in task_info
    assert 'task_eta' in task_info
    assert 'task_retval' in task_info
Exemplo n.º 9
0
def change_status(transaction_id: str, status: str) -> None:
    """If status entered is success it completes op_info
    property on incomplete transactions and refunds
    transactions on failed status"""

    task = get_task_info(dict(request_id=transaction_id))
    if task is None:
        click.echo(f'transaction id {transaction_id} does not exists')
        return
    if 'op_info' in task and task['op_info']['status'] == 'failed':
        click.echo('transaction was already refunded')
        return
    else:
        if status == 'success':
            id_value = click.prompt('please enter arcus id: ', type=str)
            amount = click.prompt('please enter amount paid in cents: ',
                                  type=int)
            update_task_info(
                dict(request_id=transaction_id),
                dict(op_info=dict(
                    request_id=transaction_id,
                    tran_type='payment',
                    status=status,
                    operation=dict(id=id_value, amount=amount, currency='MXN'),
                )),
            )
        else:
            update_insert_task_info(
                {'request_id': transaction_id},
                {
                    'op_info.request_id': transaction_id,
                    'op_info.tran_type': 'payment',
                    'op_info.status': status,
                },
            )
        try:
            CallbackHelper.send_op_result(
                OpInfo(transaction_id, OperationType.payment, status))
        except ConnectionError:
            click.echo('connection error try again')