Python six.moves.http_client.NOT_FOUND Examples

The following are 30 code examples of six.moves.http_client.NOT_FOUND(). 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 six.moves.http_client , or try the search function .
Example #1
Source File: test_blob.py    From python-storage with Apache License 2.0 6 votes vote down vote up
def test_delete_wo_generation(self):
        BLOB_NAME = "blob-name"
        not_found_response = ({"status": http_client.NOT_FOUND}, b"")
        connection = _Connection(not_found_response)
        client = _Client(connection)
        bucket = _Bucket(client)
        blob = self._make_one(BLOB_NAME, bucket=bucket)
        bucket._blobs[BLOB_NAME] = 1
        blob.delete()
        self.assertFalse(blob.exists())
        self.assertEqual(
            bucket._deleted,
            [
                (
                    BLOB_NAME,
                    None,
                    None,
                    self._get_default_timeout(),
                    None,
                    None,
                    None,
                    None,
                )
            ],
        ) 
Example #2
Source File: restclient.py    From manila with Apache License 2.0 6 votes vote down vote up
def _authorize(self):
        """Performs authorization setting x-auth-session."""
        self.headers['authorization'] = 'Basic %s' % self.auth_str
        if 'x-auth-session' in self.headers:
            del self.headers['x-auth-session']

        try:
            result = self.post("/access/v1")
            del self.headers['authorization']
            if result.status == http_client.CREATED:
                self.headers['x-auth-session'] = (
                    result.get_header('x-auth-session'))
                self.do_logout = True
                log_debug_msg(self, ('ZFSSA version: %s')
                              % result.get_header('x-zfssa-version'))

            elif result.status == http_client.NOT_FOUND:
                raise RestClientError(result.status, name="ERR_RESTError",
                                      message=("REST Not Available:"
                                               "Please Upgrade"))

        except RestClientError:
            del self.headers['authorization']
            raise 
Example #3
Source File: test__upload.py    From google-resumable-media-python with Apache License 2.0 6 votes vote down vote up
def test__process_response_bad_status(self):
        upload = _upload.ResumableUpload(RESUMABLE_URL, ONE_MB)
        _fix_up_virtual(upload)

        # Make sure the upload is valid before the failure.
        assert not upload.invalid
        response = _make_response(status_code=http_client.NOT_FOUND)
        with pytest.raises(common.InvalidResponse) as exc_info:
            upload._process_response(response, None)

        error = exc_info.value
        assert error.response is response
        assert len(error.args) == 5
        assert error.args[1] == response.status_code
        assert error.args[3] == http_client.OK
        assert error.args[4] == resumable_media.PERMANENT_REDIRECT
        # Make sure the upload is invalid after the failure.
        assert upload.invalid 
Example #4
Source File: test__download.py    From google-resumable-media-python with Apache License 2.0 6 votes vote down vote up
def test__process_response_bad_status(self):
        download = _download.Download(EXAMPLE_URL)
        _fix_up_virtual(download)

        # Make sure **not finished** before.
        assert not download.finished
        response = mock.Mock(
            status_code=int(http_client.NOT_FOUND), spec=["status_code"]
        )
        with pytest.raises(common.InvalidResponse) as exc_info:
            download._process_response(response)

        error = exc_info.value
        assert error.response is response
        assert len(error.args) == 5
        assert error.args[1] == response.status_code
        assert error.args[3] == http_client.OK
        assert error.args[4] == http_client.PARTIAL_CONTENT
        # Make sure **finished** even after a failure.
        assert download.finished 
Example #5
Source File: test_controller.py    From tacker with Apache License 2.0 6 votes vote down vote up
def test_terminate_non_existing_vnf_instance(self, mock_vnf_by_id):
        body = {'terminationType': 'GRACEFUL',
                'gracefulTerminationTimeout': 10}
        mock_vnf_by_id.side_effect = exceptions.VnfInstanceNotFound
        req = fake_request.HTTPRequest.blank(
            '/vnf_instances/%s/terminate' % uuidsentinel.vnf_instance_id)
        req.body = jsonutils.dump_as_bytes(body)
        req.headers['Content-Type'] = 'application/json'
        req.method = 'POST'

        resp = req.get_response(self.app)

        self.assertEqual(http_client.NOT_FOUND, resp.status_code)
        self.assertEqual("Can not find requested vnf instance: %s" %
            uuidsentinel.vnf_instance_id,
            resp.json['itemNotFound']['message']) 
