Python falcon.HTTP_200 Examples
The following are 30
code examples of falcon.HTTP_200().
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: app.py From iris-relay with BSD 2-Clause "Simplified" License | 8 votes |
def on_get(self, req, resp, ical_key): """Access the oncall calendar identified by the key. The response is in ical format and this url is intended to be supplied to any calendar application that can subscribe to calendars from the internet. """ try: path = self.base_url + '/api/v0/ical/' + ical_key if req.query_string: path += '?%s' % req.query_string result = self.oncall_client.get(path) except MaxRetryError as ex: logger.error(ex) else: if result.status_code == 200: resp.status = falcon.HTTP_200 resp.content_type = result.headers['Content-Type'] resp.body = result.content return elif 400 <= result.status_code <= 499: resp.status = falcon.HTTP_404 return raise falcon.HTTPInternalServerError('Internal Server Error', 'Invalid response from API')
Example #2
Source File: app.py From iris-relay with BSD 2-Clause "Simplified" License | 6 votes |
def __call__(self, req, resp): path = self.base_url + '/api/v0/' + '/'.join(req.path.split('/')[4:]) if req.query_string: path += '?%s' % req.query_string try: if req.method == 'GET': result = self.oncall_client.get(path) elif req.method == 'OPTIONS': return else: raise falcon.HTTPMethodNotAllowed(['GET', 'OPTIONS']) except MaxRetryError as e: logger.error(e.reason) raise falcon.HTTPInternalServerError('Internal Server Error', 'Max retry error, api unavailable') if result.status_code == 400: raise falcon.HTTPBadRequest('Bad Request', '') elif str(result.status_code)[0] != '2': raise falcon.HTTPInternalServerError('Internal Server Error', 'Unknown response from the api') else: resp.status = falcon.HTTP_200 resp.content_type = result.headers['Content-Type'] resp.body = result.content
Example #3
Source File: test_api_builddata.py From drydock with Apache License 2.0 | 6 votes |
def test_read_builddata_all(self, falcontest, seeded_builddata): """Test that by default the API returns all build data for a node.""" url = '/api/v1.0/nodes/foo/builddata' # Seed the database with build data nodelist = ['foo'] count = 3 seeded_builddata(nodelist=nodelist, count=count) # TODO(sh8121att) Make fixture for request header forging hdr = { 'Content-Type': 'application/json', 'X-IDENTITY-STATUS': 'Confirmed', 'X-USER-NAME': 'Test', 'X-ROLES': 'admin' } resp = falcontest.simulate_get(url, headers=hdr) assert resp.status == falcon.HTTP_200 resp_body = resp.json assert len(resp_body) == count
Example #4
Source File: test_jobs.py From freezer-api with Apache License 2.0 | 6 votes |
def test_on_patch_ok_with_some_fields(self): new_version = random.randint(0, 99) self.mock_db.update_job.return_value = new_version patch_doc = {'some_field': 'some_value', 'because': 'size_matters', 'job_schedule': {}} self.mock_req.stream.read.return_value = json.dumps(patch_doc) expected_result = {'job_id': common.fake_job_0_job_id, 'version': new_version} self.resource.update_actions_in_job = mock.Mock() self.resource.on_patch(self.mock_req, self.mock_req, common.fake_job_0_job_id) self.mock_db.update_job.assert_called_with( user_id=common.fake_job_0_user_id, job_id=common.fake_job_0_job_id, patch_doc=patch_doc) self.assertEqual(falcon.HTTP_200, self.mock_req.status) result = self.mock_req.body self.assertEqual(expected_result, result)
Example #5
Source File: nodes.py From drydock with Apache License 2.0 | 6 votes |
def on_post(self, req, resp): try: json_data = self.req_json(req) node_filter = json_data.get('node_filter', None) design_ref = json_data.get('design_ref', None) if design_ref is None: self.info(req.context, 'Missing required input value: design_ref') self.return_error( resp, falcon.HTTP_400, message='Missing input required value: design_ref', retry=False) return _, site_design = self.orchestrator.get_effective_site(design_ref) nodes = self.orchestrator.process_node_filter( node_filter=node_filter, site_design=site_design) resp_list = [n.name for n in nodes if nodes] resp.body = json.dumps(resp_list) resp.status = falcon.HTTP_200 except Exception as ex: self.error(req.context, "Unknown error: %s" % str(ex), exc_info=ex) self.return_error( resp, falcon.HTTP_500, message="Unknown error", retry=False)
Example #6
Source File: nodes.py From drydock with Apache License 2.0 | 6 votes |
def on_get(self, req, resp, hostname): try: latest = req.params.get('latest', 'false').upper() latest = True if latest == 'TRUE' else False node_bd = self.state_manager.get_build_data( node_name=hostname, latest=latest) if not node_bd: self.return_error( resp, falcon.HTTP_404, message="No build data found", retry=False) else: node_bd = [bd.to_dict() for bd in node_bd] resp.status = falcon.HTTP_200 resp.body = json.dumps(node_bd) resp.content_type = falcon.MEDIA_JSON except Exception as ex: self.error(req.context, "Unknown error: %s" % str(ex), exc_info=ex) self.return_error( resp, falcon.HTTP_500, message="Unknown error", retry=False)
Example #7
Source File: test_jobs.py From freezer-api with Apache License 2.0 | 6 votes |
def test_on_patch_ok_with_some_fields(self): new_version = random.randint(0, 99) self.mock_db.update_job.return_value = new_version patch_doc = {'some_field': 'some_value', 'because': 'size_matters', 'job_schedule': {}} self.mock_req.stream.read.return_value = json.dumps(patch_doc) expected_result = {'job_id': common.fake_job_0_job_id, 'version': new_version} self.resource.update_actions_in_job = mock.Mock() self.resource.on_patch(self.mock_req, self.mock_req, common.fake_job_0_project_id, common.fake_job_0_job_id) self.mock_db.update_job.assert_called_with( project_id=common.fake_job_0_project_id, user_id=common.fake_job_0_user_id, job_id=common.fake_job_0_job_id, patch_doc=patch_doc) self.assertEqual(falcon.HTTP_200, self.mock_req.status) result = self.mock_req.body self.assertEqual(expected_result, result)
Example #8
Source File: designs.py From drydock with Apache License 2.0 | 6 votes |
def on_get(self, req, resp): """Method handler for GET requests. :param req: Falcon request object :param resp: Falcon response object """ state = self.state_manager try: designs = list(state.designs.keys()) resp.body = json.dumps(designs) resp.status = falcon.HTTP_200 except Exception as ex: self.error(req.context, "Exception raised: %s" % str(ex)) self.return_error( resp, falcon.HTTP_500, message="Error accessing design list", retry=True)
Example #9
Source File: test_api_tasks_unit.py From drydock with Apache License 2.0 | 6 votes |
def test_get_tasks_id_resp(self, falcontest): url = '/api/v1.0/tasks/11111111-1111-1111-1111-111111111111' hdr = self.get_standard_header() result = falcontest.simulate_get(url, headers=hdr) assert result.status == falcon.HTTP_200 response_json = json.loads(result.text) assert response_json[ 'task_id'] == '11111111-1111-1111-1111-111111111111' try: response_json['build_data'] key_error = False except KeyError: key_error = True assert key_error try: response_json['subtask_errors'] key_error = False except KeyError: key_error = True assert key_error
Example #10
Source File: test_api_tasks_unit.py From drydock with Apache License 2.0 | 6 votes |
def test_get_tasks_id_layers_resp(self, falcontest): url = '/api/v1.0/tasks/11111111-1111-1111-1111-111111111113' hdr = self.get_standard_header() result = falcontest.simulate_get( url, headers=hdr, query_string='layers=2') LOG.debug(result.text) assert result.status == falcon.HTTP_200 response_json = json.loads(result.text) init_task_id = '11111111-1111-1111-1111-111111111113' sub_task_id_1 = '11111111-1111-1111-1111-111111111114' sub_task_id_2 = '11111111-1111-1111-1111-111111111115' assert response_json['init_task_id'] == init_task_id assert response_json[init_task_id]['task_id'] == init_task_id assert response_json[sub_task_id_1]['task_id'] == sub_task_id_1 assert response_json[sub_task_id_2]['task_id'] == sub_task_id_2 try: response_json['11111111-1111-1111-1111-111111111116'] key_error = False except KeyError: key_error = True assert key_error
Example #11
Source File: test_falcon.py From sentry-python with BSD 2-Clause "Simplified" License | 6 votes |
def test_falcon_raw_data_request(sentry_init, capture_events): sentry_init(integrations=[FalconIntegration()]) class Resource: def on_post(self, req, resp): sentry_sdk.capture_message("hi") resp.media = "ok" app = falcon.API() app.add_route("/", Resource()) events = capture_events() client = falcon.testing.TestClient(app) response = client.simulate_post("/", body="hi") assert response.status == falcon.HTTP_200 (event,) = events assert event["request"]["headers"]["Content-Length"] == "2" assert event["request"]["data"] == ""
Example #12
Source File: test_api_tasks_unit.py From drydock with Apache License 2.0 | 6 votes |
def test_get_tasks_id_builddata_resp(self, falcontest): url = '/api/v1.0/tasks/11111111-1111-1111-1111-111111111111' hdr = self.get_standard_header() result = falcontest.simulate_get( url, headers=hdr, query_string='builddata=true') LOG.debug(result.text) assert result.status == falcon.HTTP_200 response_json = json.loads(result.text) assert response_json['build_data'] try: response_json['subtask_errors'] key_error = False except KeyError: key_error = True assert key_error
Example #13
Source File: app.py From iris-relay with BSD 2-Clause "Simplified" License | 6 votes |
def on_get(self, req, resp): if not self.healthcheck_path: logger.error('Healthcheck path not set') raise falcon.HTTPNotFound() try: with open(self.healthcheck_path) as f: health = f.readline().strip() except IOError: raise falcon.HTTPNotFound() try: connection = db.connect() cursor = connection.cursor() cursor.execute('SELECT version()') cursor.close() connection.close() except Exception: resp.status = HTTP_503 resp.content_type = 'text/plain' resp.body = 'Could not connect to database' else: resp.status = HTTP_200 resp.content_type = 'text/plain' resp.body = health
Example #14
Source File: test_actions.py From freezer-api with Apache License 2.0 | 6 votes |
def test_on_patch_ok_with_some_fields(self): new_version = random.randint(0, 99) self.mock_db.update_action.return_value = new_version patch_doc = {'some_field': 'some_value', 'because': 'size_matters'} self.mock_json_body.return_value = patch_doc patch_doc.copy() expected_result = {'action_id': common.fake_action_0['action_id'], 'version': new_version} self.resource.on_patch(self.mock_req, self.mock_req, common.fake_action_0['action_id']) self.mock_db.update_action.assert_called_with( user_id=common.fake_action_0['user_id'], action_id=common.fake_action_0['action_id'], patch_doc=patch_doc) self.assertEqual(falcon.HTTP_200, self.mock_req.status) result = self.mock_req.body self.assertEqual(expected_result, result)
Example #15
Source File: test_falcon.py From sentry-python with BSD 2-Clause "Simplified" License | 6 votes |
def test_falcon_large_json_request(sentry_init, capture_events): sentry_init(integrations=[FalconIntegration()]) data = {"foo": {"bar": "a" * 2000}} class Resource: def on_post(self, req, resp): assert req.media == data sentry_sdk.capture_message("hi") resp.media = "ok" app = falcon.API() app.add_route("/", Resource()) events = capture_events() client = falcon.testing.TestClient(app) response = client.simulate_post("/", json=data) assert response.status == falcon.HTTP_200 (event,) = events assert event["_meta"]["request"]["data"]["foo"]["bar"] == { "": {"len": 2000, "rem": [["!limit", "x", 509, 512]]} } assert len(event["request"]["data"]["foo"]["bar"]) == 512
Example #16
Source File: test_falcon.py From sentry-python with BSD 2-Clause "Simplified" License | 6 votes |
def test_falcon_empty_json_request(sentry_init, capture_events, data): sentry_init(integrations=[FalconIntegration()]) class Resource: def on_post(self, req, resp): assert req.media == data sentry_sdk.capture_message("hi") resp.media = "ok" app = falcon.API() app.add_route("/", Resource()) events = capture_events() client = falcon.testing.TestClient(app) response = client.simulate_post("/", json=data) assert response.status == falcon.HTTP_200 (event,) = events assert event["request"]["data"] == data
Example #17
Source File: app.py From iris-relay with BSD 2-Clause "Simplified" License | 6 votes |
def on_get(self, req, resp): """ Echo back user provided content query string in TwiML: Example: Query strings: content: OK TwiML: <?xml version="1.0" encoding="UTF-8"?> <Response> <Say language="en-US" voice="alice">OK</Say> </Response> """ content = req.get_param('content') loop = req.get_param('loop') r = VoiceResponse() r.say(content, voice='alice', loop=loop, language="en-US") resp.status = falcon.HTTP_200 resp.body = str(r) resp.content_type = 'application/xml'
Example #18
Source File: falcon_app.py From py2swagger with MIT License | 6 votes |
def on_get(self, req, resp, id): """ Handles GET requests for another test --- tags: - test responses: 200: schema: type: string security: api_key: [] securityDefinitions: api_key: type: apiKey in: Header name: Authorization """ resp.status = falcon.HTTP_200 # This is the default status resp.body = '\nHello world with {}\n\n'.format(id)
Example #19
Source File: test_sessions.py From freezer-api with Apache License 2.0 | 6 votes |
def test_on_patch_ok_with_some_fields(self): new_version = random.randint(0, 99) self.mock_db.update_session.return_value = new_version patch_doc = {'some_field': 'some_value', 'because': 'size_matters'} self.mock_json_body.return_value = patch_doc expected_result = {'session_id': common.fake_session_0['session_id'], 'version': new_version} self.resource.on_patch(self.mock_req, self.mock_req, common.fake_session_0['project_id'], common.fake_session_0['session_id']) self.mock_db.update_session.assert_called_with( user_id=common.fake_session_0['user_id'], project_id=common.fake_session_0['project_id'], session_id=common.fake_session_0['session_id'], patch_doc=patch_doc) self.assertEqual(falcon.HTTP_200, self.mock_req.status) result = self.mock_req.body self.assertEqual(expected_result, result)
Example #20
Source File: test_clients.py From freezer-api with Apache License 2.0 | 5 votes |
def setUp(self): super(TestClientsCollectionResource, self).setUp() self.mock_db = mock.Mock() self.mock_req = mock.MagicMock() self.mock_req.env.__getitem__.side_effect = common.get_req_items self.mock_req.get_header.return_value = common.fake_data_0_user_id self.mock_req.status = falcon.HTTP_200 self.resource = v1_clients.ClientsCollectionResource(self.mock_db) self.mock_json_body = mock.Mock() self.mock_json_body.return_value = {} self.resource.json_body = self.mock_json_body
Example #21
Source File: test_jobs.py From freezer-api with Apache License 2.0 | 5 votes |
def setUp(self): super(TestJobsCollectionResource, self).setUp() self.mock_json_body = mock.Mock() self.mock_json_body.return_value = {} self.mock_db = mock.Mock() self.mock_req = mock.MagicMock() self.mock_req.env.__getitem__.side_effect = common.get_req_items self.mock_req.get_header.return_value = common.fake_job_0_user_id self.mock_req.status = falcon.HTTP_200 self.resource = v1_jobs.JobsCollectionResource(self.mock_db) self.resource.json_body = self.mock_json_body
Example #22
Source File: test_jobs.py From freezer-api with Apache License 2.0 | 5 votes |
def test_on_get_return_empty_list(self): self.mock_db.search_job.return_value = [] expected_result = {'jobs': []} self.resource.on_get(self.mock_req, self.mock_req) result = self.mock_req.body self.assertEqual(expected_result, result) self.assertEqual(falcon.HTTP_200, self.mock_req.status)
Example #23
Source File: test_jobs.py From freezer-api with Apache License 2.0 | 5 votes |
def test_on_get_return_correct_list(self): self.mock_db.search_job.return_value = [common.get_fake_job_0(), common.get_fake_job_1()] expected_result = { 'jobs': [common.get_fake_job_0(), common.get_fake_job_1()]} self.resource.on_get(self.mock_req, self.mock_req) result = self.mock_req.body self.assertEqual(expected_result, result) self.assertEqual(falcon.HTTP_200, self.mock_req.status)
Example #24
Source File: test_actions.py From freezer-api with Apache License 2.0 | 5 votes |
def setUp(self): super(TestActionsCollectionResource, self).setUp() self.mock_db = mock.Mock() self.mock_req = mock.MagicMock() self.mock_req.env.__getitem__.side_effect = common.get_req_items self.mock_req.get_header.return_value = common.fake_action_0['user_id'] self.mock_req.status = falcon.HTTP_200 self.resource = v1_actions.ActionsCollectionResource(self.mock_db) self.mock_json_body = mock.Mock() self.mock_json_body.return_value = {} self.resource.json_body = self.mock_json_body
Example #25
Source File: test_actions.py From freezer-api with Apache License 2.0 | 5 votes |
def test_on_get_return_empty_list(self): self.mock_db.search_action.return_value = [] expected_result = {'actions': []} self.resource.on_get(self.mock_req, self.mock_req) result = self.mock_req.body self.assertEqual(expected_result, result) self.assertEqual(falcon.HTTP_200, self.mock_req.status)
Example #26
Source File: test_sessions.py From freezer-api with Apache License 2.0 | 5 votes |
def test_on_get_return_correct_list(self): self.mock_db.search_session.return_value = [ common.get_fake_session_0(), common.get_fake_session_1()] expected_result = {'sessions': [common.get_fake_session_0(), common.get_fake_session_1()]} self.resource.on_get(self.mock_req, self.mock_req, common.fake_session_0['project_id']) result = self.mock_req.body self.assertEqual(expected_result, result) self.assertEqual(falcon.HTTP_200, self.mock_req.status)
Example #27
Source File: test_actions.py From freezer-api with Apache License 2.0 | 5 votes |
def test_on_get_return_correct_list(self): self.mock_db.search_action.return_value = [common.get_fake_action_0(), common.get_fake_action_1()] expected_result = {'actions': [common.get_fake_action_0(), common.get_fake_action_1()]} self.resource.on_get(self.mock_req, self.mock_req) result = self.mock_req.body self.assertEqual(expected_result, result) self.assertEqual(falcon.HTTP_200, self.mock_req.status)
Example #28
Source File: test_jobs.py From freezer-api with Apache License 2.0 | 5 votes |
def setUp(self): super(TestJobsResource, self).setUp() self.mock_db = mock.Mock() self.mock_req = mock.MagicMock() self.mock_req.env.__getitem__.side_effect = common.get_req_items self.mock_req.stream.read.return_value = {} self.mock_req.get_header.return_value = common.fake_job_0_user_id self.mock_req.status = falcon.HTTP_200 self.resource = v1_jobs.JobsResource(self.mock_db)
Example #29
Source File: test_actions.py From freezer-api with Apache License 2.0 | 5 votes |
def test_on_get_return_correct_data(self): self.mock_db.get_action.return_value = common.get_fake_action_0() self.resource.on_get(self.mock_req, self.mock_req, common.fake_action_0['action_id']) result = self.mock_req.body self.assertEqual(common.get_fake_action_0(), result) self.assertEqual(falcon.HTTP_200, self.mock_req.status)
Example #30
Source File: test_jobs.py From freezer-api with Apache License 2.0 | 5 votes |
def setUp(self): super(TestJobsEvent, self).setUp() self.mock_db = mock.Mock() self.mock_req = mock.MagicMock() self.mock_req.env.__getitem__.side_effect = common.get_req_items self.mock_req.get_header.return_value = common.fake_session_0[ 'user_id'] self.mock_req.status = falcon.HTTP_200 self.resource = v1_jobs.JobsEvent(self.mock_db) self.mock_json_body = mock.Mock() self.mock_json_body.return_value = {} self.resource.json_body = self.mock_json_body