当前位置: 首页>>代码示例>>Python>>正文


Python falcon.HTTP_202属性代码示例

本文整理汇总了Python中falcon.HTTP_202属性的典型用法代码示例。如果您正苦于以下问题:Python falcon.HTTP_202属性的具体用法?Python falcon.HTTP_202怎么用?Python falcon.HTTP_202使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在falcon的用法示例。


在下文中一共展示了falcon.HTTP_202属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_post

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_202 [as 别名]
def on_post(self, req, resp, session_id):
        # POST /v1/sessions/{session_id}/action
        # executes an action on the specified session

        user_id = req.get_header('X-User-ID') or ''
        doc = self.json_body(req)

        try:
            action, params = next(iter(doc.items()))
        except Exception:
            raise freezer_api_exc.BadDataFormat("Bad action request format")

        session_doc = self.db.get_session(user_id=user_id,
                                          session_id=session_id)
        session = Session(session_doc)
        session.execute_action(action, params)

        if session.need_update:
            self.db.update_session(user_id=user_id,
                                   session_id=session_id,
                                   patch_doc=session.doc)
        resp.status = falcon.HTTP_202
        resp.body = {'result': session.action_result,
                     'session_tag': session.session_tag} 
开发者ID:openstack,项目名称:freezer-api,代码行数:26,代码来源:sessions.py

示例2: on_post

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_202 [as 别名]
def on_post(self, req, resp, job_id):
        # POST /v1/jobs/{job_id}/event
        # requests an event on the specified job

        user_id = req.get_header('X-User-ID') or ''
        doc = self.json_body(req)

        try:
            event, params = next(iter(doc.items()))
        except Exception:
            raise freezer_api_exc.BadDataFormat("Bad event request format")

        job_doc = self.db.get_job(user_id=user_id,
                                  job_id=job_id)
        job = Job(job_doc)
        result = job.execute_event(event, params)

        if job.need_update:
            self.db.replace_job(user_id=user_id,
                                job_id=job_id,
                                doc=job.doc)
        resp.status = falcon.HTTP_202
        resp.body = {'result': result} 
开发者ID:openstack,项目名称:freezer-api,代码行数:25,代码来源:jobs.py

示例3: on_post

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_202 [as 别名]
def on_post(self, req, resp, project_id, job_id):
        # POST /v2/{project_id}/jobs/{job_id}/event
        # requests an event on the specified job

        user_id = req.get_header('X-User-ID') or ''
        doc = self.json_body(req)

        try:
            event, params = next(iter(doc.items()))
        except Exception:
            raise freezer_api_exc.BadDataFormat("Bad event request format")

        job_doc = self.db.get_job(project_id=project_id,
                                  user_id=user_id,
                                  job_id=job_id)
        job = Job(job_doc)
        result = job.execute_event(event, params)

        if job.need_update:
            self.db.replace_job(project_id=project_id,
                                user_id=user_id,
                                job_id=job_id,
                                doc=job.doc)
        resp.status = falcon.HTTP_202
        resp.body = {'result': result} 
开发者ID:openstack,项目名称:freezer-api,代码行数:27,代码来源:jobs.py

示例4: test_on_post_start_action_ok

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_202 [as 别名]
def test_on_post_start_action_ok(self):
        new_version = random.randint(0, 99)
        self.mock_db.get_session.return_value = common.get_fake_session_0()
        self.mock_db.update_session.return_value = new_version

        action = {"start": {
            "job_id": 'job_id_2',
            "current_tag": 5
        }}
        self.mock_json_body.return_value = action
        expected_result = {'result': 'success',
                           'session_tag': 6}
        self.resource.on_post(self.mock_req, self.mock_req,
                              common.fake_session_0['session_id'])
        self.assertEqual(falcon.HTTP_202, self.mock_req.status)
        self.assertEqual(expected_result, self.mock_req.body) 
开发者ID:openstack,项目名称:freezer-api,代码行数:18,代码来源:test_sessions.py

