def test_get_transfers(mock_usecase, client):
    mock_usecase().execute.return_value = resp.ResponseSuccess(test_transfers)
    http_response = client.get('/transfers')

    assert json.loads(http_response.data.decode('UTF-8')) == [transfer_dict1, transfer_dict2, 
                                                            transfer_dict3, transfer_dict4]
    assert http_response.status_code == 200
    assert http_response.mimetype == 'application/json'
Esempio n. 2
0
def test_post_account_success(mock_usecase, client):
    mock_usecase().execute.return_value = resp.ResponseSuccess(test_account)
    http_response = client.post('/account',
                                data=json.dumps(data),
                                headers=headers)

    assert http_response.status_code == 200
    assert http_response.mimetype == 'application/json'
Esempio n. 3
0
 def execute(self, request):
     try:
         if request:
             response = rs.ResponseSuccess(
                 self._repo.list(filters=request.filters))
         else:
             response = rs.ResponseFailure.from_invalid_request(request)
     except Exception as e:
         response = rs.ResponseFailure.build_system_error(e)
     return response
def test_get_transfers_with_filters(mock_usecase,client):
    mock_usecase().execute.return_value = resp.ResponseSuccess({})
    request_to_use = mock.Mock()
    with(mock.patch('bankaccount.usecases.request_objects.TransferHistoRequest')) as mock_request:
        mock_request.from_dict.return_value = request_to_use
        http_response = client.get('/transfers?filter_param1=value1&filter_param2=value2')

    mock_request.from_dict.assert_called_with({'filters':{'param1':'value1', 'param2':'value2'}})
    mock_usecase.execute.asset_called_with(request_to_use)
    assert http_response.status_code == 200
Esempio n. 5
0
 def execute(self, request):
     with self._uowm.start() as unit_of_work:
         try:
             if request:
                 _found_account = unit_of_work.accounts.find_account(account_code=request.account['code'])
                 if(_found_account is not None):
                     response = rs.ResponseSuccess(unit_of_work.accounts.account_deposit(account=_found_account,
                                                                                         amount=request.account['amount']))
                     unit_of_work.commit()
                 else:
                     response = rs.ResponseFailure.build_resource_error('account not found')
             else:
                 response = rs.ResponseFailure.from_invalid_request(request)
         except Exception as e:
             unit_of_work.rollback()
             response = rs.ResponseFailure.build_system_error(e)            
     return response
Esempio n. 6
0
    def execute(self, request):
        with self._uowm.start() as unit_of_work:
            try:
                if not request:
                    response = rs.ResponseFailure.from_invalid_request(request)

                elif len(request.errors) > 0:
                    response = rs.ResponseFailure.build_parameters_error(
                        'parameter not in the correct format')

                else:
                    _acc_from = unit_of_work.accounts.find_account(
                        account_code=request.transfer['from'])
                    _acc_to = unit_of_work.accounts.find_account(
                        account_code=request.transfer['to'])

                    if request.transfer['from'] == request.transfer['to']:
                        response = rs.ResponseFailure.build_parameters_error(
                            'payer account must be different than the payee')

                    elif _acc_from is None or _acc_to is None:
                        response = rs.ResponseFailure.build_parameters_error(
                            "account doesn't exist")

                    else:
                        _trs = Transfer(request.transfer['id'],
                                        request.transfer['timestamp'],
                                        _acc_from, _acc_to,
                                        request.transfer['amount'])

                        unit_of_work.accounts.account_withdraw(
                            account=_acc_from, amount=_trs.trs_amount)
                        unit_of_work.accounts.account_deposit(
                            account=_acc_to, amount=_trs.trs_amount)
                        unit_of_work.transfers.add_transfer(trs=_trs)
                        unit_of_work.commit()
                        response = rs.ResponseSuccess()

            except Exception as e:
                unit_of_work.rollback()
                response = rs.ResponseFailure.build_system_error(e)

        return response
Esempio n. 7
0
def test_response_success_value(response_value):
    resp = ro.ResponseSuccess(response_value)
    assert resp.value == response_value
Esempio n. 8
0
def test_response_success_is_true(response_value):
    assert bool(ro.ResponseSuccess(response_value)) is True