Example #6
Source File: test_blob.py    From python-storage with Apache License 2.0 6 votes vote down vote up
def test_exists_miss(self):
        NONESUCH = "nonesuch"
        not_found_response = ({"status": http_client.NOT_FOUND}, b"")
        connection = _Connection(not_found_response)
        client = _Client(connection)
        bucket = _Bucket(client)
        blob = self._make_one(NONESUCH, bucket=bucket)
        self.assertFalse(blob.exists(timeout=42))
        self.assertEqual(len(connection._requested), 1)
        self.assertEqual(
            connection._requested[0],
            {
                "method": "GET",
                "path": "/b/name/o/{}".format(NONESUCH),
                "query_params": {"fields": "name"},
                "_target_object": None,
                "timeout": 42,
            },
        ) 
Example #7
Source File: test_controller.py    From tacker with Apache License 2.0 6 votes vote down vote up
def test_instantiate_with_non_existing_vnf_instance(
            self, mock_vnf_by_id):
        mock_vnf_by_id.side_effect = exceptions.VnfInstanceNotFound
        body = {"flavourId": "simple"}
        req = fake_request.HTTPRequest.blank(
            '/vnf_instances/%s/instantiate' % uuidsentinel.vnf_instance_id)
        req.body = jsonutils.dump_as_bytes(body)
        req.headers['Content-Type'] = 'application/json'
        req.method = 'POST'

        # Call Instantiate API
        resp = req.get_response(self.app)

        self.assertEqual(http_client.NOT_FOUND, resp.status_code)
        self.assertEqual("Can not find requested vnf instance: %s" %
                         uuidsentinel.vnf_instance_id,
                         resp.json['itemNotFound']['message']) 
Example #8
Source File: store.py    From glance_store with Apache License 2.0 6 votes vote down vote up
def _get_object(self, location, manager, start=None):
        headers = {}
        if start is not None:
            bytes_range = 'bytes=%d-' % start
            headers = {'Range': bytes_range}

        try:
            resp_headers, resp_body = manager.get_connection().get_object(
                location.container, location.obj,
                resp_chunk_size=self.CHUNKSIZE, headers=headers)
        except swiftclient.ClientException as e:
            if e.http_status == http_client.NOT_FOUND:
                msg = _("Swift could not find object %s.") % location.obj
                LOG.warning(msg)
                raise exceptions.NotFound(message=msg)
            else:
                raise

        return (resp_headers, resp_body) 
Example #9
Source File: nodeinfo.py    From treadmill with Apache License 2.0 6 votes vote down vote up
def init(api, _cors, impl):
    """Configures REST handlers for allocation resource."""

    namespace = webutils.namespace(
        api, __name__, 'Local nodeinfo redirect API.'
    )

    @namespace.route('/<hostname>/<path:path>')
    class _NodeRedirect(restplus.Resource):
        """Redirects to local nodeinfo endpoint."""

        def get(self, hostname, path):
            """Returns list of local instances."""
            hostport = impl.get(hostname)
            if not hostport:
                return 'Host not found.', http_client.NOT_FOUND

            url = utils.encode_uri_parts(path)
            return flask.redirect('http://%s/%s' % (hostport, url),
                                  code=http_client.FOUND) 
