Python falcon.HTTP_404 Examples

The following are 30 code examples of falcon.HTTP_404(). 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 vote down vote up
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: configdocs_helper.py    From shipyard with Apache License 2.0 6 votes vote down vote up
def _get_doc_from_buffer(self, collection_id, cleartext_secrets=False):
        """Returns the collection if it exists in the buffer.
        If the buffer contains the collection, the latest
        representation is what we want.
        """
        # Need to guard with this check for buffer to ensure
        # that the collection is not just carried through unmodified
        # into the buffer, and is actually represented.
        if self.is_collection_in_buffer(collection_id):
            # prior check for collection in buffer means the buffer
            # revision exists
            buffer_id = self.get_revision_id(BUFFER)
            return self.deckhand.get_docs_from_revision(
                revision_id=buffer_id, bucket_id=collection_id,
                cleartext_secrets=cleartext_secrets)
        raise ApiError(
            title='No documents to retrieve',
            description=('The Shipyard buffer is empty or does not contain '
                         'this collection'),
            status=falcon.HTTP_404,
            retry=False) 
Example #3
Source File: designs.py    From drydock with Apache License 2.0 6 votes vote down vote up
def on_get(self, req, resp, design_id):
        """Method Handler for GET design singleton.

        :param req: Falcon request object
        :param resp: Falcon response object
        :param design_id: UUID of the design resource
        """
        source = req.params.get('source', 'designed')

        try:
            design = None
            if source == 'compiled':
                design = self.orchestrator.get_effective_site(design_id)
            elif source == 'designed':
                design = self.orchestrator.get_described_site(design_id)

            resp.body = json.dumps(design.obj_to_simple())
        except errors.DesignError:
            self.error(req.context, "Design %s not found" % design_id)
            self.return_error(
                resp,
                falcon.HTTP_404,
                message="Design %s not found" % design_id,
                retry=False) 
Example #4
Source File: nodes.py    From drydock with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: actions_validations_id_api.py    From shipyard with Apache License 2.0 6 votes vote down vote up
def get_action_validation(self, action_id, validation_id):
        """
        Interacts with the shipyard database to return the requested
        validation information
        :returns: the validation dicitonary object
        """
        action = self.get_action_db(action_id=action_id)

        if action is None:
            raise ApiError(
                title='Action not found',
                description='Unknown action {}'.format(action_id),
                status=falcon.HTTP_404)

        validation = self.get_validation_db(validation_id=validation_id)
        if validation is not None:
            return validation

        # if we didn't find it, 404
        raise ApiError(
            title='Validation not found',
            description='Unknown validation {}'.format(validation_id),
            status=falcon.HTTP_404) 
Example #6
Source File: notedetails_api.py    From shipyard with Apache License 2.0 6 votes vote down vote up
def get_note_with_access_check(self, context, note_id):
        """Retrieve the note and checks user access to the note

        :param context: the request context
        :param note_id: the id of the note to retrieve.
        :returns: the note
        """
        try:
            note = notes_helper.get_note(note_id)
            note_type = notes_helper.get_note_assoc_id_type(note)
            if note_type not in NOTE_TYPE_RBAC:
                raise ApiError(
                    title="Unable to check permission for note type",
                    description=(
                        "Shipyard is not correctly identifying note type "
                        "for note {}".format(note_id)),
                    status=falcon.HTTP_500,
                    retry=False)
            policy.check_auth(context, NOTE_TYPE_RBAC[note_type])
            return note
        except NoteNotFoundError:
            raise ApiError(
                title="No note found",
                description=("Note {} is not found".format(note_id)),
                status=falcon.HTTP_404) 
Example #7
Source File: configdocs_helper.py    From shipyard with Apache License 2.0 6 votes vote down vote up
def _get_target_docs(self, collection_id, target_rev,
                         cleartext_secrets=False):
        """Returns the collection if it exists as committed, last_site_action
        or successful_site_action.
        """
        revision_id = self.get_revision_id(target_rev)

        if revision_id:
            return self.deckhand.get_docs_from_revision(
                revision_id=revision_id, bucket_id=collection_id,
                cleartext_secrets=cleartext_secrets)

        raise ApiError(
            title='No documents to retrieve',
            description=('No collection {} for revision '
                         '{}'.format(collection_id, target_rev)),
            status=falcon.HTTP_404,
            retry=False) 
