def test_module_should_fail_when_ftd_server_error(self, resource_mock): operation_name = 'test name' code = 500 response = {'error': 'foo'} resource_mock.side_effect = FtdServerError(response, code) result = self._run_module_with_fail_json({'operation': operation_name}) assert result['failed'] assert 'Server returned an error trying to execute %s operation. Status code: %s. ' \ 'Server response: %s' % (operation_name, code, response) == \ result['msg']
def request_handler(url_path=None, http_method=None, body_params=None, path_params=None, query_params=None): if http_method == HTTPMethod.POST: assert url_path == url assert body_params == params['data'] assert query_params == {} assert path_params == {} return { ResponseParams.SUCCESS: False, ResponseParams.RESPONSE: DUPLICATE_NAME_ERROR_MESSAGE, ResponseParams.STATUS_CODE: UNPROCESSABLE_ENTITY_STATUS } elif http_method == HTTPMethod.GET: is_get_list_req = url_path == url is_get_req = url_path == url_with_id_templ assert is_get_req or is_get_list_req if is_get_list_req: assert body_params == {} assert query_params == { QueryParams.FILTER: 'name:testObject', 'limit': 10, 'offset': 0 } elif is_get_req: assert body_params == {} assert query_params == {} assert path_params == {'objId': obj_id} return { ResponseParams.SUCCESS: True, ResponseParams.RESPONSE: { 'items': [{ 'name': 'testObject', 'value': old_value, 'type': 'object', 'id': obj_id, 'version': version }] } } elif http_method == HTTPMethod.PUT: assert url_path == url_with_id_templ raise FtdServerError(error_msg, error_code) else: assert False
def raise_for_failure(resp): if not resp[ResponseParams.SUCCESS]: raise FtdServerError(resp[ResponseParams.RESPONSE], resp[ResponseParams.STATUS_CODE])