示例5: test_on_post_start_succeeds_in_holdoff_if_tag_needs_not_increment

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_202 [as 别名]
def test_on_post_start_succeeds_in_holdoff_if_tag_needs_not_increment(
            self, mock_time):
        mock_time.time.return_value = 1000
        new_version = random.randint(0, 99)
        session_doc = common.get_fake_session_0()
        session_doc['time_start'] = 999
        self.mock_db.get_session.return_value = session_doc
        self.mock_db.update_session.return_value = new_version
        action = {"start": {
            "job_id": 'job_id_2',
            "current_tag": 4
        }}
        self.mock_json_body.return_value = action
        expected_result = {'result': 'success',
                           'session_tag': 5}
        self.resource.on_post(self.mock_req, self.mock_req,
                              common.fake_session_0['session_id'])
        self.assertEqual(falcon.HTTP_202, self.mock_req.status)
        self.assertEqual(expected_result, self.mock_req.body) 
开发者ID:openstack,项目名称:freezer-api,代码行数:21,代码来源:test_sessions.py

示例6: test_on_post_start_replies_holdoff_if_tag_would_increment

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_202 [as 别名]
def test_on_post_start_replies_holdoff_if_tag_would_increment(self,
                                                                  mock_time):
        mock_time.time.return_value = 1000
        new_version = random.randint(0, 99)
        session_doc = common.get_fake_session_0()
        session_doc['time_start'] = 999
        self.mock_db.get_session.return_value = session_doc
        self.mock_db.update_session.return_value = new_version
        action = {"start": {
            "job_id": 'job_id_2',
            "current_tag": 5
        }}
        self.mock_json_body.return_value = action
        expected_result = {'result': 'hold-off',
                           'session_tag': 5}
        self.resource.on_post(self.mock_req, self.mock_req,
                              common.fake_session_0['session_id'])
        self.assertEqual(falcon.HTTP_202, self.mock_req.status)
        self.assertEqual(expected_result, self.mock_req.body) 
开发者ID:openstack,项目名称:freezer-api,代码行数:21,代码来源:test_sessions.py

示例7: test_on_post_start_outofholdoff_replies_outofsync_when_tag_too_low

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_202 [as 别名]
def test_on_post_start_outofholdoff_replies_outofsync_when_tag_too_low(
            self, mock_time):
        mock_time.time.return_value = 2000
        new_version = random.randint(0, 99)
        session_doc = common.get_fake_session_0()
        session_doc['time_start'] = 999
        self.mock_db.get_session.return_value = session_doc
        self.mock_db.update_session.return_value = new_version
        action = {"start": {
            "job_id": 'job_id_2',
            "current_tag": 2
        }}
        self.mock_json_body.return_value = action
        expected_result = {'result': 'out-of-sync',
                           'session_tag': 5}
        self.resource.on_post(self.mock_req, self.mock_req,
                              common.fake_session_0['session_id'])
        self.assertEqual(falcon.HTTP_202, self.mock_req.status)
        self.assertEqual(expected_result, self.mock_req.body) 
开发者ID:openstack,项目名称:freezer-api,代码行数:21,代码来源:test_sessions.py

示例8: test_on_post_start_action_ok

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_202 [as 别名]
def test_on_post_start_action_ok(self):
        new_version = random.randint(0, 99)
        self.mock_db.get_session.return_value = common.get_fake_session_0()
        self.mock_db.update_session.return_value = new_version
        action = {"start": {
            "job_id": 'job_id_2',
            "current_tag": 5
        }}
        self.mock_json_body.return_value = action
        expected_result = {'result': 'success',
                           'session_tag': 6}
        self.resource.on_post(self.mock_req, self.mock_req,
                              common.fake_session_0['project_id'],
                              common.fake_session_0['session_id'])
        self.assertEqual(falcon.HTTP_202, self.mock_req.status)
        self.assertEqual(expected_result, self.mock_req.body) 