Example #8
Source File: action_helper.py    From shipyard with Apache License 2.0 6 votes vote down vote up
def _get_dag_info(self):
        """
        returns: Dag Information
        """
        # Retrieve 'dag_id' and 'dag_execution_date'
        dag_id = self.action.get('dag_id')
        dag_execution_date = self.action.get('dag_execution_date')

        if not dag_id:
            raise ApiError(
                title='Dag ID Not Found!',
                description='Unable to retrieve Dag ID',
                status=falcon.HTTP_404)
        elif not dag_execution_date:
            raise ApiError(
                title='Execution Date Not Found!',
                description='Unable to retrieve Execution Date',
                status=falcon.HTTP_404)
        else:
            return dag_id, dag_execution_date 
Example #9
Source File: nodes.py    From drydock with Apache License 2.0 6 votes vote down vote up
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 #10
Source File: action_helper.py    From shipyard with Apache License 2.0 6 votes vote down vote up
def _get_all_steps(self):
        """
        returns: All steps for the action ID
        """
        # Retrieve dag_id and dag_execution_date
        dag_id, dag_execution_date = self._get_dag_info()

        # Retrieve the action steps
        steps = self._get_tasks_db(dag_id, dag_execution_date)

        if not steps:
            raise ApiError(
                title='Steps Not Found!',
                description='Unable to retrieve Information on Steps',
                status=falcon.HTTP_404)
        else:
            LOG.debug("%s steps found for action %s",
                      len(steps), self.action_id)
            LOG.debug("The steps for action %s are as follows:",
                      self.action_id)
            LOG.debug(steps)

            return steps 
Example #11
Source File: designs.py    From drydock with Apache License 2.0 6 votes vote down vote up
def on_get(self, req, resp, design_id):
        """Method Handler for GET design singleton.

        :param req: Falcon request object
        :param resp: Falcon response object
        :param design_id: UUID of the design resource
        """
        source = req.params.get('source', 'designed')

        try:
            design = None
            if source == 'compiled':
                design = self.orchestrator.get_effective_site(design_id)
            elif source == 'designed':
                design = self.orchestrator.get_described_site(design_id)

            resp.body = json.dumps(design.obj_to_simple())
        except errors.DesignError:
            self.error(req.context, "Design %s not found" % design_id)
            self.return_error(
                resp,
                falcon.HTTP_404,
                message="Design %s not found" % design_id,
                retry=False) 
Example #12
Source File: configdocs_helper.py    From shipyard with Apache License 2.0 5 votes vote down vote up
def get_rendered_configdocs(self, version=BUFFER, cleartext_secrets=False):
        """Returns the rendered configuration documents for the specified
        revision (by name BUFFER, COMMITTED, LAST_SITE_ACTION,
        SUCCESSFUL_SITE_ACTION)
        """
        revision_dict = self._get_revision_dict()

        # Raise Exceptions if we received unexpected version
        if version not in [BUFFER, COMMITTED, LAST_SITE_ACTION,
                           SUCCESSFUL_SITE_ACTION]:
            raise ApiError(
                title='Invalid version',
                description='{} is not a valid version'.format(version),
                status=falcon.HTTP_400,
                retry=False)

        if revision_dict.get(version):
            revision_id = revision_dict.get(version).get('id')

            try:
                return self.deckhand.get_rendered_docs_from_revision(
                    cleartext_secrets=cleartext_secrets,
                    revision_id=revision_id)
            except DeckhandError as de:
                raise ApiError(
                    title='Deckhand indicated an error while rendering',
                    description=de.response_message,
                    status=falcon.HTTP_500,
                    retry=False)

        else:
            raise ApiError(
                title='This revision does not exist',
                description='{} version does not exist'.format(version),
                status=falcon.HTTP_404,
                retry=False) 
Example #13
Source File: workflows_api.py    From shipyard with Apache License 2.0 5 votes vote down vote up
def get_workflow_detail(self, helper, workflow_id):
        """
        Retrieve a workflow by id,
        :param helper: The WorkflowHelper constructed for this invocation
        :param workflow_id: a string in {dag_id}__{execution_date} format
                            identifying a workflow
        :returns: a workflow detail dictionary including steps
        """
        if not WorkflowHelper.validate_workflow_id(workflow_id):
            raise ApiError(
                title='Invalid Workflow ID specified',
                description=(
                    'Workflow id must use {dag id}__{execution date} format',
                ),
                status=falcon.HTTP_400,
                retry=False,
            )
        workflow = helper.get_workflow(workflow_id=workflow_id)
        if workflow is None:
            raise ApiError(
                title='Workflow not found',
                description=(
                    'A Workflow with id {} was not found'.format(workflow_id),
                ),
                status=falcon.HTTP_404,
                retry=False,
            )
        return workflow 
