Python six.moves.http_client.NO_CONTENT Examples
The following are 30
code examples of six.moves.http_client.NO_CONTENT().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
six.moves.http_client
, or try the search function
.
Example #1
Source File: test_release_resources.py From rotest with MIT License | 6 votes |
def test_valid_release(self): """Assert valid resource release.""" resources = DemoResourceData.objects.filter( name='available_resource1') resource, = resources resource.owner = "localhost" resource.save() SESSIONS[self.token].resources = [resource] response, _ = self.requester(json_data={ "resources": ["available_resource1"], "token": self.token }) # refresh from db resources = DemoResourceData.objects.filter( name='available_resource1') resource, = resources self.assertEqual(response.status_code, http_client.NO_CONTENT) self.assertEqual(resource.owner, "")
Example #2
Source File: test_run.py From column with GNU General Public License v3.0 | 6 votes |
def _test_delete_running_job(self): pb = 'tests/fixtures/playbooks/hello_world_with_sleep.yml' response = self.app.post( '/runs', data=json.dumps(dict(playbook_path=pb, inventory_file='localhost,', options={'connection': 'local', 'subset': None})), content_type='application/json') res_dict = json.loads(response.data) self.assertEqual(http_client.CREATED, response.status_code) response = self.app.delete('/runs/{}'.format(res_dict['id'])) self.assertEqual(http_client.NO_CONTENT, response.status_code) response = self.app.get('/runs/{}'.format(res_dict['id'])) res_dict = json.loads(response.data) self.assertEqual('ABORTED', res_dict['state']) self._wait_for_run_complete(res_dict['id'])
Example #3
Source File: test_transport_http.py From suds with GNU Lesser General Public License v3.0 | 6 votes |
def test_operation_invoke_with_urlopen_accept_no_content__no_data(self, status_code): """ suds.client.Client web service operation invocation expecting no output data, and for which a corresponding urlopen call raises a HTTPError with status code ACCEPTED or NO_CONTENT, should treat this as a successful invocation. """ # We are not yet sure that the behaviour checked for in this test is # actually desired. The test is only an 'educated guess' prepared to # demonstrate a related problem in the original suds library # implementation. The original implementation is definitely buggy as # its web service operation invocation raises an AttributeError # exception by attempting to access a non-existing 'None.message' # attribute internally. e = self.create_HTTPError(code=status_code) transport = suds.transport.http.HttpTransport() transport.urlopener = MockURLOpenerSaboteur(open_exception=e) wsdl = testutils.wsdl('<xsd:element name="o" type="xsd:string"/>', output="o", operation_name="f") client = testutils.client_from_wsdl(wsdl, transport=transport) assert client.service.f() is None
Example #4
Source File: test_transport_http.py From suds with GNU Lesser General Public License v3.0 | 6 votes |
def test_operation_invoke_with_urlopen_accept_no_content__data(self, status_code): """ suds.client.Client web service operation invocation expecting output data, and for which a corresponding urlopen call raises a HTTPError with status code ACCEPTED or NO_CONTENT, should report this as a TransportError. """ e = self.create_HTTPError(code=status_code) transport = suds.transport.http.HttpTransport() transport.urlopener = MockURLOpenerSaboteur(open_exception=e) wsdl = testutils.wsdl('<xsd:element name="o" type="xsd:string"/>', output="o", operation_name="f") client = testutils.client_from_wsdl(wsdl, transport=transport) pytest.raises(suds.transport.TransportError, client.service.f)
Example #5
Source File: start_composite.py From rotest with MIT License | 6 votes |
def post(self, request, sessions, *args, **kwargs): """Update the test data to 'in progress' state and set the start time. Args: test_id (number): the identifier of the test. """ session_token = request.model.token try: session_data = sessions[session_token] test_data = session_data.all_tests[request.model.test_id] except KeyError: raise BadRequest("Invalid token/test_id provided " "(Test timed out?)") test_data.start() test_data.save() return Response({}, status=http_client.NO_CONTENT)
Example #6
Source File: base_api.py From apitools with Apache License 2.0 | 6 votes |
def __ProcessHttpResponse(self, method_config, http_response, request): """Process the given http response.""" if http_response.status_code not in (http_client.OK, http_client.CREATED, http_client.NO_CONTENT): raise exceptions.HttpError.FromResponse( http_response, method_config=method_config, request=request) if http_response.status_code == http_client.NO_CONTENT: # TODO(craigcitro): Find out why _replace doesn't seem to work # here. http_response = http_wrapper.Response( info=http_response.info, content='{}', request_url=http_response.request_url) content = http_response.content if self._client.response_encoding and isinstance(content, bytes): content = content.decode(self._client.response_encoding) if self.__client.response_type_model == 'json': return content response_type = _LoadClass(method_config.response_type_name, self.__client.MESSAGES_MODULE) return self.__client.DeserializeMessage(response_type, content)
Example #7
Source File: add_test_result.py From rotest with MIT License | 6 votes |
def post(self, request, sessions, *args, **kwargs): """Add a result to the test. Args: test_id (number): the identifier of the test. result_code (number): code of the result as defined in TestOutcome. info (str): additional info (traceback / end reason etc). """ session_token = request.model.test_details.token try: session_data = sessions[session_token] test_data = \ session_data.all_tests[request.model.test_details.test_id] except KeyError: raise BadRequest("Invalid token/test_id provided " "(Test timed out?)") test_data.update_result(request.model.result.result_code, request.model.result.info) test_data.save() return Response({}, status=http_client.NO_CONTENT)
Example #8
Source File: stop_test.py From rotest with MIT License | 6 votes |
def post(self, request, sessions, *args, **kwargs): """End a test run. Args: request (Request): StopTest request. """ session_token = request.model.token try: session_data = sessions[session_token] test_data = session_data.all_tests[request.model.test_id] except KeyError: raise BadRequest("Invalid token/test_id provided " "(Test timed out?)") test_data.end() test_data.save() return Response({}, status=http_client.NO_CONTENT)
Example #9
Source File: stop_composite.py From rotest with MIT License | 6 votes |
def post(self, request, sessions, *args, **kwargs): """Save the composite test's data. Args: test_id (number): the identifier of the test. """ session_token = request.model.token try: session_data = sessions[session_token] test_data = session_data.all_tests[request.model.test_id] except KeyError: raise BadRequest("Invalid token/test_id provided " "(Test timed out?)") has_succeeded = all(sub_test.success for sub_test in test_data) test_data.success = has_succeeded test_data.end() test_data.save() return Response({}, status=http_client.NO_CONTENT)
Example #10
Source File: update_fields.py From rotest with MIT License | 6 votes |
def put(self, request, *args, **kwargs): """Update content in the server's DB. Args: model (type): Django model to apply changes on. filter (dict): arguments to filter by. changes (dict): the additional arguments are the changes to apply on the filtered instances. """ model = extract_type(request.model.resource_descriptor.type) filter_dict = request.model.resource_descriptor.properties kwargs_vars = request.model.changes with transaction.atomic(): objects = model.objects.select_for_update() if filter_dict is not None and len(filter_dict) > 0: objects.filter(**filter_dict).update(**kwargs_vars) else: objects.all().update(**kwargs_vars) return Response({}, status=http_client.NO_CONTENT)
Example #11
Source File: test_policies.py From st2 with Apache License 2.0 | 6 votes |
def test_crud(self): instance = self.__create_instance() post_resp = self.__do_post(instance) self.assertEqual(post_resp.status_int, http_client.CREATED) get_resp = self.__do_get_one(self.__get_obj_id(post_resp)) self.assertEqual(get_resp.status_int, http_client.OK) updated_input = get_resp.json updated_input['enabled'] = not updated_input['enabled'] put_resp = self.__do_put(self.__get_obj_id(post_resp), updated_input) self.assertEqual(put_resp.status_int, http_client.OK) self.assertEqual(put_resp.json['enabled'], updated_input['enabled']) del_resp = self.__do_delete(self.__get_obj_id(post_resp)) self.assertEqual(del_resp.status_int, http_client.NO_CONTENT)
Example #12
Source File: cleanup_user.py From rotest with MIT License | 6 votes |
def post(self, request, sessions, *args, **kwargs): """Clean up user's requests and locked resources. Args: username (str): the username to cleanup. Returns: SuccessReply. a reply indicating on a successful operation. """ username = get_username(request) session = sessions[request.model.token] for resource in session.resources: ReleaseResources.release_resource(resource, username=None) return Response({ "details": "User {} was successfully cleaned".format(username) }, status=http_client.NO_CONTENT)
Example #13
Source File: test_test_control.py From rotest with MIT License | 6 votes |
def test_update_resources(self): """Assert that the request has the right server response.""" response, _ = self.requester( path="tests/update_resources", params={ "token": self.token, "test_id": self.test_case.identifier }, json_data={ "descriptors": [{ "type": "rotest.management.models.ut_models." "DemoResourceData", "properties": { "name": "available_resource1" } }] }) self.assertEqual(response.status_code, http_client.NO_CONTENT)
Example #14
Source File: test_test_control.py From rotest with MIT License | 6 votes |
def test_start_test_stop_test(self): """Assert that the request has the right server response.""" response, _ = self.requester(path="tests/start_test", params={ "token": self.token, "test_id": self.test_case.identifier }) self.assertEqual(response.status_code, http_client.NO_CONTENT) response, _ = self.requester(path="tests/stop_test", params={ "token": self.token, "test_id": self.test_case.identifier }) self.assertEqual(response.status_code, http_client.NO_CONTENT)
Example #15
Source File: test_test_control.py From rotest with MIT License | 6 votes |
def test_start_test_stop_composite(self): """Assert that the request has the right server response.""" response, _ = self.requester(path="tests/start_composite", params={ "token": self.token, "test_id": self.test_case.identifier }) self.assertEqual(response.status_code, http_client.NO_CONTENT) response, _ = self.requester(path="tests/stop_composite", params={ "token": self.token, "test_id": self.test_case.identifier }) self.assertEqual(response.status_code, http_client.NO_CONTENT)
Example #16
Source File: test_cleanup_user.py From rotest with MIT License | 6 votes |
def test_release_owner_complex_resource(self): """Assert response - cleanup of complex resource.""" resources = DemoComplexResourceData.objects.filter( name='complex_resource1') resource, = resources sub_resource = resource.demo1 resource.owner = "localhost" sub_resource.owner = "localhost" resource.save() sub_resource.save() SESSIONS[self.token].resources = [resource] response, _ = self.requester(json_data={"token": self.token}) self.assertEqual(response.status_code, http_client.NO_CONTENT) resources = DemoComplexResourceData.objects.filter( name='complex_resource1') resource, = resources sub_resource = resource.demo1 self.assertEqual(resource.owner, "") self.assertEqual(sub_resource.owner, "")
Example #17
Source File: test_update_fields.py From rotest with MIT License | 6 votes |
def test_update_all_resources_fields(self): """Assert that updating all resources when no filter exists - works.""" response, _ = self.requester(json_data={ "resource_descriptor": { "type": "rotest.management.models.ut_models." "DemoResourceData", "properties": {} }, "changes": { "reserved": "A_User" } }) self.assertEqual(response.status_code, http_client.NO_CONTENT) resources = DemoResourceData.objects.all() for resource in resources: self.assertEqual(resource.reserved, "A_User")
Example #18
Source File: test_update_fields.py From rotest with MIT License | 6 votes |
def test_update_specific_resource_fields(self): """Assert that updating specific resource - works.""" response, _ = self.requester(json_data={ "resource_descriptor": { "type": "rotest.management.models.ut_models." "DemoResourceData", "properties": { "name": "available_resource1" } }, "changes": { "reserved": "A_User" } }) self.assertEqual(response.status_code, http_client.NO_CONTENT) resources = DemoResourceData.objects.filter(name="available_resource1") for resource in resources: self.assertEqual(resource.reserved, "A_User") resources = DemoResourceData.objects.filter( ~Q(name="available_resource1")) for resource in resources: self.assertNotEqual(resource.reserved, "A_User")
Example #19
Source File: release_resources.py From rotest with MIT License | 5 votes |
def post(self, request, sessions, *args, **kwargs): """Release the given resources one by one.""" try: session = sessions[request.model.token] except KeyError: raise BadRequest("Invalid token provided!") errors = {} username = get_username(request) with transaction.atomic(): for name in request.model.resources: try: resource_data = ResourceData.objects.select_for_update() \ .get(name=name) except ObjectDoesNotExist: errors[name] = (ResourceDoesNotExistError.ERROR_CODE, "Resource %r doesn't exist" % name) continue resource = get_sub_model(resource_data) try: self.release_resource(resource, username) session.resources.remove(resource) except ServerError as ex: errors[name] = (ex.ERROR_CODE, ex.get_error_content()) if len(errors) > 0: return Response({ "errors": errors, "details": "errors occurred while releasing resource" }, status=http_client.BAD_REQUEST) return Response({}, status=http_client.NO_CONTENT)
Example #20
Source File: test_test_control.py From rotest with MIT License | 5 votes |
def test_update_run_date(self): """Assert that the request has the right server response.""" response, _ = self.requester( path="tests/update_run_data", json_data={ "token": self.token, "run_data": { "run_name": "name2" } }) self.assertEqual(response.status_code, http_client.NO_CONTENT)
Example #21
Source File: update_run_data.py From rotest with MIT License | 5 votes |
def post(self, request, sessions, *args, **kwargs): """Initialize the tests run data.""" session_token = request.model.token try: session_data = sessions[session_token] except KeyError: raise BadRequest("Invalid token provided!") run_data = session_data.run_data RunData.objects.filter(pk=run_data.pk).update( **request.model.run_data) return Response({}, status=http_client.NO_CONTENT)
Example #22
Source File: test_test_control.py From rotest with MIT License | 5 votes |
def test_add_test_result(self): """Assert that the request has the right server response.""" response, _ = self.requester( path="tests/add_test_result", params={ "token": self.token, "test_id": self.test_case.identifier }, json_data={ "result": { "result_code": TestOutcome.FAILED, "info": "This test failed!" } }) self.assertEqual(response.status_code, http_client.NO_CONTENT)
Example #23
Source File: start_test_run.py From rotest with MIT License | 5 votes |
def post(self, request, sessions, *args, **kwargs): """Initialize the tests run data. Args: tests_tree (dict): contains the hierarchy of the tests in the run. run_data (dict): contains additional data about the run. """ try: run_data = RunData.objects.create(**request.model.run_data) except TypeError: raise BadRequest("Invalid run data provided!") all_tests = {} tests_tree = request.model.tests try: main_test = self._create_test_data(tests_tree, run_data, all_tests) except KeyError: raise BadRequest("Invalid tests tree provided!") run_data.main_test = main_test run_data.user_name = request.get_host() run_data.save() session = sessions[request.model.token] session.all_tests = all_tests session.run_data = run_data session.main_test = main_test return Response({}, status=http_client.NO_CONTENT)
Example #24
Source File: test_transport_http.py From suds with GNU Lesser General Public License v3.0 | 5 votes |
def test_send_transforming_HTTPError_exceptions(self, status_code, monkeypatch): """ HttpTransport send() operation should transform HTTPError urlopener exceptions with status codes other than ACCEPTED or NO_CONTENT to suds.transport.TransportError exceptions. """ # Setup. monkeypatch.delattr(locals(), "e", False) msg = object() fp = MockFP() e_original = self.create_HTTPError(msg=msg, code=status_code, fp=fp) t = suds.transport.http.HttpTransport() t.urlopener = MockURLOpenerSaboteur(open_exception=e_original) request = create_request() # Execute. e = pytest.raises(suds.transport.TransportError, t.send, request).value try: # Verify. assert len(e.args) == 1 assert e.args[0] is e_original.msg assert e.httpcode is status_code assert e.fp is fp finally: del e # explicitly break circular reference chain in Python 3
Example #25
Source File: update_resources.py From rotest with MIT License | 5 votes |
def post(self, request, sessions, *args, **kwargs): """Update the resources list for a test data. Args: test_id (number): the identifier of the test. descriptors (list): the resources the test used. """ session_token = request.model.test_details.token try: session_data = sessions[session_token] test_data = \ session_data.all_tests[request.model.test_details.test_id] except KeyError: raise BadRequest("Invalid token/test_id provided " "(Test timed out?)") test_data.resources.clear() for resource_descriptor in request.model.descriptors: resource_dict = ResourceDescriptor.decode(resource_descriptor) test_data.resources.add(resource_dict.type.objects.get( **resource_dict.properties)) test_data.save() return Response({}, status=http_client.NO_CONTENT)
Example #26
Source File: exc.py From python-egnyte with MIT License | 5 votes |
def check_json_response(self, response, *ok_statuses): """ Check if HTTP response has a correct status and then parse it as JSON, try to raise a specific EgnyteError subclass if not """ try: r = self.check_response(response, *ok_statuses) if r.status_code == http_client.NO_CONTENT: return None return r.json() except ValueError: raise JsonParseError({"http response": response.text})
Example #27
Source File: test_controller.py From tacker with Apache License 2.0 | 5 votes |
def test_delete_with_204_status(self, mock_delete_rpc, mock_vnf_by_id): vnfpkg_updates = {'operational_state': 'DISABLED'} mock_vnf_by_id.return_value = fakes.return_vnfpkg_obj( vnf_package_updates=vnfpkg_updates) req = fake_request.HTTPRequest.blank( '/vnf_packages/%s' % constants.UUID) req.headers['Content-Type'] = 'application/json' req.method = 'DELETE' resp = req.get_response(self.app) self.assertEqual(http_client.NO_CONTENT, resp.status_code)
Example #28
Source File: test__helpers.py From google-resumable-media-python with Apache License 2.0 | 5 votes |
def test_failure(self): status_codes = (http_client.CREATED, http_client.NO_CONTENT) response = _make_response(http_client.OK) with pytest.raises(common.InvalidResponse) as exc_info: _helpers.require_status_code(response, status_codes, self._get_status_code) error = exc_info.value assert error.response is response assert len(error.args) == 5 assert error.args[1] == response.status_code assert error.args[3:] == status_codes
Example #29
Source File: share_group_types.py From manila with Apache License 2.0 | 5 votes |
def _delete(self, req, id): """Deletes an existing group type.""" context = req.environ['manila.context'] try: share_group_type = share_group_types.get(context, id) share_group_types.destroy(context, share_group_type['id']) except exception.ShareGroupTypeInUse: msg = _('Target share group type with id %s is still in use.') raise webob.exc.HTTPBadRequest(explanation=msg % id) except exception.NotFound: raise webob.exc.HTTPNotFound() return webob.Response(status_int=http_client.NO_CONTENT)
Example #30
Source File: messages.py From manila with Apache License 2.0 | 5 votes |
def delete(self, req, id): """Delete a message.""" context = req.environ['manila.context'] try: message = self.message_api.get(context, id) self.message_api.delete(context, message) except exception.MessageNotFound as error: raise exc.HTTPNotFound(explanation=error.msg) return webob.Response(status_int=http_client.NO_CONTENT)