Python six.moves.http_client.ACCEPTED Examples
The following are 30
code examples of six.moves.http_client.ACCEPTED().
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: share_types.py From manila with Apache License 2.0 | 6 votes |
def _delete(self, req, id): """Deletes an existing share type.""" context = req.environ['manila.context'] try: share_type = share_types.get_share_type(context, id) share_types.destroy(context, share_type['id']) self._notify_share_type_info( context, 'share_type.delete', share_type) except exception.ShareTypeInUse as err: notifier_err = dict(id=id, error_message=six.text_type(err)) self._notify_share_type_error(context, 'share_type.delete', notifier_err) msg = 'Target share type is still in use.' raise webob.exc.HTTPBadRequest(explanation=msg) except exception.NotFound as err: notifier_err = dict(id=id, error_message=six.text_type(err)) self._notify_share_type_error(context, 'share_type.delete', notifier_err) raise webob.exc.HTTPNotFound() return webob.Response(status_int=http_client.ACCEPTED)
Example #2
Source File: test_notifications.py From masakari with Apache License 2.0 | 6 votes |
def test_create_success_with_201_response_code( self, mock_client, mock_create): body = { "notification": { "hostname": "fake_host", "payload": { "instance_uuid": uuidsentinel.instance_uuid, "vir_domain_event": "STOPPED_FAILED", "event": "LIFECYCLE" }, "type": "VM", "generated_time": NOW } } fake_req = self.req fake_req.headers['Content-Type'] = 'application/json' fake_req.method = 'POST' fake_req.body = jsonutils.dump_as_bytes(body) resp = fake_req.get_response(self.app) self.assertEqual(http.ACCEPTED, resp.status_code)
Example #3
Source File: test_wsgi.py From masakari with Apache License 2.0 | 6 votes |
def test_resource_headers_py2_are_utf8(self): resp = webob.Response(status_int=http.ACCEPTED) resp.headers['x-header1'] = 1 resp.headers['x-header2'] = u'header2' resp.headers['x-header3'] = u'header3' class Controller(object): def index(self, req): return resp req = webob.Request.blank('/tests') app = fakes.TestRouter(Controller()) response = req.get_response(app) if six.PY2: for val in response.headers.values(): # All headers must be utf8 self.assertThat(val, matchers.EncodedByUTF8()) self.assertEqual(b'1', response.headers['x-header1']) self.assertEqual(b'header2', response.headers['x-header2']) self.assertEqual(b'header3', response.headers['x-header3']) else: self.assertEqual('1', response.headers['x-header1']) self.assertEqual(u'header2', response.headers['x-header2']) self.assertEqual(u'header3', response.headers['x-header3'])
Example #4
Source File: quota_sets.py From manila with Apache License 2.0 | 6 votes |
def _delete(self, req, id): context = req.environ['manila.context'] params = parse.parse_qs(req.environ.get('QUERY_STRING', '')) user_id = params.get('user_id', [None])[0] share_type = params.get('share_type', [None])[0] self._validate_user_id_and_share_type_args(user_id, share_type) try: db.authorize_project_context(context, id) if user_id: QUOTAS.destroy_all_by_project_and_user(context, id, user_id) elif share_type: share_type_id = self._get_share_type_id(context, share_type) QUOTAS.destroy_all_by_project_and_share_type( context, id, share_type_id) else: QUOTAS.destroy_all_by_project(context, id) return webob.Response(status_int=http_client.ACCEPTED) except exception.NotAuthorized: raise webob.exc.HTTPForbidden()
Example #5
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_upload_vnf_package_content(self, mock_vnf_pack_save, mock_vnf_by_id, mock_upload_vnf_package_content, mock_glance_store): updates = {'onboarding_state': 'CREATED', 'operational_state': 'DISABLED'} vnf_package_dict = fakes.fake_vnf_package(updates) vnf_package_obj = objects.VnfPackage(**vnf_package_dict) mock_vnf_by_id.return_value = vnf_package_obj mock_vnf_pack_save.return_value = vnf_package_obj mock_glance_store.return_value = 'location', 0, 'checksum',\ 'multihash', 'loc_meta' req = fake_request.HTTPRequest.blank( '/vnf_packages/%s/package_content' % constants.UUID) req.headers['Content-Type'] = 'application/zip' req.method = 'PUT' req.body = jsonutils.dump_as_bytes(mock.mock_open()) resp = req.get_response(self.app) mock_glance_store.assert_called() self.assertEqual(http_client.ACCEPTED, resp.status_code)
Example #6
Source File: share_replicas.py From manila with Apache License 2.0 | 6 votes |
def delete(self, req, id): """Delete a replica.""" context = req.environ['manila.context'] try: replica = db.share_replica_get(context, id) except exception.ShareReplicaNotFound: msg = _("No replica exists with ID %s.") raise exc.HTTPNotFound(explanation=msg % id) try: self.share_api.delete_share_replica(context, replica) except exception.ReplicationException as e: raise exc.HTTPBadRequest(explanation=six.text_type(e)) return webob.Response(status_int=http_client.ACCEPTED)
Example #7
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_upload_vnf_package_from_uri(self, mock_vnf_pack_save, mock_vnf_by_id, mock_upload_vnf_package_from_uri, mock_url_open): body = {"addressInformation": "http://localhost/test_data.zip"} updates = {'onboarding_state': 'CREATED', 'operational_state': 'DISABLED'} vnf_package_dict = fakes.fake_vnf_package(updates) vnf_package_obj = objects.VnfPackage(**vnf_package_dict) mock_vnf_by_id.return_value = vnf_package_obj mock_vnf_pack_save.return_value = vnf_package_obj req = fake_request.HTTPRequest.blank( '/vnf_packages/%s/package_content/upload_from_uri' % constants.UUID) req.headers['Content-Type'] = 'application/json' req.method = 'POST' req.body = jsonutils.dump_as_bytes(body) resp = req.get_response(self.app) self.assertEqual(http_client.ACCEPTED, resp.status_code)
Example #8
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_instantiate_with_deployment_flavour( self, mock_instantiate, mock_vnf_package_get_by_id, mock_vnf_package_vnfd_get_by_id, mock_save, mock_vnf_instance_get_by_id, mock_get_vim): mock_vnf_instance_get_by_id.return_value =\ fakes.return_vnf_instance_model() mock_vnf_package_vnfd_get_by_id.return_value = \ fakes.return_vnf_package_vnfd() mock_vnf_package_get_by_id.return_value = \ fakes.return_vnf_package_with_deployment_flavour() body = {"flavourId": "simple"} req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/instantiate' % uuidsentinel.vnf_instance_id) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' # Call Instantiate API resp = req.get_response(self.app) self.assertEqual(http_client.ACCEPTED, resp.status_code) mock_instantiate.assert_called_once()
Example #9
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_instantiate_with_instantiation_level( self, mock_instantiate, mock_vnf_package_get_by_id, mock_vnf_package_vnfd_get_by_id, mock_save, mock_vnf_instance_get_by_id, mock_get_vim): mock_vnf_instance_get_by_id.return_value =\ fakes.return_vnf_instance_model() mock_vnf_package_vnfd_get_by_id.return_value = \ fakes.return_vnf_package_vnfd() mock_vnf_package_get_by_id.return_value = \ fakes.return_vnf_package_with_deployment_flavour() body = {"flavourId": "simple", "instantiationLevelId": "instantiation_level_1"} req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/instantiate' % uuidsentinel.vnf_instance_id) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' # Call Instantiate API resp = req.get_response(self.app) self.assertEqual(http_client.ACCEPTED, resp.status_code) mock_instantiate.assert_called_once()
Example #10
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_heal(self, body, mock_rpc_heal, mock_save, mock_vnf_by_id): vnf_instance_obj = fakes.return_vnf_instance( fields.VnfInstanceState.INSTANTIATED) mock_vnf_by_id.return_value = vnf_instance_obj req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/heal' % uuidsentinel.vnf_instance_id) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' resp = req.get_response(self.app) self.assertEqual(http_client.ACCEPTED, resp.status_code) mock_rpc_heal.assert_called_once()
Example #11
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 #12
Source File: share_servers.py From manila with Apache License 2.0 | 6 votes |
def delete(self, req, id): """Delete specified share server.""" context = req.environ['manila.context'] try: share_server = db_api.share_server_get(context, id) except exception.ShareServerNotFound as e: raise exc.HTTPNotFound(explanation=e.msg) allowed_statuses = [constants.STATUS_ERROR, constants.STATUS_ACTIVE] if share_server['status'] not in allowed_statuses: data = { 'status': share_server['status'], 'allowed_statuses': allowed_statuses, } msg = _("Share server's actual status is %(status)s, allowed " "statuses for deletion are %(allowed_statuses)s.") % (data) raise exc.HTTPForbidden(explanation=msg) LOG.debug("Deleting share server with id: %s.", id) try: self.share_api.delete_share_server(context, share_server) except exception.ShareServerInUse as e: raise exc.HTTPConflict(explanation=e.msg) return webob.Response(status_int=http_client.ACCEPTED)
Example #13
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 #14
Source File: share_types_extra_specs.py From manila with Apache License 2.0 | 6 votes |
def _delete(self, req, type_id, id): """Deletes an existing extra spec.""" context = req.environ['manila.context'] if id in share_types.get_required_extra_specs(): msg = _("Extra spec '%s' can't be deleted.") % id raise webob.exc.HTTPForbidden(explanation=msg) try: db.share_type_extra_specs_delete(context, type_id, id) except exception.ShareTypeExtraSpecsNotFound as error: raise webob.exc.HTTPNotFound(explanation=error.msg) notifier_info = dict(type_id=type_id, id=id) notifier = rpc.get_notifier('shareTypeExtraSpecs') notifier.info(context, 'share_type_extra_specs.delete', notifier_info) return webob.Response(status_int=http_client.ACCEPTED)
Example #15
Source File: shares.py From manila with Apache License 2.0 | 6 votes |
def _deny_access(self, req, id, body): """Remove share access rule.""" context = req.environ['manila.context'] access_id = body.get( 'deny_access', body.get('os-deny_access'))['access_id'] try: access = self.share_api.access_get(context, access_id) if access.share_id != id: raise exception.NotFound() share = self.share_api.get(context, id) except exception.NotFound as error: raise webob.exc.HTTPNotFound(explanation=six.text_type(error)) self.share_api.deny_access(context, share, access) return webob.Response(status_int=http_client.ACCEPTED)
Example #16
Source File: test_controller.py From tacker with Apache License 2.0 | 5 votes |
def test_instantiate_with_vim_connection( self, mock_instantiate, mock_vnf_package_get_by_id, mock_vnf_package_vnfd_get_by_id, mock_save, mock_vnf_instance_get_by_id, mock_get_vim): mock_vnf_instance_get_by_id.return_value =\ fakes.return_vnf_instance_model() mock_vnf_package_vnfd_get_by_id.return_value = \ fakes.return_vnf_package_vnfd() mock_vnf_package_get_by_id.return_value = \ fakes.return_vnf_package_with_deployment_flavour() body = {"flavourId": "simple", "vimConnectionInfo": [ {"id": uuidsentinel.vim_connection_id, "vimId": uuidsentinel.vim_id, "vimType": 'openstack'} ]} req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/instantiate' % uuidsentinel.vnf_instance_id) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' # Call Instantiate API resp = req.get_response(self.app) self.assertEqual(http_client.ACCEPTED, resp.status_code) mock_instantiate.assert_called_once()
Example #17
Source File: test_reply_handling.py From suds with GNU Lesser General Public License v3.0 | 5 votes |
def test_ACCEPTED_and_NO_CONTENT_status_reported_as_None_with_faults(): client = testutils.client_from_wsdl(_wsdl__simple_f, faults=True) def f(reply, status): inject = {"reply": suds.byte_str(reply), "status": status} return client.service.f(__inject=inject) assert f("", None) is None pytest.raises(Exception, f, "", http_client.INTERNAL_SERVER_ERROR) assert f("", http_client.ACCEPTED) is None assert f("", http_client.NO_CONTENT) is None assert f("bla-bla", http_client.ACCEPTED) is None assert f("bla-bla", http_client.NO_CONTENT) is None
Example #18
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 #19
Source File: test_transport_http.py From suds with GNU Lesser General Public License v3.0 | 5 votes |
def test_send_transforming_HTTPError_exceptions__accepted_no_content(self, status_code): """ HttpTransport send() operation should return None when their underlying urlopen operation raises a HTTPError exception with status code ACCEPTED or NO_CONTENT. """ e_original = self.create_HTTPError(code=status_code) t = suds.transport.http.HttpTransport() t.urlopener = MockURLOpenerSaboteur(open_exception=e_original) assert t.send(create_request()) is None
Example #20
Source File: test_worker_with_transform.py From sagemaker-containers with Apache License 2.0 | 5 votes |
def test_worker_with_custom_ping(): transformer = Transformer() def custom_ping(): return "ping", http_client.ACCEPTED with _worker.Worker( transform_fn=transformer.transform, healthcheck_fn=custom_ping, module_name="custom_ping" ).test_client() as client: response = client.get("/ping") assert response.status_code == http_client.ACCEPTED assert response.get_data(as_text=True) == "ping"
Example #21
Source File: test_wsgi.py From masakari with Apache License 2.0 | 5 votes |
def test_override_modified_code(self): robj = wsgi.ResponseObject({}, code=http.NOT_FOUND) robj._default_code = http.ACCEPTED self.assertEqual(robj.code, http.NOT_FOUND)
Example #22
Source File: test_wsgi.py From masakari with Apache License 2.0 | 5 votes |
def test_modified_code(self): robj = wsgi.ResponseObject({}) robj._default_code = http.ACCEPTED self.assertEqual(robj.code, http.ACCEPTED)
Example #23
Source File: shares.py From manila with Apache License 2.0 | 5 votes |
def delete(self, req, id): """Delete a share.""" context = req.environ['manila.context'] LOG.info("Delete share with id: %s", id, context=context) try: share = self.share_api.get(context, id) # NOTE(ameade): If the share is in a share group, we require its # id be specified as a param. sg_id_key = 'share_group_id' if share.get(sg_id_key): share_group_id = req.params.get(sg_id_key) if not share_group_id: msg = _("Must provide '%s' as a request " "parameter when deleting a share in a share " "group.") % sg_id_key raise exc.HTTPBadRequest(explanation=msg) elif share_group_id != share.get(sg_id_key): msg = _("The specified '%s' does not match " "the share group id of the share.") % sg_id_key raise exc.HTTPBadRequest(explanation=msg) self.share_api.delete(context, share) except exception.NotFound: raise exc.HTTPNotFound() except exception.InvalidShare as e: raise exc.HTTPForbidden(explanation=six.text_type(e)) except exception.Conflict as e: raise exc.HTTPConflict(explanation=six.text_type(e)) return webob.Response(status_int=http_client.ACCEPTED)
Example #24
Source File: rest_conf_switch.py From ryu with Apache License 2.0 | 5 votes |
def delete_switch(self, _req, dpid, **_kwargs): def _delete_switch(dpid): self.conf_switch.del_dpid(dpid) return None def _ret(_ret): return Response(status=http_client.ACCEPTED) return self._do_switch(dpid, _delete_switch, _ret)
Example #25
Source File: share_servers.py From manila with Apache License 2.0 | 5 votes |
def _unmanage(self, req, id, body=None): context = req.environ['manila.context'] LOG.debug("Unmanage Share Server with id: %s", id) # force's default value is False # force will be True if body is {'unmanage': {'force': True}} force = (body.get('unmanage') or {}).get('force', False) or False try: share_server = db_api.share_server_get( context, id) except exception.ShareServerNotFound as e: raise exc.HTTPNotFound(explanation=e.msg) allowed_statuses = [constants.STATUS_ERROR, constants.STATUS_ACTIVE, constants.STATUS_MANAGE_ERROR, constants.STATUS_UNMANAGE_ERROR] if share_server['status'] not in allowed_statuses: data = { 'status': share_server['status'], 'allowed_statuses': ', '.join(allowed_statuses), } msg = _("Share server's actual status is %(status)s, allowed " "statuses for unmanaging are " "%(allowed_statuses)s.") % data raise exc.HTTPBadRequest(explanation=msg) try: self.share_api.unmanage_share_server( context, share_server, force=force) except (exception.ShareServerInUse, exception.PolicyNotAuthorized) as e: raise exc.HTTPBadRequest(explanation=e.msg) return webob.Response(status_int=http_client.ACCEPTED)
Example #26
Source File: share_group_snapshots.py From manila with Apache License 2.0 | 5 votes |
def _delete_group_snapshot(self, req, id): """Delete a share group snapshot.""" context = req.environ['manila.context'] LOG.info("Delete share group snapshot with id: %s", id, context=context) sg_snapshot = self._get_share_group_snapshot(context, id) try: self.share_group_api.delete_share_group_snapshot( context, sg_snapshot) except exception.InvalidShareGroupSnapshot as e: raise exc.HTTPConflict(explanation=six.text_type(e)) return webob.Response(status_int=http_client.ACCEPTED)
Example #27
Source File: share_snapshots.py From manila with Apache License 2.0 | 5 votes |
def _unmanage(self, req, id, body=None, allow_dhss_true=False): """Unmanage a share snapshot.""" context = req.environ['manila.context'] LOG.info("Unmanage share snapshot with id: %s.", id) try: snapshot = self.share_api.get_snapshot(context, id) share = self.share_api.get(context, snapshot['share_id']) if not allow_dhss_true and share.get('share_server_id'): msg = _("Operation 'unmanage_snapshot' is not supported for " "snapshots of shares that are created with share" " servers (created with share-networks).") raise exc.HTTPForbidden(explanation=msg) elif share.get('has_replicas'): msg = _("Share %s has replicas. Snapshots of this share " "cannot currently be unmanaged until all replicas " "are removed.") % share['id'] raise exc.HTTPConflict(explanation=msg) elif snapshot['status'] in constants.TRANSITIONAL_STATUSES: msg = _("Snapshot with transitional state cannot be " "unmanaged. Snapshot '%(s_id)s' is in '%(state)s' " "state.") % {'state': snapshot['status'], 's_id': snapshot['id']} raise exc.HTTPForbidden(explanation=msg) self.share_api.unmanage_snapshot(context, snapshot, share['host']) except (exception.ShareSnapshotNotFound, exception.ShareNotFound) as e: raise exc.HTTPNotFound(explanation=e) return webob.Response(status_int=http_client.ACCEPTED)
Example #28
Source File: share_groups.py From manila with Apache License 2.0 | 5 votes |
def _delete_share_group(self, req, id): """Delete a share group.""" context = req.environ['manila.context'] LOG.info("Delete share group with id: %s", id, context=context) share_group = self._get_share_group(context, id) try: self.share_group_api.delete(context, share_group) except exception.InvalidShareGroup as e: raise exc.HTTPConflict(explanation=six.text_type(e)) return webob.Response(status_int=http_client.ACCEPTED)
Example #29
Source File: shares.py From manila with Apache License 2.0 | 5 votes |
def migration_complete(self, req, id, body): """Invokes 2nd phase of share migration.""" context = req.environ['manila.context'] try: share = self.share_api.get(context, id) except exception.NotFound: msg = _("Share %s not found.") % id raise exc.HTTPNotFound(explanation=msg) self.share_api.migration_complete(context, share) return webob.Response(status_int=http_client.ACCEPTED)
Example #30
Source File: share_types.py From manila with Apache License 2.0 | 5 votes |
def _remove_project_access(self, req, id, body): context = req.environ['manila.context'] self._check_body(body, 'removeProjectAccess') project = body['removeProjectAccess']['project'] self._verify_if_non_public_share_type(context, id) try: share_types.remove_share_type_access(context, id, project) except exception.ShareTypeAccessNotFound as err: raise webob.exc.HTTPNotFound(explanation=six.text_type(err)) return webob.Response(status_int=http_client.ACCEPTED)