Example #14
Source File: action_helper.py    From shipyard with Apache License 2.0 5 votes vote down vote up
def get_step(self, step_id, try_number=None):
        """
        :param step_id: Step ID - task_id in db
        :param try_number: Number of try - try_number in db

        returns: Step
        """
        # Retrieve step. Note that we will get a list and it will
        # be the content of step[0]
        step_list = [x for x in
                     self._get_all_steps()
                     if step_id == x['task_id'] and
                     (try_number is None or try_number == x['try_number'])
                     ]
        # try_number is needed to get correct task from correct worker
        # the worker host for request URL
        # is referenced in correct task's 'hostname' field

        if not step_list:
            raise ApiError(
                title='Step Not Found!',
                description='Unable to retrieve Step',
                status=falcon.HTTP_404)
        else:
            step = step_list[0]
            LOG.debug("Step Located:")
            LOG.debug(step)

            return step 
Example #15
Source File: test_actions_steps_id_logs_api.py    From shipyard with Apache License 2.0 5 votes vote down vote up
def test_retrieve_logs_404(self, mock_get):
        mock_get.return_value.status_code = 404
        action_logs_resource = ActionsStepsLogsResource()
        with pytest.raises(ApiError) as e:
            action_logs_resource.retrieve_logs(None)
        assert ('Airflow endpoint returned error status code' in
                e.value.description)
        assert falcon.HTTP_404 == e.value.status 
Example #16
Source File: harvester.py    From polkascan-pre-harvester with GNU General Public License v3.0 5 votes vote down vote up
def on_post(self, req, resp):

        resp.status = falcon.HTTP_404

        resp.media = {
            'status': 'success',
            'data': {
                'message': 'TODO'
            }
        } 
Example #17
Source File: tools.py    From polkascan-pre-harvester with GNU General Public License v3.0 5 votes vote down vote up
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 #18
Source File: tasks.py    From drydock with Apache License 2.0 5 votes vote down vote up
def on_get(self, req, resp, task_id):
        """Handler for GET method."""
        try:
            builddata = req.get_param_as_bool('builddata')
            subtask_errors = req.get_param_as_bool('subtaskerrors')
            try:
                layers = int(req.params.get('layers', '0'))
            except Exception as ex:
                layers = 0

            first_task = self.get_task(req, resp, task_id, builddata)

            if first_task is None:
                self.info(req.context, "Task %s does not exist" % task_id)
                self.return_error(
                    resp,
                    falcon.HTTP_404,
                    message="Task %s does not exist" % task_id,
                    retry=False)
            else:
                # If layers is passed in then it returns a dict of tasks instead of the task dict.
                if layers:
                    resp_data, errors = self.handle_layers(req, resp, task_id, builddata, subtask_errors, layers,
                                                           first_task)
                    # Includes subtask_errors if the query param 'subtaskerrors' is passed in as true.
                    if (subtask_errors):
                        resp_data['subtask_errors'] = errors
                else:
                    resp_data = first_task
                    # Includes subtask_errors if the query param 'subtaskerrors' is passed in as true.
                    if (subtask_errors):
                        _, errors = self.handle_layers(req, resp, task_id, False, subtask_errors, 1,
                                                       first_task)
                        resp_data['subtask_errors'] = errors

                resp.body = json.dumps(resp_data)
                resp.status = falcon.HTTP_200
        except Exception as ex:
            self.error(req.context, "Unknown error: %s" % (str(ex)))
            self.return_error(
                resp, falcon.HTTP_500, message="Unknown error", retry=False) 
Example #19
Source File: designs.py    From drydock with Apache License 2.0 5 votes vote down vote up
def on_get(self, req, resp, design_id, kind, name):
        source = req.params.get('source', 'designed')

        try:
            design = None
            if source == 'compiled':
                design = self.orchestrator.get_effective_site(design_id)
            elif source == 'designed':
                design = self.orchestrator.get_described_site(design_id)

            part = None
            if kind == 'Site':
                part = design.get_site()
            elif kind == 'Network':
                part = design.get_network(name)
            elif kind == 'NetworkLink':
                part = design.get_network_link(name)
            elif kind == 'HardwareProfile':
                part = design.get_hardware_profile(name)
            elif kind == 'HostProfile':
                part = design.get_host_profile(name)
            elif kind == 'BaremetalNode':
                part = design.get_baremetal_node(name)
            else:
                self.error(req.context, "Kind %s unknown" % kind)
                self.return_error(
                    resp,
                    falcon.HTTP_404,
                    message="Kind %s unknown" % kind,
                    retry=False)
                return

            resp.body = json.dumps(part.obj_to_simple())
        except errors.DesignError as dex:
            self.error(req.context, str(dex))
            self.return_error(
                resp, falcon.HTTP_404, message=str(dex), retry=False)
        except Exception as exc:
            self.error(req.context, str(exc))
            self.return_error(
                resp.falcon.HTTP_500, message=str(exc), retry=False) 
