Python http.HTTPStatus.NO_CONTENT Examples
The following are 30
code examples of http.HTTPStatus.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
http.HTTPStatus
, or try the search function
.
Example #1
Source File: test_service_instances.py From cf-python-client with Apache License 2.0 | 6 votes |
def test_delete_purge(self): self.client.delete.return_value = self.mock_response( '/v2/service_instances/instance_id', HTTPStatus.NO_CONTENT, None) self.client.v2.service_instances.remove('instance_id', accepts_incomplete=True, purge=True) self.client.delete.assert_called_with(self.client.delete.return_value.url, params=dict(accepts_incomplete='true', purge="true")) self.client.delete.return_value = self.mock_response( '/v2/service_instances/instance_id', HTTPStatus.NO_CONTENT, None) self.client.v2.service_instances.remove('instance_id', purge="true") self.client.delete.assert_called_with(self.client.delete.return_value.url, params=dict(purge="true")) self.client.delete.return_value = self.mock_response( '/v2/service_instances/instance_id', HTTPStatus.NO_CONTENT, None) self.client.v2.service_instances.remove('instance_id', purge="true") self.client.delete.assert_called_with(self.client.delete.return_value.url, params=dict(purge="true"))
Example #2
Source File: task.py From zimfarm with GNU General Public License v3.0 | 6 votes |
def post(self, task_id: str, token: AccessToken.Payload): task = Tasks().find_one( {"status": {"$in": TaskStatus.incomplete()}, "_id": task_id}, {"_id": 1} ) if task is None: raise TaskNotFound() task_event_handler( task["_id"], TaskStatus.cancel_requested, {"canceled_by": token.username} ) # broadcast cancel-request to worker BROADCASTER.broadcast_cancel_task(task_id) return Response(status=HTTPStatus.NO_CONTENT)
Example #3
Source File: device_email.py From selene-backend with GNU Affero General Public License v3.0 | 6 votes |
def put(self, device_id): self._authenticate(device_id) payload = json.loads(self.request.data) send_email = SendEmail(payload) send_email.validate() account = AccountRepository(self.db).get_account_by_device_id(device_id) if account: message = EmailMessage() message['Subject'] = str(send_email.title) message['From'] = str(send_email.sender) message.set_content(str(send_email.body)) message['To'] = account.email_address self._send_email(message) response = '', HTTPStatus.OK else: response = '', HTTPStatus.NO_CONTENT return response
Example #4
Source File: test_drivers_google.py From cloudstorage with MIT License | 6 votes |
def test_container_generate_upload_url(container, binary_stream): form_post = container.generate_upload_url( blob_name="prefix_", **settings.BINARY_OPTIONS ) assert "url" in form_post and "fields" in form_post assert uri_validator(form_post["url"]) url = form_post["url"] fields = form_post["fields"] multipart_form_data = { "file": (settings.BINARY_FORM_FILENAME, binary_stream, "image/png"), } response = requests.post(url, data=fields, files=multipart_form_data) assert response.status_code == HTTPStatus.NO_CONTENT, response.text blob = container.get_blob("prefix_" + settings.BINARY_FORM_FILENAME) assert blob.meta_data == settings.BINARY_OPTIONS["meta_data"] assert blob.content_type == settings.BINARY_OPTIONS["content_type"] assert blob.content_disposition == settings.BINARY_OPTIONS["content_disposition"] assert blob.cache_control == settings.BINARY_OPTIONS["cache_control"]
Example #5
Source File: worker.py From zimfarm with GNU General Public License v3.0 | 6 votes |
def put(self, name: str, *args, **kwargs): try: request_json = WorkerCheckInSchema().load(request.get_json()) except ValidationError as e: raise InvalidRequestJSON(e.messages) document = { "name": name, "username": request_json["username"], "selfish": request_json["selfish"], "resources": { "cpu": request_json["cpu"], "memory": request_json["memory"], "disk": request_json["disk"], }, "offliners": request_json["offliners"], "platforms": request_json.get("platforms", {}), "last_seen": getnow(), } Workers().replace_one({"name": name}, document, upsert=True) BROADCASTER.broadcast_worker_checkin(document) return Response(status=HTTPStatus.NO_CONTENT)
Example #6
Source File: user.py From zimfarm with GNU General Public License v3.0 | 6 votes |
def patch(self, token: AccessToken.Payload, username: str): # find user based on username query = {"username": username} if Users().count_documents(query) != 1: raise errors.NotFound() try: request_json = UserUpdateSchema().load(request.get_json()) except ValidationError as e: raise errors.BadRequest(e.messages) update = {} if "email" in request_json: update["email"] = request_json["email"] if "role" in request_json: update["scope"] = ROLES.get(request_json["role"]) Users().update_one(query, {"$set": update}) return Response(status=HTTPStatus.NO_CONTENT)
Example #7
Source File: keys.py From zimfarm with GNU General Public License v3.0 | 6 votes |
def delete(self, username: str, fingerprint: str, token: AccessToken.Payload): # if user in url is not user in token, check user permission if username != token.username: if not token.get_permission("users", "ssh_keys"): raise errors.NotEnoughPrivilege() # database result = Users().update_one( {"username": username}, {"$pull": {"ssh_keys": {"fingerprint": fingerprint}}}, ) if result.modified_count > 0: Response(status=HTTPStatus.NO_CONTENT) else: raise errors.NotFound() return Response(status=HTTPStatus.NO_CONTENT)
Example #8
Source File: task.py From zimfarm with GNU General Public License v3.0 | 6 votes |
def patch(self, task_id: str, token: AccessToken.Payload): task = Tasks().find_one({"_id": task_id}, {"_id": 1}) if task is None: raise TaskNotFound() try: request_json = TasKUpdateSchema().load(request.get_json()) # empty dict passes the validator but troubles mongo if not request.get_json(): raise ValidationError("Update can't be empty") except ValidationError as e: raise InvalidRequestJSON(e.messages) task_event_handler(task["_id"], request_json["event"], request_json["payload"]) BROADCASTER.broadcast_updated_task( task_id, request_json["event"], request_json["payload"] ) return Response(status=HTTPStatus.NO_CONTENT)
Example #9
Source File: test_drivers_minio.py From cloudstorage with MIT License | 6 votes |
def test_container_generate_upload_url(container, binary_stream, temp_file): form_post = container.generate_upload_url( settings.BINARY_FORM_FILENAME, **settings.BINARY_OPTIONS ) assert "url" in form_post and "fields" in form_post assert uri_validator(form_post["url"]) url = form_post["url"] fields = form_post["fields"] multipart_form_data = { "file": (settings.BINARY_FORM_FILENAME, binary_stream, "image/png"), } response = requests.post(url, data=fields, files=multipart_form_data) assert response.status_code == HTTPStatus.NO_CONTENT, response.text blob = container.get_blob(settings.BINARY_FORM_FILENAME) assert blob.meta_data == settings.BINARY_OPTIONS["meta_data"] assert blob.content_type == settings.BINARY_OPTIONS["content_type"] # assert blob.content_disposition == settings.BINARY_OPTIONS['content_disposition'] # assert blob.cache_control == settings.BINARY_OPTIONS['cache_control']
Example #10
Source File: device_skill_settings.py From selene-backend with GNU Affero General Public License v3.0 | 6 votes |
def _build_response(self, device_id, response_data): if response_data is None: response = Response( '', status=HTTPStatus.NO_CONTENT, content_type='application/json' ) else: response = Response( json.dumps(response_data), status=HTTPStatus.OK, content_type='application/json' ) self._add_etag(DEVICE_SKILL_ETAG_KEY.format(device_id=device_id)) return response
Example #11
Source File: send_order.py From Python-Programming-Blueprints with MIT License | 6 votes |
def send_order(data): token = '' headers = { 'Authorization': f'Token {token}', 'Content-type': 'application/json' } response = requests.post( 'http://127.0.0.1:8000/api/order/add/', headers=headers, data=json.dumps(data)) if response.status_code == HTTPStatus.NO_CONTENT: print('Ops! Something went wrong!') sys.exit(1) print('Request was successfull')
Example #12
Source File: app.py From waspy with Apache License 2.0 | 6 votes |
def response_wrapper_factory(app, handler): @wraps(handler) async def wrap_response_middleware(request): response = await handler(request) if not isinstance(response, Response): if isinstance(response, tuple): body = response[0] status = response[1] response = Response(status=status, body=body) elif isinstance(response, dict) or isinstance(response, str): response = Response(body=response) elif response is None: response = Response(status=HTTPStatus.NO_CONTENT) else: raise ValueError('Request handler returned an invalid type.' ' Return types should be one of ' '[Response, dict, str, None, (dict, int)]') return response return wrap_response_middleware
Example #13
Source File: test_service_instances.py From cf-python-client with Apache License 2.0 | 6 votes |
def test_delete_accepts_incomplete(self): self.client.delete.return_value = self.mock_response( '/v2/service_instances/instance_id', HTTPStatus.NO_CONTENT, None) self.client.v2.service_instances.remove('instance_id', accepts_incomplete=True) self.client.delete.assert_called_with(self.client.delete.return_value.url, params=dict(accepts_incomplete="true")) self.client.delete.return_value = self.mock_response( '/v2/service_instances/instance_id', HTTPStatus.NO_CONTENT, None) self.client.v2.service_instances.remove('instance_id', accepts_incomplete="true") self.client.delete.assert_called_with(self.client.delete.return_value.url, params=dict(accepts_incomplete="true"))
Example #14
Source File: security_controller.py From flask-unchained with MIT License | 6 votes |
def forgot_password(self): """ View function to request a password recovery email with a reset token. Supports html and json requests. """ form = self._get_form('SECURITY_FORGOT_PASSWORD_FORM') if form.validate_on_submit(): self.security_service.send_reset_password_instructions(form.user) self.flash(_('flask_unchained.bundles.security:flash.password_reset_request', email=form.user.email), category='info') if request.is_json: return '', HTTPStatus.NO_CONTENT return self.redirect('forgot_password') elif form.errors and request.is_json: return self.errors(form.errors) return self.render('forgot_password', forgot_password_form=form, **self.security.run_ctx_processor('forgot_password'))
Example #15
Source File: security_controller.py From flask-unchained with MIT License | 6 votes |
def send_confirmation_email(self): """ View function which sends confirmation token and instructions to a user. """ form = self._get_form('SECURITY_SEND_CONFIRMATION_FORM') if form.validate_on_submit(): self.security_service.send_email_confirmation_instructions(form.user) self.flash(_('flask_unchained.bundles.security:flash.confirmation_request', email=form.user.email), category='info') if request.is_json: return '', HTTPStatus.NO_CONTENT return self.redirect('send_confirmation_email') elif form.errors and request.is_json: return self.errors(form.errors) return self.render('send_confirmation_email', send_confirmation_form=form, **self.security.run_ctx_processor('send_confirmation_email'))
Example #16
Source File: security_controller.py From flask-unchained with MIT License | 6 votes |
def register(self): """ View function to register user. Supports html and json requests. """ form = self._get_form('SECURITY_REGISTER_FORM') if form.validate_on_submit(): user = self.security_service.user_manager.create(**form.to_dict()) self.security_service.register_user(user) if request.is_json: return '', HTTPStatus.NO_CONTENT return self.redirect('SECURITY_POST_REGISTER_REDIRECT_ENDPOINT') elif form.errors and request.is_json: return self.errors(form.errors) return self.render('register', register_user_form=form, **self.security.run_ctx_processor('register'))
Example #17
Source File: koji_builds.py From packit-service with MIT License | 6 votes |
def get(self, id): """A specific koji build details. From koji_build hash, filled by worker.""" builds_list = KojiBuildModel.get_all_by_build_id(str(id)) if bool(builds_list.first()): build = builds_list[0] build_dict = build.api_structure.copy() build_dict["srpm_logs"] = ( build.srpm_build.logs if build.srpm_build else None ) build = make_response(dumps(build_dict)) build.headers["Content-Type"] = "application/json" build.headers["Access-Control-Allow-Origin"] = "*" return build if build else ("", HTTPStatus.NO_CONTENT) else: return "", HTTPStatus.NO_CONTENT
Example #18
Source File: test_httpservers.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_send_error(self): allow_transfer_encoding_codes = (HTTPStatus.NOT_MODIFIED, HTTPStatus.RESET_CONTENT) for code in (HTTPStatus.NO_CONTENT, HTTPStatus.NOT_MODIFIED, HTTPStatus.PROCESSING, HTTPStatus.RESET_CONTENT, HTTPStatus.SWITCHING_PROTOCOLS): self.con.request('SEND_ERROR', '/{}'.format(code)) res = self.con.getresponse() self.assertEqual(code, res.status) self.assertEqual(None, res.getheader('Content-Length')) self.assertEqual(None, res.getheader('Content-Type')) if code not in allow_transfer_encoding_codes: self.assertEqual(None, res.getheader('Transfer-Encoding')) data = res.read() self.assertEqual(b'', data)
Example #19
Source File: send_order.py From Python-Programming-Blueprints with MIT License | 6 votes |
def send_order(data): token = '8d19ddce090211fffe22af6c06cdfd06ecb94f4e' headers = { 'Authorization': f'Token {token}', 'Content-type': 'application/json' } response = requests.post( 'http://127.0.0.1:8000/api/order/add/', headers=headers, data=json.dumps(data)) if response.status_code == HTTPStatus.NO_CONTENT: print('Ops! Something went wrong!') sys.exit(1) print('Request was successfull')
Example #20
Source File: device.py From selene-backend with GNU Affero General Public License v3.0 | 6 votes |
def get(self, device_id): self._authenticate(device_id) self._validate_etag(device_etag_key(device_id)) device = DeviceRepository(self.db).get_device_by_id(device_id) if device is not None: response_data = dict( uuid=device.id, name=device.name, description=device.placement, coreVersion=device.core_version, enclosureVersion=device.enclosure_version, platform=device.platform, user=dict(uuid=device.account_id) ) response = response_data, HTTPStatus.OK self._add_etag(device_etag_key(device_id)) else: response = '', HTTPStatus.NO_CONTENT return response
Example #21
Source File: test_apps.py From cf-python-client with Apache License 2.0 | 5 votes |
def test_main_restart_app_instance(self): with patch('cloudfoundry_client.main.main.build_client_from_configuration', new=lambda: self.client): self.client.delete.return_value = self.mock_response( '/v2/apps/906775ea-622e-4bc7-af5d-9aab3b652f81/instances/666', HTTPStatus.NO_CONTENT, None) main.main() self.client.delete.assert_called_with(self.client.delete.return_value.url)
Example #22
Source File: test_domains.py From cf-python-client with Apache License 2.0 | 5 votes |
def test_remove(self): self.client.delete.return_value = self.mock_response( '/v3/domains/domain_id', HTTPStatus.NO_CONTENT, None) self.client.v3.domains.remove('domain_id') self.client.delete.assert_called_with(self.client.delete.return_value.url)
Example #23
Source File: test_apps.py From cf-python-client with Apache License 2.0 | 5 votes |
def test_remove_route(self): self.client.delete.return_value = self.mock_response('/v2/apps/app_id/routes/route_id', HTTPStatus.NO_CONTENT, None) self.client.v2.apps.remove_route('app_id', 'route_id') self.client.delete.assert_called_with(self.client.delete.return_value.url)
Example #24
Source File: __init__.py From zimfarm with GNU General Public License v3.0 | 5 votes |
def test(token: AccessToken.Payload): return Response(status=HTTPStatus.NO_CONTENT)
Example #25
Source File: validate.py From zimfarm with GNU General Public License v3.0 | 5 votes |
def ssh_key(): """ Validate ssh public keys exists and matches with username """ # validate request json class KeySchema(Schema): username = fields.String(required=True, validate=validate.Length(min=1)) key = fields.String(required=True, validate=validate.Length(min=1)) try: request_json = KeySchema().load(request.get_json()) except ValidationError as e: raise errors.InvalidRequestJSON(e.messages) # compute fingerprint try: key = request_json["key"] rsa_key = paramiko.RSAKey(data=base64.b64decode(key)) fingerprint = binascii.hexlify(rsa_key.get_fingerprint()).decode() except (binascii.Error, paramiko.SSHException): raise errors.BadRequest("Invalid RSA key") # database username = request_json["username"] user = Users().update_one( { "username": username, "ssh_keys": {"$elemMatch": {"fingerprint": fingerprint}}, }, {"$set": {"ssh_keys.$.last_used": datetime.now()}}, ) if user.matched_count == 0: raise errors.Unauthorized() return Response(status=HTTPStatus.NO_CONTENT)
Example #26
Source File: test_apps.py From cf-python-client with Apache License 2.0 | 5 votes |
def test_remove(self): self.client.delete.return_value = self.mock_response( '/v2/apps/app_id', HTTPStatus.NO_CONTENT, None) self.client.v2.apps.remove('app_id') self.client.delete.assert_called_with(self.client.delete.return_value.url)
Example #27
Source File: test_apps.py From cf-python-client with Apache License 2.0 | 5 votes |
def test_restart_instance(self): self.client.delete.return_value = self.mock_response( '/v2/apps/app_id/instances/666', HTTPStatus.NO_CONTENT, None) self.client.v2.apps.restart_instance('app_id', 666) self.client.delete.assert_called_with(self.client.delete.return_value.url)
Example #28
Source File: _cors.py From waspy with Apache License 2.0 | 5 votes |
def options_handler(self, request): return Response(status=HTTPStatus.NO_CONTENT)
Example #29
Source File: test_spaces.py From cf-python-client with Apache License 2.0 | 5 votes |
def test_remove(self): self.client.delete.return_value = self.mock_response( '/v3/spaces/space_id', HTTPStatus.NO_CONTENT, None) self.client.v3.spaces.remove('space_id') self.client.delete.assert_called_with(self.client.delete.return_value.url)
Example #30
Source File: test_service_bindings.py From cf-python-client with Apache License 2.0 | 5 votes |
def test_delete(self): self.client.delete.return_value = self.mock_response( '/v2/service_bindings/binding_id', HTTPStatus.NO_CONTENT, None) self.client.v2.service_bindings.remove('binding_id') self.client.delete.assert_called_with(self.client.delete.return_value.url)