def test_trs_op_generic_error(unit_of_work):
    with mock.patch.object(unit_of_work._transfers,
                           'add_transfer',
                           side_effect=Exception('error message')):
        uowm = unit_of_work
        timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        _trs = {
            'id': uuid.uuid4(),
            'timestamp': timestamp,
            'from': '1234567890F',
            'to': '7765432255B',
            'amount': 100.00
        }

        trs_op = uc_trs.TransferAmountUseCase(uowm)
        req = rq.TransferAmountRequest.from_dict({'transfer': _trs})
        resp = trs_op.execute(req)

        assert bool(resp) is False
        assert unit_of_work._committed is False
        assert unit_of_work._rolledback
        assert resp.value == {
            'type': rs.ResponseFailure.SYSTEM_ERROR,
            'message': 'Exception : error message'
        }
def test_trs_op_wrong_param(unit_of_work):
    uowm = unit_of_work

    trs_op = uc_trs.TransferAmountUseCase(uowm)
    req = rq.TransferAmountRequest(trs=0)
    resp = trs_op.execute(req)

    assert bool(resp) is False
    assert unit_of_work._committed is False
    assert resp.value == {
        'type': rs.ResponseFailure.PARAMETERS_ERROR,
        'message': 'transfer : parameter not in the correct format'
    }
def test_trs_op_no_param(unit_of_work):
    uowm = unit_of_work

    trs_op = uc_trs.TransferAmountUseCase(uowm)
    req = rq.TransferAmountRequest.from_dict({})
    resp = trs_op.execute(req)

    assert bool(resp) is False
    assert unit_of_work._committed is False
    assert resp.value == {
        'type': rs.ResponseFailure.PARAMETERS_ERROR,
        'message': 'transfer : parameter is required'
    }
def test_trs_op_success(unit_of_work):
    uowm = unit_of_work
    timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    _trs = {
        'id': uuid.uuid4(),
        'timestamp': timestamp,
        'from': '1234567890F',
        'to': '7765432255B',
        'amount': 100.00
    }

    trs_repo = uowm.transfers
    trs_op = uc_trs.TransferAmountUseCase(uowm)
    req = rq.TransferAmountRequest.from_dict({'transfer': _trs})
    resp = trs_op.execute(req)

    assert bool(resp) is True
    assert unit_of_work._committed
Ejemplo n.º 5
0
def transfer_create():
    if request.headers['Content-Type'] != 'application/json':
        return Response(json.dumps({'message':'content type must be json'}),
                    mimetype='application/json',
                    status=STATUS_CODES[resp.ResponseFailure.PARAMETERS_ERROR])
    else:
        id = uuid.uuid4()
        timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        json_req = request.json
        trs = {'id':str(id),'timestamp':timestamp, 'from':json_req['from'], 'to':json_req['to'], 'amount':json_req['amount']}
        req_object = req.TransferAmountRequest(trs=trs)
        uowm = db.unit_of_work_manager
        usecase = trs_uc.TransferAmountUseCase(uowm)

        resp_object = usecase.execute(req_object)

        return Response(json.dumps(resp_object.value, cls=trs_ser.TransferEncoder),
                        mimetype='application/json',
                        status=STATUS_CODES[resp_object.type])
def test_trs_op_account_not_found(unit_of_work):
    uowm = unit_of_work
    timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    _trs = {
        'id': uuid.uuid4(),
        'timestamp': timestamp,
        'from': '0000000000F',
        'to': '7765432255B',
        'amount': 100.00
    }

    trs_op = uc_trs.TransferAmountUseCase(uowm)
    req = rq.TransferAmountRequest.from_dict({'transfer': _trs})
    resp = trs_op.execute(req)

    assert bool(resp) is False
    assert unit_of_work._committed is False
    assert resp.value == {
        'type': rs.ResponseFailure.PARAMETERS_ERROR,
        'message': "account doesn't exist"
    }
def test_trs_op_payer_is_payee(unit_of_work):
    uowm = unit_of_work
    timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    _trs = {
        'id': uuid.uuid4(),
        'timestamp': timestamp,
        'from': '1234567890F',
        'to': '1234567890F',
        'amount': 100.00
    }

    trs_op = uc_trs.TransferAmountUseCase(uowm)
    req = rq.TransferAmountRequest.from_dict({'transfer': _trs})
    resp = trs_op.execute(req)

    assert bool(resp) is False
    assert unit_of_work._committed is False
    assert resp.value == {
        'type': rs.ResponseFailure.PARAMETERS_ERROR,
        'message': 'payer account must be different than the payee'
    }