Example #20
Source File: python_service.py    From sagemaker-tensorflow-serving-container with Apache License 2.0 5 votes vote down vote up
def on_delete(self, req, res, model_name):  # pylint: disable=W0613
        if model_name not in self._model_tfs_pid:
            res.status = falcon.HTTP_404
            res.body = json.dumps({
                'error': 'Model {} is not loaded yet'.format(model_name)
            })
        else:
            try:
                self._model_tfs_pid[model_name].kill()
                os.remove('/sagemaker/tfs-config/{}/model-config.cfg'.format(model_name))
                os.rmdir('/sagemaker/tfs-config/{}'.format(model_name))
                release_rest_port = self._model_tfs_rest_port[model_name]
                release_grpc_port = self._model_tfs_grpc_port[model_name]
                with lock():
                    bisect.insort(self._tfs_ports['rest_port'], release_rest_port)
                    bisect.insort(self._tfs_ports['grpc_port'], release_grpc_port)
                del self._model_tfs_rest_port[model_name]
                del self._model_tfs_grpc_port[model_name]
                del self._model_tfs_pid[model_name]
                res.status = falcon.HTTP_200
                res.body = json.dumps({
                    'success': 'Successfully unloaded model {}.'.format(model_name)
                })
            except OSError as error:
                res.status = falcon.HTTP_500
                res.body = json.dumps({
                    'error': str(error)
                }).encode('utf-8') 
Example #21
Source File: python_service.py    From sagemaker-tensorflow-serving-container with Apache License 2.0 5 votes vote down vote up
def on_get(self, req, res, model_name=None):  # pylint: disable=W0613
        if model_name is None:
            models_info = {}
            uri = 'http://localhost:{}/v1/models/{}'
            for model, port in self._model_tfs_rest_port.items():
                try:
                    info = json.loads(requests.get(uri.format(port, model)).content)
                    models_info[model] = info
                except ValueError as e:
                    log.exception('exception handling request: {}'.format(e))
                    res.status = falcon.HTTP_500
                    res.body = json.dumps({
                        'error': str(e)
                    }).encode('utf-8')
            res.status = falcon.HTTP_200
            res.body = json.dumps(models_info)
        else:
            if model_name not in self._model_tfs_rest_port:
                res.status = falcon.HTTP_404
                res.body = json.dumps({
                    'error': 'Model {} is loaded yet.'.format(model_name)
                }).encode('utf-8')
            else:
                port = self._model_tfs_rest_port[model_name]
                uri = 'http://localhost:{}/v1/models/{}'.format(port, model_name)
                try:
                    info = requests.get(uri)
                    res.status = falcon.HTTP_200
                    res.body = json.dumps({
                        'model': info
                    }).encode('utf-8')
                except ValueError as e:
                    log.exception('exception handling GET models request.')
                    res.status = falcon.HTTP_500
                    res.body = json.dumps({
                        'error': str(e)
                    }).encode('utf-8') 
Example #22
Source File: python_service.py    From sagemaker-tensorflow-serving-container with Apache License 2.0 5 votes vote down vote up
def _handle_invocation_post(self, req, res, model_name=None):
        if SAGEMAKER_MULTI_MODEL_ENABLED:
            if model_name:
                if model_name not in self._model_tfs_rest_port:
                    res.status = falcon.HTTP_404
                    res.body = json.dumps({
                        'error': "Model {} is not loaded yet.".format(model_name)
                    })
                    return
                else:
                    log.info("model name: {}".format(model_name))
                    rest_port = self._model_tfs_rest_port[model_name]
                    log.info("rest port: {}".format(str(self._model_tfs_rest_port[model_name])))
                    grpc_port = self._model_tfs_grpc_port[model_name]
                    log.info("grpc port: {}".format(str(self._model_tfs_grpc_port[model_name])))
                    data, context = tfs_utils.parse_request(req, rest_port, grpc_port,
                                                            self._tfs_default_model_name,
                                                            model_name)
            else:
                res.status = falcon.HTTP_400
                res.body = json.dumps({
                    'error': 'Invocation request does not contain model name.'
                })
        else:
            data, context = tfs_utils.parse_request(req, self._tfs_rest_port, self._tfs_grpc_port,
                                                    self._tfs_default_model_name)

        try:
            res.status = falcon.HTTP_200
            res.body, res.content_type = self._handlers(data, context)
        except Exception as e:  # pylint: disable=broad-except
            log.exception('exception handling request: {}'.format(e))
            res.status = falcon.HTTP_500
            res.body = json.dumps({
                'error': str(e)
            }).encode('utf-8')  # pylint: disable=E1101 