开发者ID:openstack,项目名称:freezer-api,代码行数:18,代码来源:test_sessions.py

示例9: test_on_post_start_succeeds_in_holdoff_if_tag_needs_not_increment

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_202 [as 别名]
def test_on_post_start_succeeds_in_holdoff_if_tag_needs_not_increment(
            self, mock_time):
        mock_time.time.return_value = 1000
        new_version = random.randint(0, 99)
        session_doc = common.get_fake_session_0()
        session_doc['time_start'] = 999
        self.mock_db.get_session.return_value = session_doc
        self.mock_db.update_session.return_value = new_version
        action = {"start": {
            "job_id": 'job_id_2',
            "current_tag": 4
        }}
        self.mock_json_body.return_value = action
        expected_result = {'result': 'success',
                           'session_tag': 5}
        self.resource.on_post(self.mock_req, self.mock_req,
                              common.fake_session_0['project_id'],
                              common.fake_session_0['session_id'])
        self.assertEqual(falcon.HTTP_202, self.mock_req.status)
        self.assertEqual(expected_result, self.mock_req.body) 
开发者ID:openstack,项目名称:freezer-api,代码行数:22,代码来源:test_sessions.py

示例10: test_on_post_start_replies_holdoff_if_tag_would_increment

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_202 [as 别名]
def test_on_post_start_replies_holdoff_if_tag_would_increment(self,
                                                                  mock_time):
        mock_time.time.return_value = 1000
        new_version = random.randint(0, 99)
        session_doc = common.get_fake_session_0()
        session_doc['time_start'] = 999
        self.mock_db.get_session.return_value = session_doc
        self.mock_db.update_session.return_value = new_version
        action = {"start": {
            "job_id": 'ahahahahah',
            "current_tag": 5
        }}
        self.mock_json_body.return_value = action
        expected_result = {'result': 'hold-off',
                           'session_tag': 5}
        self.resource.on_post(self.mock_req, self.mock_req,
                              common.fake_session_0['project_id'],
                              common.fake_session_0['session_id'])
        self.assertEqual(falcon.HTTP_202, self.mock_req.status)
        self.assertEqual(expected_result, self.mock_req.body) 
开发者ID:openstack,项目名称:freezer-api,代码行数:22,代码来源:test_sessions.py

示例11: test_on_post_start_outofholdoff_replies_outofsync_when_tag_too_low

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_202 [as 别名]
def test_on_post_start_outofholdoff_replies_outofsync_when_tag_too_low(
            self, mock_time):
        mock_time.time.return_value = 2000
        new_version = random.randint(0, 99)
        session_doc = common.get_fake_session_0()
        session_doc['time_start'] = 999
        self.mock_db.get_session.return_value = session_doc
        self.mock_db.update_session.return_value = new_version
        action = {"start": {
            "job_id": 'ahahahahah',
            "current_tag": 2
        }}
        self.mock_json_body.return_value = action
        expected_result = {'result': 'out-of-sync',
                           'session_tag': 5}
        self.resource.on_post(self.mock_req, self.mock_req,
                              common.fake_session_0['project_id'],
                              common.fake_session_0['session_id'])
        self.assertEqual(falcon.HTTP_202, self.mock_req.status)
        self.assertEqual(expected_result, self.mock_req.body) 
开发者ID:openstack,项目名称:freezer-api,代码行数:22,代码来源:test_sessions.py

示例12: on_post

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_202 [as 别名]
def on_post(self, req, resp, project_id, session_id):
        # POST /v2/{project_id}/sessions/{session_id}/action
        # executes an action on the specified session

        user_id = req.get_header('X-User-ID') or ''
        doc = self.json_body(req)

        try:
            action, params = next(iter(doc.items()))
        except Exception:
            raise freezer_api_exc.BadDataFormat("Bad action request format")

        session_doc = self.db.get_session(project_id=project_id,
                                          user_id=user_id,
                                          session_id=session_id)
        session = Session(session_doc)
        session.execute_action(action, params)

        if session.need_update:
            self.db.update_session(project_id=project_id,
                                   user_id=user_id,
                                   session_id=session_id,
                                   patch_doc=session.doc)
        resp.status = falcon.HTTP_202
        resp.body = {'result': session.action_result,
                     'session_tag': session.session_tag} 