Example #10
Source File: test_run.py    From column with GNU General Public License v3.0 6 votes vote down vote up
def _test_get_run_by_id(self):
        response = self.app.get('/runs/1234')
        self.assertEqual(http_client.NOT_FOUND, response.status_code)

        pb = 'tests/fixtures/playbooks/hello_world.yml'
        response = self.app.post(
            '/runs',
            data=json.dumps(dict(playbook_path=pb,
                                 inventory_file='localhosti,',
                                 options={'connection': 'local'})),
            content_type='application/json')
        res_dict = json.loads(response.data)
        run_id = res_dict['id']
        self.assertEqual(http_client.CREATED, response.status_code)
        response = self.app.get('/runs/{}'.format(run_id))
        self.assertEqual(http_client.OK, response.status_code)
        self._wait_for_run_complete(run_id) 
Example #11
Source File: timers.py    From st2 with Apache License 2.0 6 votes vote down vote up
def get_one(self, ref_or_id, requester_user):
        try:
            trigger_db = self._get_by_ref_or_id(ref_or_id=ref_or_id)
        except Exception as e:
            LOG.exception(six.text_type(e))
            abort(http_client.NOT_FOUND, six.text_type(e))
            return

        permission_type = PermissionType.TIMER_VIEW
        resource_db = TimerDB(pack=trigger_db.pack, name=trigger_db.name)

        rbac_utils = get_rbac_backend().get_utils_class()
        rbac_utils.assert_user_has_resource_db_permission(user_db=requester_user,
                                                          resource_db=resource_db,
                                                          permission_type=permission_type)

        result = self.model.from_model(trigger_db)
        return result 
Example #12
Source File: core.py    From osbs-client with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def wait_for_new_build_config_instance(self, build_config_id, prev_version):
        logger.info("waiting for build config %s to get instantiated", build_config_id)
        for changetype, obj in self.watch_resource("buildconfigs", build_config_id):
            if changetype in (None, WATCH_MODIFIED):
                version = graceful_chain_get(obj, 'status', 'lastVersion')
                if not isinstance(version, numbers.Integral):
                    logger.error("BuildConfig %s has unexpected lastVersion: %s", build_config_id,
                                 version)
                    continue

                if version > prev_version:
                    return "%s-%s" % (build_config_id, version)

            if changetype == WATCH_DELETED:
                logger.error("BuildConfig deleted while waiting for new build instance")
                break

        raise OsbsResponseException("New BuildConfig instance not found",
                                    http_client.NOT_FOUND) 
Example #13
Source File: test_controller.py    From tacker with Apache License 2.0 5 votes vote down vote up
def test_delete_with_invalid_uuid(self):
        req = fake_request.HTTPRequest.blank(
            '/vnf_instances/%s' % constants.INVALID_UUID)
        req.method = 'DELETE'

        # Call delete API
        resp = req.get_response(self.app)

        self.assertEqual(http_client.NOT_FOUND, resp.status_code)
        self.assertEqual("Can not find requested vnf instance: %s" %
            constants.INVALID_UUID,
            resp.json['itemNotFound']['message']) 
Example #14
Source File: test_packs_views.py    From st2 with Apache License 2.0 5 votes vote down vote up
def test_get_pack_file_pack_doesnt_exist(self):
        resp = self.app.get('/v1/packs/views/files/doesntexist/pack.yaml', expect_errors=True)
        self.assertEqual(resp.status_int, http_client.NOT_FOUND) 
Example #15
Source File: test_packs_views.py    From st2 with Apache License 2.0 5 votes vote down vote up
def test_get_pack_files_pack_doesnt_exist(self):
        resp = self.app.get('/v1/packs/views/files/doesntexist', expect_errors=True)
        self.assertEqual(resp.status_int, http_client.NOT_FOUND) 
Example #16
Source File: core.py    From st2 with Apache License 2.0 5 votes vote down vote up
def delete_by_id(self, instance_id, **kwargs):
        url = '/%s/%s' % (self.resource.get_url_path_name(), instance_id)
        response = self.client.delete(url, **kwargs)
        if response.status_code not in [http_client.OK,
                                        http_client.NO_CONTENT,
                                        http_client.NOT_FOUND]:
            self.handle_error(response)
            return False
        try:
            resp_json = response.json()
            if resp_json:
                return resp_json
        except:
            pass
        return True 