Example #23
Source File: test_clients.py    From freezer-api with Apache License 2.0 5 votes vote down vote up
def test_on_get_return_no_result_and_404_when_not_found(self):
        self.mock_db.get_client.return_value = []
        self.mock_req.body = None
        self.resource.on_get(self.mock_req, self.mock_req,
                             common.fake_client_info_0['project_id'],
                             common.fake_client_info_0['client_id'])
        self.assertIsNone(self.mock_req.body)
        self.assertEqual(falcon.HTTP_404, self.mock_req.status) 
Example #24
Source File: test_actions.py    From freezer-api with Apache License 2.0 5 votes vote down vote up
def test_on_get_return_no_result_and_404_when_not_found(self):
        self.mock_db.get_action.return_value = None
        self.mock_req.body = None
        self.resource.on_get(self.mock_req, self.mock_req,
                             common.fake_action_0['project_id'],
                             common.fake_action_0['action_id'])
        self.assertIsNone(self.mock_req.body)
        self.assertEqual(falcon.HTTP_404, self.mock_req.status) 
Example #25
Source File: test_jobs.py    From freezer-api with Apache License 2.0 5 votes vote down vote up
def test_on_get_return_no_result_and_404_when_not_found(self):
        self.mock_req.body = None
        self.mock_db.get_job.return_value = None
        self.resource.on_get(self.mock_req, self.mock_req,
                             common.fake_job_0_project_id,
                             common.fake_job_0_job_id)
        self.assertIsNone(self.mock_req.body)
        self.assertEqual(falcon.HTTP_404, self.mock_req.status) 
Example #26
Source File: test_backups.py    From freezer-api with Apache License 2.0 5 votes vote down vote up
def test_on_get_return_no_result_and_404_when_not_found(self):
        self.mock_db.get_backup.return_value = []
        self.mock_req.body = None
        self.resource.on_get(self.mock_req, self.mock_req,
                             common.fake_data_0_wrapped_backup_metadata[
                                 'project_id'],
                             common.fake_data_0_wrapped_backup_metadata[
                                 'backup_id'])
        self.assertIsNone(self.mock_req.body)
        self.assertEqual(falcon.HTTP_404, self.mock_req.status) 
Example #27
Source File: test_clients.py    From freezer-api with Apache License 2.0 5 votes vote down vote up
def test_on_get_return_no_result_and_404_when_not_found(self):
        self.mock_db.get_client.return_value = []
        self.mock_req.body = None
        self.resource.on_get(self.mock_req, self.mock_req,
                             common.fake_client_info_0['client_id'])
        self.assertIsNone(self.mock_req.body)
        self.assertEqual(falcon.HTTP_404, self.mock_req.status) 
Example #28
Source File: test_actions.py    From freezer-api with Apache License 2.0 5 votes vote down vote up
def test_on_get_return_no_result_and_404_when_not_found(self):
        self.mock_db.get_action.return_value = None
        self.mock_req.body = None
        self.resource.on_get(self.mock_req, self.mock_req,
                             common.fake_action_0['action_id'])
        self.assertIsNone(self.mock_req.body)
        self.assertEqual(falcon.HTTP_404, self.mock_req.status) 
Example #29
Source File: test_jobs.py    From freezer-api with Apache License 2.0 5 votes vote down vote up
def test_on_get_return_no_result_and_404_when_not_found(self):
        self.mock_req.body = None
        self.mock_db.get_job.return_value = None
        self.resource.on_get(self.mock_req, self.mock_req,
                             common.fake_job_0_job_id)
        self.assertIsNone(self.mock_req.body)
        self.assertEqual(falcon.HTTP_404, self.mock_req.status) 
Example #30
Source File: test_backups.py    From freezer-api with Apache License 2.0 5 votes vote down vote up
def test_on_get_return_no_result_and_404_when_not_found(self):
        self.mock_db.get_backup.return_value = []
        self.mock_req.body = None
        self.resource.on_get(self.mock_req, self.mock_req,
                             common.fake_data_0_wrapped_backup_metadata[
                                 'backup_id'])
        self.assertIsNone(self.mock_req.body)
        self.assertEqual(falcon.HTTP_404, self.mock_req.status)