Python falcon.HTTP_201 Examples
The following are 30
code examples of falcon.HTTP_201().
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
falcon
, or try the search function
.
Example #1
Source File: actions_api.py From shipyard with Apache License 2.0 | 6 votes |
def on_post(self, req, resp, **kwargs): """ Accept an action into shipyard """ # The 'allow-intermediate-commits' query parameter is set to False # unless explicitly set to True allow_intermediate_commits = ( req.get_param_as_bool(name='allow-intermediate-commits')) input_action = self.req_json(req, validate_json_schema=ACTION) action = self.create_action( action=input_action, context=req.context, allow_intermediate_commits=allow_intermediate_commits) LOG.info("Id %s generated for action %s", action['id'], action['name']) # respond with the action and location for checking status resp.status = falcon.HTTP_201 resp.body = self.to_json(action) resp.location = '/api/v1.0/actions/{}'.format(action['id'])
Example #2
Source File: tasks.py From drydock with Apache License 2.0 | 6 votes |
def task_verify_site(self, req, resp, json_data): """Create async task for verify site.""" action = json_data.get('action', None) if action != 'verify_site': self.error( req.context, "Task body ended up in wrong handler: action %s in task_verify_site" % action) self.return_error( resp, falcon.HTTP_500, message="Error", retry=False) try: task = self.create_task(json_data, req.context) resp.body = json.dumps(task.to_dict()) resp.append_header('Location', "/api/v1.0/tasks/%s" % str(task.task_id)) resp.status = falcon.HTTP_201 except errors.InvalidFormat as ex: self.error(req.context, ex.msg) self.return_error( resp, falcon.HTTP_400, message=ex.msg, retry=False)
Example #3
Source File: tasks.py From drydock with Apache License 2.0 | 6 votes |
def task_prepare_site(self, req, resp, json_data): """Create async task for prepare site.""" action = json_data.get('action', None) if action != 'prepare_site': self.error( req.context, "Task body ended up in wrong handler: action %s in task_prepare_site" % action) self.return_error( resp, falcon.HTTP_500, message="Error", retry=False) try: task = self.create_task(json_data, req.context) resp.body = json.dumps(task.to_dict()) resp.append_header('Location', "/api/v1.0/tasks/%s" % str(task.task_id)) resp.status = falcon.HTTP_201 except errors.InvalidFormat as ex: self.error(req.context, ex.msg) self.return_error( resp, falcon.HTTP_400, message=ex.msg, retry=False)
Example #4
Source File: tasks.py From drydock with Apache License 2.0 | 6 votes |
def task_prepare_nodes(self, req, resp, json_data): """Create async task for prepare node.""" action = json_data.get('action', None) if action != 'prepare_nodes': self.error( req.context, "Task body ended up in wrong handler: action %s in task_prepare_nodes" % action) self.return_error( resp, falcon.HTTP_500, message="Error", retry=False) try: task = self.create_task(json_data, req.context) resp.body = json.dumps(task.to_dict()) resp.append_header('Location', "/api/v1.0/tasks/%s" % str(task.task_id)) resp.status = falcon.HTTP_201 except errors.InvalidFormat as ex: self.error(req.context, ex.msg) self.return_error( resp, falcon.HTTP_400, message=ex.msg, retry=False)
Example #5
Source File: tasks.py From drydock with Apache License 2.0 | 6 votes |
def task_deploy_nodes(self, req, resp, json_data): """Create async task for deploy node.""" action = json_data.get('action', None) if action != 'deploy_nodes': self.error( req.context, "Task body ended up in wrong handler: action %s in task_deploy_nodes" % action) self.return_error( resp, falcon.HTTP_500, message="Error", retry=False) try: task = self.create_task(json_data, req.context) resp.body = json.dumps(task.to_dict()) resp.append_header('Location', "/api/v1.0/tasks/%s" % str(task.task_id)) resp.status = falcon.HTTP_201 except errors.InvalidFormat as ex: self.error(req.context, ex.msg) self.return_error( resp, falcon.HTTP_400, message=ex.msg, retry=False)
Example #6
Source File: tasks.py From drydock with Apache License 2.0 | 6 votes |
def task_destroy_nodes(self, req, resp, json_data): """Create async task for destroy node.""" action = json_data.get('action', None) if action != 'destroy_nodes': self.error( req.context, "Task body ended up in wrong handler: action %s in task_destroy_nodes" % action) self.return_error( resp, falcon.HTTP_500, message="Error", retry=False) try: task = self.create_task(json_data, req.context) resp.body = json.dumps(task.to_dict()) resp.append_header('Location', "/api/v1.0/tasks/%s" % str(task.task_id)) resp.status = falcon.HTTP_201 except errors.InvalidFormat as ex: self.error(req.context, ex.msg) self.return_error( resp, falcon.HTTP_400, message=ex.msg, retry=False)
Example #7
Source File: test_api_tasks.py From drydock with Apache License 2.0 | 6 votes |
def test_create_task(self, falcontest, blank_state): url = '/api/v1.0/tasks' req_hdr = { 'Content-Type': 'application/json', 'X-IDENTITY-STATUS': 'Confirmed', 'X-USER-NAME': 'Test', 'X-ROLES': 'admin', } json_body = json.dumps({ 'action': 'verify_site', 'design_ref': 'http://foo.com', }) resp = falcontest.simulate_post(url, headers=req_hdr, body=json_body) assert resp.status == falcon.HTTP_201 assert resp.headers.get('Location') is not None # TODO(sh8121att) Make this a general fixture in conftest.py
Example #8
Source File: tasks.py From drydock with Apache License 2.0 | 6 votes |
def task_validate_design(self, req, resp, json_data): """Create async task for validate design.""" action = json_data.get('action', None) if action != 'validate_design': self.error( req.context, "Task body ended up in wrong handler: action %s in task_validate_design" % action) self.return_error( resp, falcon.HTTP_500, message="Error", retry=False) try: task = self.create_task(json_data, req.context) resp.body = json.dumps(task.to_dict()) resp.append_header('Location', "/api/v1.0/tasks/%s" % str(task.task_id)) resp.status = falcon.HTTP_201 except errors.InvalidFormat as ex: self.error(req.context, ex.msg) self.return_error( resp, falcon.HTTP_400, message=ex.msg, retry=False)
Example #9
Source File: request.py From certidude with MIT License | 6 votes |
def on_post(self, req, resp, cn): """ Sign a certificate signing request """ try: cert, buf = self.authority.sign(cn, profile=config.PROFILES[req.get_param("profile", default="rw")], overwrite=True, signer=req.context.get("user").name) # Mailing and long poll publishing implemented in the function above except EnvironmentError: # no such CSR raise falcon.HTTPNotFound() resp.body = "Certificate successfully signed" resp.status = falcon.HTTP_201 resp.location = os.path.join(req.relative_uri, "..", "..", "signed", cn) logger.info("Signing request %s signed by %s from %s", cn, req.context.get("user"), req.context.get("remote_addr"))
Example #10
Source File: test_api_tasks.py From drydock with Apache License 2.0 | 6 votes |
def test_create_task(self, falcontest, blank_state): url = '/api/v1.0/tasks' req_hdr = { 'Content-Type': 'application/json', 'X-IDENTITY-STATUS': 'Confirmed', 'X-USER-NAME': 'Test', 'X-ROLES': 'admin', } json_body = json.dumps({ 'action': 'verify_site', 'design_ref': 'http://foo.com', }) resp = falcontest.simulate_post(url, headers=req_hdr, body=json_body) assert resp.status == falcon.HTTP_201 assert resp.headers.get('Location') is not None # TODO(sh8121att) Make this a general fixture in conftest.py
Example #11
Source File: tasks.py From drydock with Apache License 2.0 | 6 votes |
def task_relabel_nodes(self, req, resp, json_data): """Create async task for relabel nodes.""" action = json_data.get('action', None) if action != 'relabel_nodes': self.error( req.context, "Task body ended up in wrong handler: action %s in task_relabel_nodes" % action) self.return_error( resp, falcon.HTTP_500, message="Error", retry=False) try: task = self.create_task(json_data, req.context) resp.body = json.dumps(task.to_dict()) resp.append_header('Location', "/api/v1.0/tasks/%s" % str(task.task_id)) resp.status = falcon.HTTP_201 except errors.InvalidFormat as ex: self.error(req.context, ex.msg) self.return_error( resp, falcon.HTTP_400, message=ex.msg, retry=False)
Example #12
Source File: tasks.py From drydock with Apache License 2.0 | 6 votes |
def task_destroy_nodes(self, req, resp, json_data): """Create async task for destroy node.""" action = json_data.get('action', None) if action != 'destroy_nodes': self.error( req.context, "Task body ended up in wrong handler: action %s in task_destroy_nodes" % action) self.return_error( resp, falcon.HTTP_500, message="Error", retry=False) try: task = self.create_task(json_data, req.context) resp.body = json.dumps(task.to_dict()) resp.append_header('Location', "/api/v1.0/tasks/%s" % str(task.task_id)) resp.status = falcon.HTTP_201 except errors.InvalidFormat as ex: self.error(req.context, ex.msg) self.return_error( resp, falcon.HTTP_400, message=ex.msg, retry=False)
Example #13
Source File: tasks.py From drydock with Apache License 2.0 | 6 votes |
def task_deploy_nodes(self, req, resp, json_data): """Create async task for deploy node.""" action = json_data.get('action', None) if action != 'deploy_nodes': self.error( req.context, "Task body ended up in wrong handler: action %s in task_deploy_nodes" % action) self.return_error( resp, falcon.HTTP_500, message="Error", retry=False) try: task = self.create_task(json_data, req.context) resp.body = json.dumps(task.to_dict()) resp.append_header('Location', "/api/v1.0/tasks/%s" % str(task.task_id)) resp.status = falcon.HTTP_201 except errors.InvalidFormat as ex: self.error(req.context, ex.msg) self.return_error( resp, falcon.HTTP_400, message=ex.msg, retry=False)
Example #14
Source File: tasks.py From drydock with Apache License 2.0 | 6 votes |
def task_prepare_nodes(self, req, resp, json_data): """Create async task for prepare node.""" action = json_data.get('action', None) if action != 'prepare_nodes': self.error( req.context, "Task body ended up in wrong handler: action %s in task_prepare_nodes" % action) self.return_error( resp, falcon.HTTP_500, message="Error", retry=False) try: task = self.create_task(json_data, req.context) resp.body = json.dumps(task.to_dict()) resp.append_header('Location', "/api/v1.0/tasks/%s" % str(task.task_id)) resp.status = falcon.HTTP_201 except errors.InvalidFormat as ex: self.error(req.context, ex.msg) self.return_error( resp, falcon.HTTP_400, message=ex.msg, retry=False)
Example #15
Source File: tasks.py From drydock with Apache License 2.0 | 6 votes |
def task_prepare_site(self, req, resp, json_data): """Create async task for prepare site.""" action = json_data.get('action', None) if action != 'prepare_site': self.error( req.context, "Task body ended up in wrong handler: action %s in task_prepare_site" % action) self.return_error( resp, falcon.HTTP_500, message="Error", retry=False) try: task = self.create_task(json_data, req.context) resp.body = json.dumps(task.to_dict()) resp.append_header('Location', "/api/v1.0/tasks/%s" % str(task.task_id)) resp.status = falcon.HTTP_201 except errors.InvalidFormat as ex: self.error(req.context, ex.msg) self.return_error( resp, falcon.HTTP_400, message=ex.msg, retry=False)
Example #16
Source File: tasks.py From drydock with Apache License 2.0 | 6 votes |
def task_verify_site(self, req, resp, json_data): """Create async task for verify site.""" action = json_data.get('action', None) if action != 'verify_site': self.error( req.context, "Task body ended up in wrong handler: action %s in task_verify_site" % action) self.return_error( resp, falcon.HTTP_500, message="Error", retry=False) try: task = self.create_task(json_data, req.context) resp.body = json.dumps(task.to_dict()) resp.append_header('Location', "/api/v1.0/tasks/%s" % str(task.task_id)) resp.status = falcon.HTTP_201 except errors.InvalidFormat as ex: self.error(req.context, ex.msg) self.return_error( resp, falcon.HTTP_400, message=ex.msg, retry=False)
Example #17
Source File: tasks.py From drydock with Apache License 2.0 | 6 votes |
def task_validate_design(self, req, resp, json_data): """Create async task for validate design.""" action = json_data.get('action', None) if action != 'validate_design': self.error( req.context, "Task body ended up in wrong handler: action %s in task_validate_design" % action) self.return_error( resp, falcon.HTTP_500, message="Error", retry=False) try: task = self.create_task(json_data, req.context) resp.body = json.dumps(task.to_dict()) resp.append_header('Location', "/api/v1.0/tasks/%s" % str(task.task_id)) resp.status = falcon.HTTP_201 except errors.InvalidFormat as ex: self.error(req.context, ex.msg) self.return_error( resp, falcon.HTTP_400, message=ex.msg, retry=False)
Example #18
Source File: test_jobs.py From freezer-api with Apache License 2.0 | 5 votes |
def test_on_post_ok(self): new_version = random.randint(0, 99) self.mock_db.replace_job.return_value = new_version job = common.get_fake_job_0() self.mock_req.stream.read.return_value = json.dumps(job) expected_result = {'job_id': common.fake_job_0_job_id, 'version': new_version} self.resource.on_post(self.mock_req, self.mock_req, common.fake_job_0_job_id) self.assertEqual(falcon.HTTP_201, self.mock_req.status) self.assertEqual(expected_result, self.mock_req.body)
Example #19
Source File: test_jobs.py From freezer-api with Apache License 2.0 | 5 votes |
def test_on_post_inserts_correct_data(self): job = common.get_fake_job_0() self.mock_json_body.return_value = job self.mock_db.add_job.return_value = 'pjiofrdslaikfunr' expected_result = {'job_id': 'pjiofrdslaikfunr'} self.resource.on_post(self.mock_req, self.mock_req, common.fake_job_0_project_id) self.assertEqual(falcon.HTTP_201, self.mock_req.status) self.assertEqual(expected_result, self.mock_req.body)
Example #20
Source File: test_jobs.py From freezer-api with Apache License 2.0 | 5 votes |
def test_on_post_ok(self): new_version = random.randint(0, 99) self.mock_db.replace_job.return_value = new_version job = common.get_fake_job_0() self.mock_req.stream.read.return_value = json.dumps(job) expected_result = {'job_id': common.fake_job_0_job_id, 'version': new_version} self.resource.on_post(self.mock_req, self.mock_req, common.fake_job_0_project_id, common.fake_job_0_job_id) self.assertEqual(falcon.HTTP_201, self.mock_req.status) self.assertEqual(expected_result, self.mock_req.body)
Example #21
Source File: test_actions.py From freezer-api with Apache License 2.0 | 5 votes |
def test_on_post_ok(self): new_version = random.randint(0, 99) self.mock_db.replace_action.return_value = new_version action = common.get_fake_action_0() self.mock_json_body.return_value = action expected_result = {'action_id': common.fake_action_0['action_id'], 'version': new_version} self.resource.on_post(self.mock_req, self.mock_req, common.fake_action_0['project_id'], common.fake_action_0['action_id']) self.assertEqual(falcon.HTTP_201, self.mock_req.status) self.assertEqual(expected_result, self.mock_req.body)
Example #22
Source File: test_clients.py From freezer-api with Apache License 2.0 | 5 votes |
def test_on_post_inserts_correct_data(self): self.mock_json_body.return_value = common.fake_client_info_0 self.mock_db.add_client.return_value = common.fake_client_info_0[ 'client_id'] expected_result = {'client_id': common.fake_client_info_0['client_id']} self.resource.on_post(self.mock_req, self.mock_req, common.fake_client_info_0['project_id']) self.assertEqual(falcon.HTTP_201, self.mock_req.status) self.assertEqual(expected_result, self.mock_req.body)
Example #23
Source File: designs.py From drydock with Apache License 2.0 | 5 votes |
def on_post(self, req, resp): """Method handler for POST requests. :param req: Falcon request object :param resp: Falcon response object """ try: json_data = self.req_json(req) design = None if json_data is not None: base_design = json_data.get('base_design_id', None) if base_design is not None: base_design = uuid.UUID(base_design) design = hd_objects.SiteDesign(base_design_id=base_design) else: design = hd_objects.SiteDesign() design.assign_id() design.create(req.context, self.state_manager) resp.body = json.dumps(design.obj_to_simple()) resp.status = falcon.HTTP_201 except errors.StateError: self.error(req.context, "Error updating persistence") self.return_error( resp, falcon.HTTP_500, message="Error updating persistence", retry=True) except errors.InvalidFormat as fex: self.error(req.context, str(fex)) self.return_error( resp, falcon.HTTP_400, message=str(fex), retry=False)
Example #24
Source File: reset.py From PROTON with BSD 3-Clause "New" or "Revised" License | 5 votes |
def on_post(self, req, resp): try: post_payload = json.loads(req.stream.read()) results = self.proton_reset_user(post_payload['db_flavour'], 'iam', post_payload['reset_payload']) resp.body = results resp.status = falcon.HTTP_201 except Exception as e: resp.body = json.dumps({ 'message': "POST request must contain 'db_flavour'[PROTON supports `sqlite` or `postgresql`] " "and 'reset_payload'" }) resp.status = falcon.HTTP_403
Example #25
Source File: test_backups.py From freezer-api with Apache License 2.0 | 5 votes |
def test_on_post_inserts_correct_data(self): self.mock_json_body.return_value = common.fake_data_0_backup_metadata self.mock_db.add_backup.return_value = ( common.fake_data_0_wrapped_backup_metadata['backup_id'] ) self.resource.on_post(self.mock_req, self.mock_req, common.fake_data_0_wrapped_backup_metadata[ 'project_id']) expected_result = { 'backup_id': common.fake_data_0_wrapped_backup_metadata[ 'backup_id']} self.assertEqual(expected_result, self.mock_req.body) self.assertEqual(falcon.HTTP_201, self.mock_req.status)
Example #26
Source File: server.py From cccatalog-api with MIT License | 5 votes |
def on_post(self, req, resp): j = req.media try: event_controller.create_search_rating( query=j['query'], relevant=j['relevant'] ) resp.status = falcon.HTTP_201 except ValueError: resp.body = '{"message": "Rating must be True or False"}' resp.status = falcon.HTTP_400
Example #27
Source File: server.py From cccatalog-api with MIT License | 5 votes |
def on_post(self, req, resp): j = req.media try: event_controller.create_detail_event( event=j['event_type'], result_uuid=j['result_uuid'] ) resp.status = falcon.HTTP_201 except KeyError: valid_events = event_controller.list_valid_detail_events() resp.body = \ '{{"message": "Invalid event_type. Valid types: {}"}}' \ .format(valid_events) resp.status = falcon.HTTP_400
Example #28
Source File: tools.py From polkascan-pre-harvester with GNU General Public License v3.0 | 5 votes |
def on_get(self, req, resp): substrate = SubstrateInterface(SUBSTRATE_RPC_URL) # Get extrinsics json_block = substrate.get_chain_block(req.params.get('block_hash')) if not json_block: resp.status = falcon.HTTP_404 else: extrinsics = json_block['block']['extrinsics'] # Get metadata metadata_decoder = substrate.get_block_metadata(json_block['block']['header']['parentHash']) #result = [{'runtime': substrate.get_block_runtime_version(req.params.get('block_hash')), 'metadata': metadata_result.get_data_dict()}] result = [] for extrinsic in extrinsics: if int(json_block['block']['header']['number'], 16) == 61181: extrinsics_decoder = ExtrinsicsBlock61181Decoder(ScaleBytes(extrinsic), metadata=metadata_decoder) else: extrinsics_decoder = ExtrinsicsDecoder(ScaleBytes(extrinsic), metadata=metadata_decoder) result.append(extrinsics_decoder.decode()) resp.status = falcon.HTTP_201 resp.media = result
Example #29
Source File: tools.py From polkascan-pre-harvester with GNU General Public License v3.0 | 5 votes |
def on_get(self, req, resp): substrate = SubstrateInterface(SUBSTRATE_RPC_URL) # Get Parent hash json_block = substrate.get_block_header(req.params.get('block_hash')) # Get metadata metadata_decoder = substrate.get_block_metadata(json_block['parentHash']) # Get events for block hash events_decoder = substrate.get_block_events(req.params.get('block_hash'), metadata_decoder=metadata_decoder) resp.status = falcon.HTTP_201 resp.media = {'events': events_decoder.value, 'runtime': substrate.get_block_runtime_version(req.params.get('block_hash'))}
Example #30
Source File: harvester.py From polkascan-pre-harvester with GNU General Public License v3.0 | 5 votes |
def on_post(self, req, resp): task = start_harvester.delay(check_gaps=True) resp.status = falcon.HTTP_201 resp.media = { 'status': 'success', 'data': { 'task_id': task.id } }