當前位置: 首頁>>代碼示例>>Python>>正文


Python falcon.HTTP_200屬性代碼示例

本文整理匯總了Python中falcon.HTTP_200屬性的典型用法代碼示例。如果您正苦於以下問題:Python falcon.HTTP_200屬性的具體用法?Python falcon.HTTP_200怎麽用?Python falcon.HTTP_200使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在falcon的用法示例。


在下文中一共展示了falcon.HTTP_200屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: on_get

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_200 [as 別名]
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) 
開發者ID:airshipit,項目名稱:drydock,代碼行數:22,代碼來源:designs.py

示例2: on_get

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_200 [as 別名]
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) 
開發者ID:airshipit,項目名稱:drydock,代碼行數:25,代碼來源:nodes.py

示例3: on_post

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_200 [as 別名]
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) 
開發者ID:airshipit,項目名稱:drydock,代碼行數:27,代碼來源:nodes.py

示例4: test_read_builddata_all

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_200 [as 別名]
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 
開發者ID:airshipit,項目名稱:drydock,代碼行數:26,代碼來源:test_api_builddata.py

示例5: test_get_tasks_id_resp

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_200 [as 別名]
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 
開發者ID:airshipit,項目名稱:drydock,代碼行數:24,代碼來源:test_api_tasks_unit.py

示例6: test_get_tasks_id_builddata_resp

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_200 [as 別名]
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 
開發者ID:airshipit,項目名稱:drydock,代碼行數:19,代碼來源:test_api_tasks_unit.py

示例7: test_get_tasks_id_layers_resp

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_200 [as 別名]
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 
開發者ID:airshipit,項目名稱:drydock,代碼行數:25,代碼來源:test_api_tasks_unit.py

示例8: on_get

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_200 [as 別名]
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) 
開發者ID:Arello-Mobile,項目名稱:py2swagger,代碼行數:22,代碼來源:falcon_app.py

示例9: on_get

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_200 [as 別名]
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') 
開發者ID:linkedin,項目名稱:iris-relay,代碼行數:27,代碼來源:app.py

示例10: __call__

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_200 [as 別名]
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 
開發者ID:linkedin,項目名稱:iris-relay,代碼行數:24,代碼來源:app.py

示例11: test_falcon_large_json_request

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_200 [as 別名]
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 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:27,代碼來源:test_falcon.py

示例12: test_falcon_empty_json_request

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_200 [as 別名]
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 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:22,代碼來源:test_falcon.py

示例13: test_falcon_raw_data_request

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_200 [as 別名]
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"] == "" 
開發者ID:getsentry,項目名稱:sentry-python,代碼行數:22,代碼來源:test_falcon.py

示例14: test_on_patch_ok_with_some_fields

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_200 [as 別名]
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) 
開發者ID:openstack,項目名稱:freezer-api,代碼行數:21,代碼來源:test_jobs.py

示例15: test_on_patch_ok_with_some_fields

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_200 [as 別名]
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) 
開發者ID:openstack,項目名稱:freezer-api,代碼行數:23,代碼來源:test_actions.py


注:本文中的falcon.HTTP_200屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。