當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。