Example #17
Source File: test_inquiries.py    From st2 with Apache License 2.0 5 votes vote down vote up
def test_get_one_failed(self):
        """Test failed retrieval of an Inquiry
        """
        inquiry_id = 'asdfeoijasdf'
        get_resp = self._do_get_one(inquiry_id, expect_errors=True)
        self.assertEqual(get_resp.status_int, http_client.NOT_FOUND)
        self.assertIn('resource could not be found', get_resp.json['faultstring']) 
Example #18
Source File: test_policies.py    From st2 with Apache License 2.0 5 votes vote down vote up
def test_delete_not_found(self):
        del_resp = self.__do_delete('12345')
        self.assertEqual(del_resp.status_int, http_client.NOT_FOUND) 
Example #19
Source File: state_test.py    From treadmill with Apache License 2.0 5 votes vote down vote up
def test_get_state_notfound(self):
        """Test getting an instance state (not found)."""
        self.impl.get.return_value = None
        resp = self.client.get('/state/foo.bar#0000000002')
        self.assertEqual(resp.status_code, http_client.NOT_FOUND) 
Example #20
Source File: transfer.py    From apitools with Apache License 2.0 5 votes vote down vote up
def __ProcessResponse(self, response):
        """Process response (by updating self and writing to self.stream)."""
        if response.status_code not in self._ACCEPTABLE_STATUSES:
            # We distinguish errors that mean we made a mistake in setting
            # up the transfer versus something we should attempt again.
            if response.status_code in (http_client.FORBIDDEN,
                                        http_client.NOT_FOUND):
                raise exceptions.HttpError.FromResponse(response)
            else:
                raise exceptions.TransferRetryError(response.content)
        if response.status_code in (http_client.OK,
                                    http_client.PARTIAL_CONTENT):
            try:
                self.stream.write(six.ensure_binary(response.content))
            except TypeError:
                self.stream.write(six.ensure_text(response.content))
            self.__progress += response.length
            if response.info and 'content-encoding' in response.info:
                # TODO(craigcitro): Handle the case where this changes over a
                # download.
                self.__encoding = response.info['content-encoding']
        elif response.status_code == http_client.NO_CONTENT:
            # It's important to write something to the stream for the case
            # of a 0-byte download to a file, as otherwise python won't
            # create the file.
            self.stream.write('')
        return response 
Example #21
Source File: test_policies.py    From st2 with Apache License 2.0 5 votes vote down vote up
def test_put_not_found(self):
        updated_input = self.__create_instance()
        put_resp = self.__do_put('12345', updated_input)
        self.assertEqual(put_resp.status_int, http_client.NOT_FOUND) 
Example #22
Source File: inquiries.py    From st2 with Apache License 2.0 5 votes vote down vote up
def get_one(self, inquiry_id, requester_user=None):
        """Retrieve a single Inquiry

            Handles requests:
                GET /inquiries/<inquiry id>
        """

        # Retrieve the inquiry by id.
        # (Passing permission_type here leverages inquiry service built-in RBAC assertions)
        try:
            inquiry = self._get_one_by_id(
                id=inquiry_id,
                requester_user=requester_user,
                permission_type=rbac_types.PermissionType.INQUIRY_VIEW
            )
        except db_exceptions.StackStormDBObjectNotFoundError as e:
            LOG.exception('Unable to identify inquiry with id "%s".' % inquiry_id)
            api_router.abort(http_client.NOT_FOUND, six.text_type(e))
        except rbac_exceptions.ResourceAccessDeniedError as e:
            LOG.exception('User is denied access to inquiry "%s".' % inquiry_id)
            api_router.abort(http_client.FORBIDDEN, six.text_type(e))
        except Exception as e:
            LOG.exception('Unable to get record for inquiry "%s".' % inquiry_id)
            api_router.abort(http_client.INTERNAL_SERVER_ERROR, six.text_type(e))

        try:
            inquiry_service.check_inquiry(inquiry)
        except Exception as e:
            api_router.abort(http_client.BAD_REQUEST, six.text_type(e))

        return inqy_api_models.InquiryResponseAPI.from_inquiry_api(inquiry) 