开发者ID:openstack,项目名称:freezer-api,代码行数:28,代码来源:sessions.py

示例13: test_on_post_start_event_ok

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_202 [as 别名]
def test_on_post_start_event_ok(self):
        new_version = random.randint(0, 99)
        self.mock_db.get_job.return_value = {
            'job_schedule': {
                'status': 'stop'
            }
        }
        self.mock_db.replace_job.return_value = new_version
        event = {"start": None}
        self.mock_json_body.return_value = event
        expected_result = {'result': 'success'}
        self.resource.on_post(self.mock_req, self.mock_req, 'my_job_id')
        self.assertEqual(falcon.HTTP_202, self.mock_req.status)
        self.assertEqual(expected_result, self.mock_req.body) 
开发者ID:openstack,项目名称:freezer-api,代码行数:16,代码来源:test_jobs.py

示例14: test_on_post_start_event_ok

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_202 [as 别名]
def test_on_post_start_event_ok(self):
        new_version = random.randint(0, 99)
        self.mock_db.get_job.return_value = {
            'job_schedule': {
                'status': 'stop'
            }
        }
        self.mock_db.replace_job.return_value = new_version
        event = {"start": None}
        self.mock_json_body.return_value = event
        expected_result = {'result': 'success'}
        self.resource.on_post(self.mock_req, self.mock_req,
                              'my_project_id', 'my_job_id')
        self.assertEqual(falcon.HTTP_202, self.mock_req.status)
        self.assertEqual(expected_result, self.mock_req.body) 
开发者ID:openstack,项目名称:freezer-api,代码行数:17,代码来源:test_jobs.py

示例15: on_post

# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_202 [as 别名]
def on_post(self, req, resp):
        """ Create a task. """
        raw_body = req.stream.read()
        request_error = self._validate_create_task(raw_body)
        if request_error:
            logging.warning(
                'Invalid request made. Reason: {}'.format(request_error)
            )
            resp.status = falcon.HTTP_400
            resp.media = {
                'message': request_error
            }
            return
        body = json.loads(raw_body.decode('utf-8'))
        model = body[MODEL]
        action = body[ACTION]
        callback_url = None
        if CALLBACK_URL in body:
            callback_url = body[CALLBACK_URL]
        since_date = body[SINCE_DATE] if SINCE_DATE in body else None
        task_id = str(uuid.uuid4())
        # Inject shared memory
        progress = Value('d', 0.0)
        finish_time = Value('d', 0.0)
        task = Task(
            model=model,
            task_type=TaskTypes[action],
            since_date=since_date,
            progress=progress,
            task_id=task_id,
            finish_time=finish_time,
            callback_url=callback_url
        )
        task.start()
        task_id = self.tracker \
            .add_task(task, task_id, action, progress, finish_time)
        base_url = self._get_base_url(req)
        status_url = base_url + '/task/{}'.format(task_id)
        # Give the task a moment to start so we can detect immediate failure.
        # TODO: Use IPC to detect if the job launched successfully instead
        # of giving it 100ms to crash. This is prone to race conditions.
        time.sleep(0.1)
        if task.is_alive():
            resp.status = falcon.HTTP_202
            resp.media = {
                'message': 'Successfully scheduled task',
                'task_id': task_id,
                'status_check': status_url
            }
            return
        else:
            resp.status = falcon.HTTP_500
            resp.media = {
                'message': 'Failed to schedule task due to an internal server '
                           'error. Check scheduler logs.'
            }
            return 
开发者ID:creativecommons,项目名称:cccatalog-api,代码行数:59,代码来源:api.py


注:本文中的falcon.HTTP_202属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。