Example #23
Source File: test_controller.py    From tacker with Apache License 2.0 5 votes vote down vote up
def test_show_with_invalid_uuid(self):
        req = fake_request.HTTPRequest.blank(
            '/vnf_instances/%s' % constants.INVALID_UUID)

        resp = req.get_response(self.app)
        self.assertEqual(http_client.NOT_FOUND, resp.status_code)
        self.assertEqual("Can not find requested vnf instance: %s" %
            constants.INVALID_UUID, resp.json['itemNotFound']['message']) 
Example #24
Source File: test_controller.py    From tacker with Apache License 2.0 5 votes vote down vote up
def test_show_with_non_existing_vnf_instance(self, mock_vnf_by_id):
        mock_vnf_by_id.side_effect = exceptions.VnfInstanceNotFound
        req = fake_request.HTTPRequest.blank(
            '/vnf_instances/%s' % uuidsentinel.vnf_instance_id)

        resp = req.get_response(self.app)

        self.assertEqual(http_client.NOT_FOUND, resp.status_code)
        self.assertEqual("Can not find requested vnf instance: %s" %
            uuidsentinel.vnf_instance_id,
            resp.json['itemNotFound']['message']) 
Example #25
Source File: test_controller.py    From tacker with Apache License 2.0 5 votes vote down vote up
def test_instantiate_with_invalid_uuid(self):
        req = fake_request.HTTPRequest.blank(
            '/vnf_instances/%s/instantiate' % constants.INVALID_UUID)
        body = {"flavourId": "simple"}
        req.body = jsonutils.dump_as_bytes(body)
        req.headers['Content-Type'] = 'application/json'
        req.method = 'POST'

        # Call Instantiate API
        resp = req.get_response(self.app)

        self.assertEqual(http_client.NOT_FOUND, resp.status_code)
        self.assertEqual(
            "Can not find requested vnf instance: %s" % constants.INVALID_UUID,
            resp.json['itemNotFound']['message']) 
Example #26
Source File: test_wsgi.py    From masakari with Apache License 2.0 5 votes vote down vote up
def test_override_default_code(self):
        robj = wsgi.ResponseObject({}, code=http.NOT_FOUND)
        self.assertEqual(robj.code, http.NOT_FOUND) 
Example #27
Source File: test_versions.py    From masakari with Apache License 2.0 5 votes vote down vote up
def test_get_version_1_versions_invalid(self, mock_get_client):
        req = webob.Request.blank('/v1/versions/1234/foo')
        req.accept = "application/json"
        res = req.get_response(self.wsgi_app)
        self.assertEqual(http.NOT_FOUND, res.status_int) 
Example #28
Source File: test_extensions.py    From masakari with Apache License 2.0 5 votes vote down vote up
def test_extensions_unexpected_policy_not_authorized_error(self):
        @extensions.expected_errors(http.NOT_FOUND)
        def fake_func():
            raise exception.PolicyNotAuthorized(action="foo")

        self.assertRaises(exception.PolicyNotAuthorized, fake_func) 
Example #29
Source File: test_extensions.py    From masakari with Apache License 2.0 5 votes vote down vote up
def test_extensions_unexpected_error_from_list(self):
        @extensions.expected_errors((http.NOT_FOUND,
                                     http.REQUEST_ENTITY_TOO_LARGE))
        def fake_func():
            raise webob.exc.HTTPConflict()

        self.assertRaises(webob.exc.HTTPInternalServerError, fake_func) 
Example #30
Source File: test_extensions.py    From masakari with Apache License 2.0 5 votes vote down vote up
def test_extensions_unexpected_error(self):
        @extensions.expected_errors(http.NOT_FOUND)
        def fake_func():
            raise webob.exc.HTTPConflict()

        self.assertRaises(webob.exc.HTTPInternalServerError, fake_func)