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


Python Request.blank方法代码示例

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


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

示例1: test_admin_setup

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
    def test_admin_setup(self):
        # PUTs for account and 16 .hash's
        self.test_origin.app = FakeApp(iter([("204 No Content", {}, "") for i in xrange(102)]))
        resp = Request.blank(
            "/origin/.prep",
            environ={"REQUEST_METHOD": "PUT"},
            headers={"X-Origin-Admin-User": ".origin_admin", "X-Origin-Admin-Key": "unittest"},
        ).get_response(self.test_origin)
        self.assertEquals(resp.status_int, 204)
        self.assertEquals(self.test_origin.app.calls, 101)

        self.test_origin.app = FakeApp(iter([("404 Not Found", {}, "")]))
        req = Request.blank(
            "/origin/.prep",
            environ={"REQUEST_METHOD": "PUT"},
            headers={"X-Origin-Admin-User": ".origin_admin", "X-Origin-Admin-Key": "unittest"},
        )
        self.assertRaises(Exception, req.get_response, self.test_origin)

        self.test_origin.app = FakeApp(iter([("204 No Content", {}, ""), ("404 Not Found", {}, "")]))
        req = Request.blank(
            "/origin/.prep",
            environ={"REQUEST_METHOD": "PUT"},
            headers={"X-Origin-Admin-User": ".origin_admin", "X-Origin-Admin-Key": "unittest"},
        )
        self.assertRaises(Exception, req.get_response, self.test_origin)
开发者ID:pandemicsyn,项目名称:sos,代码行数:28,代码来源:test_origin.py

示例2: make_pre_authed_request

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
def make_pre_authed_request(env, method, path, body=None, headers=None, agent="Swift"):
    """
    Makes a new webob.Request based on the current env but with the
    parameters specified. Note that this request will be preauthorized.

    :param env: Current WSGI environment dictionary
    :param method: HTTP method of new request
    :param path: HTTP path of new request
    :param body: HTTP body of new request; None by default
    :param headers: Extra HTTP headers of new request; None by default

    :returns: webob.Request object

    (Stolen from Swauth: https://github.com/gholt/swauth)
    """
    newenv = {"REQUEST_METHOD": method, "HTTP_USER_AGENT": agent}
    for name in ("swift.cache", "swift.trans_id"):
        if name in env:
            newenv[name] = env[name]
    newenv["swift.authorize"] = lambda req: None
    if not headers:
        headers = {}
    if body:
        return Request.blank(path, environ=newenv, body=body, headers=headers)
    else:
        return Request.blank(path, environ=newenv, headers=headers)
开发者ID:lixmgl,项目名称:Intern_OpenStack_Swift,代码行数:28,代码来源:wsgi.py

示例3: test_GET_empty_account_plain

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
 def test_GET_empty_account_plain(self):
     req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'PUT',
         'HTTP_X_TIMESTAMP': '0'})
     self.controller.PUT(req)
     req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'GET'})
     resp = self.controller.GET(req)
     self.assertEquals(resp.status_int, 204)
开发者ID:colecrawford,项目名称:swift,代码行数:9,代码来源:test_server.py

示例4: test_origin_db_valid_setup

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
    def test_origin_db_valid_setup(self):
        fake_conf = FakeConf(data=['[sos]',
            'origin_cdn_host_suffixes = origin_cdn.com'])
        test_origin = origin.filter_factory(
            {'sos_conf': fake_conf})(FakeApp())
        resp = Request.blank('http://origin_db.com:8080/v1/acc/cont',
            environ={'REQUEST_METHOD': 'POST'}).get_response(test_origin)
        self.assertEquals(resp.status_int, 404)

        fake_conf = FakeConf(data='''[sos]
origin_admin_key = unittest
origin_cdn_host_suffixes = origin_cdn.com
origin_db_hosts = origin_db.com
origin_account = .origin
max_cdn_file_size = 0
'''.split('\n'))
        test_origin = origin.filter_factory(
            {'sos_conf': fake_conf})(FakeApp())
        resp = Request.blank('http://origin_db.com:8080/v1/acc/cont',
            environ={'REQUEST_METHOD': 'POST'}).get_response(test_origin)
        self.assertEquals(resp.status_int, 500)

        fake_conf = FakeConf(data='''[sos]
origin_admin_key = unittest
origin_db_hosts = origin_db.com
origin_account = .origin
max_cdn_file_size = 0
'''.split('\n'))
        factory = origin.filter_factory(
            {'sos_conf': fake_conf})
        self.assertRaises(origin.InvalidConfiguration, factory, FakeApp())
开发者ID:dhersam,项目名称:sos,代码行数:33,代码来源:test_origin.py

示例5: test_cdn_get_no_content

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
    def test_cdn_get_no_content(self):
        prev_data = json.dumps({'account': 'acc', 'container': 'cont',
                'ttl': 1234, 'logs_enabled': True, 'cdn_enabled': True})
        self.test_origin.app = FakeApp(iter([
            ('204 No Content', {}, prev_data), # call to _get_cdn_data
            ('304 No Content', {}, '')])) #call to get obj
        req = Request.blank('http://1234.r34.origin_cdn.com:8080/obj1.jpg',
            environ={'REQUEST_METHOD': 'HEAD',
                     'swift.cdn_hash': 'abcd',
                     'swift.cdn_object_name': 'obj1.jpg'})
        resp = req.get_response(self.test_origin)
        self.assertEquals(resp.status_int, 304)

        self.test_origin.app = FakeApp(iter([
            ('204 No Content', {}, prev_data), # call to _get_cdn_data
            ('404 No Content', {}, '')])) #call to get obj
        req = Request.blank('http://1234.r34.origin_cdn.com:8080/obj1.jpg',
            environ={'REQUEST_METHOD': 'HEAD',
                     'swift.cdn_hash': 'abcd',
                     'swift.cdn_object_name': 'obj1.jpg'})
        resp = req.get_response(self.test_origin)
        self.assertEquals(resp.status_int, 404)

        self.test_origin.app = FakeApp(iter([
            ('204 No Content', {}, prev_data), # call to _get_cdn_data
            ('416 No Content', {}, '')])) #call to get obj
        req = Request.blank('http://1234.r34.origin_cdn.com:8080/obj1.jpg',
            environ={'REQUEST_METHOD': 'HEAD',
                     'swift.cdn_hash': 'abcd',
                     'swift.cdn_object_name': 'obj1.jpg'})
        resp = req.get_response(self.test_origin)
        self.assertEquals(resp.status_int, 416)
开发者ID:dhersam,项目名称:sos,代码行数:34,代码来源:test_origin.py

示例6: test_xml_transcript

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
    def test_xml_transcript(self):
        """
        Set data_dir and remove runtime modulestore to simulate an XMLModuelStore course.
        Then run the same tests as static_asset_path run.
        """
        # Simulate XMLModuleStore xmodule
        self.item_descriptor.data_dir = 'dummy/static'
        del self.item_descriptor.runtime.modulestore

        self.assertFalse(self.course.static_asset_path)

        # Test youtube style en
        request = Request.blank('/translation/en?videoId=12345')
        response = self.item.transcript(request=request, dispatch='translation/en')
        self.assertEqual(response.status, '307 Temporary Redirect')
        self.assertIn(
            ('Location', '/static/dummy/static/subs_12345.srt.sjson'),
            response.headerlist
        )

        # Test HTML5 video style
        self.item.sub = 'OEoXaMPEzfM'
        request = Request.blank('/translation/en')
        response = self.item.transcript(request=request, dispatch='translation/en')
        self.assertEqual(response.status, '307 Temporary Redirect')
        self.assertIn(
            ('Location', '/static/dummy/static/subs_OEoXaMPEzfM.srt.sjson'),
            response.headerlist
        )

        # Test different language to ensure we are just ignoring it since we can't
        # translate with static fallback
        request = Request.blank('/translation/uk')
        response = self.item.transcript(request=request, dispatch='translation/uk')
        self.assertEqual(response.status, '404 Not Found')
开发者ID:AshWilliams,项目名称:edx-platform,代码行数:37,代码来源:test_video_handlers.py

示例7: test_bucket_GET_max_keys

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
    def test_bucket_GET_max_keys(self):
        class FakeApp(object):
            def __call__(self, env, start_response):
                self.query_string = env['QUERY_STRING']
                start_response('200 OK', [])
                return '[]'
        fake_app = FakeApp()
        local_app = swift3.filter_factory({})(fake_app)
        bucket_name = 'junk'

        req = Request.blank('/%s' % bucket_name,
                environ={'REQUEST_METHOD': 'GET',
                         'QUERY_STRING': 'max-keys=5'},
                headers={'Authorization': 'AWS test:tester:hmac'})
        resp = local_app(req.environ, lambda *args: None)
        dom = xml.dom.minidom.parseString("".join(resp))
        self.assertEquals(dom.getElementsByTagName('MaxKeys')[0].
                childNodes[0].nodeValue, '5')
        args = dict(cgi.parse_qsl(fake_app.query_string))
        self.assert_(args['limit'] == '6')

        req = Request.blank('/%s' % bucket_name,
                environ={'REQUEST_METHOD': 'GET',
                         'QUERY_STRING': 'max-keys=5000'},
                headers={'Authorization': 'AWS test:tester:hmac'})
        resp = local_app(req.environ, lambda *args: None)
        dom = xml.dom.minidom.parseString("".join(resp))
        self.assertEquals(dom.getElementsByTagName('MaxKeys')[0].
                childNodes[0].nodeValue, '1000')
        args = dict(cgi.parse_qsl(fake_app.query_string))
        self.assertEquals(args['limit'], '1001')
开发者ID:lixmgl,项目名称:Intern_OpenStack_Swift,代码行数:33,代码来源:test_swift3.py

示例8: test_param_guard

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
    def test_param_guard(self):
        r = route(
            "/news/{id:int}/", "target",
            guards=qs(q=opt(String), page=opt(Int)))

        req = Request.blank("/news/42/")
        tr = r(req)
        self.assertEqual(
            (tr.args, tr.kwargs, tr.target),
            ((42,), {}, "target"))

        req = Request.blank("/news/42/?q=search")
        tr = r(req)
        self.assertEqual(
            (tr.args, tr.kwargs.items(), tr.target),
            ((42,), [("q", "search")], "target"))

        req = Request.blank("/news/42/?q=search&page=100")
        tr = r(req)
        self.assertEqual(
            (tr.args, tr.kwargs.items(), tr.target),
            ((42,), [("q", "search"), ("page", 100)], "target"))

        self.assertRaises(
            exc.HTTPBadRequest,
            r, Request.blank("/news/42/?q=search&page=aa"))
开发者ID:FedericoCeratto,项目名称:routr,代码行数:28,代码来源:tests.py

示例9: test_group_inexact_pattern

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
    def test_group_inexact_pattern(self):
        r = route("news",
                route("{id:int}",
                    route("comments", "view")))
        req = Request.blank("/news/42/comments")
        tr = r(req)
        self.assertEqual(
                (tr.args, tr.kwargs, tr.endpoint.target),
                ((42,), {}, "view"))

        r = route("news/{id:int}",
                route("comments", "view"))
        req = Request.blank("/news/42/comments")
        tr = r(req)
        self.assertEqual(
                (tr.args, tr.kwargs, tr.endpoint.target),
                ((42,), {}, "view"))

        r = route("news",
                route("{id:int}/comments", "view"))
        req = Request.blank("/news/42/comments")
        tr = r(req)
        self.assertEqual(
                (tr.args, tr.kwargs, tr.endpoint.target),
                ((42,), {}, "view"))
开发者ID:FedericoCeratto,项目名称:routr,代码行数:27,代码来源:tests.py

示例10: test_translation_static_transcript_xml_with_data_dirc

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
    def test_translation_static_transcript_xml_with_data_dirc(self):
        """
        Test id data_dir is set in XML course.

        Set course data_dir and ensure we get redirected to that path
        if it isn't found in the contentstore.
        """
        # Simulate data_dir set in course.
        test_modulestore = MagicMock()
        attrs = {"get_course.return_value": Mock(data_dir="dummy/static", static_asset_path="")}
        test_modulestore.configure_mock(**attrs)
        self.item_descriptor.runtime.modulestore = test_modulestore

        # Test youtube style en
        request = Request.blank("/translation/en?videoId=12345")
        response = self.item.transcript(request=request, dispatch="translation/en")
        self.assertEqual(response.status, "307 Temporary Redirect")
        self.assertIn(("Location", "/static/dummy/static/subs_12345.srt.sjson"), response.headerlist)

        # Test HTML5 video style
        self.item.sub = "OEoXaMPEzfM"
        request = Request.blank("/translation/en")
        response = self.item.transcript(request=request, dispatch="translation/en")
        self.assertEqual(response.status, "307 Temporary Redirect")
        self.assertIn(("Location", "/static/dummy/static/subs_OEoXaMPEzfM.srt.sjson"), response.headerlist)

        # Test different language to ensure we are just ignoring it since we can't
        # translate with static fallback
        request = Request.blank("/translation/uk")
        response = self.item.transcript(request=request, dispatch="translation/uk")
        self.assertEqual(response.status, "404 Not Found")
开发者ID:DNFcode,项目名称:edx-platform,代码行数:33,代码来源:test_video_handlers.py

示例11: test_client

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
def test_client(client_app=None):
    with serve(simple_app) as server:
        req = Request.blank(server.url, method="POST", content_type="application/json", json={"test": 1})
        resp = req.send(client_app)
        assert resp.status_code == 200, resp.status
        assert resp.json["headers"]["Content-Type"] == "application/json"
        assert resp.json["method"] == "POST"
        # Test that these values get filled in:
        del req.environ["SERVER_NAME"]
        del req.environ["SERVER_PORT"]
        resp = req.send(client_app)
        assert resp.status_code == 200, resp.status
        req = Request.blank(server.url)
        del req.environ["SERVER_NAME"]
        del req.environ["SERVER_PORT"]
        assert req.send(client_app).status_code == 200
        req.headers["Host"] = server.url.lstrip("http://")
        del req.environ["SERVER_NAME"]
        del req.environ["SERVER_PORT"]
        resp = req.send(client_app)
        assert resp.status_code == 200, resp.status
        del req.environ["SERVER_NAME"]
        del req.environ["SERVER_PORT"]
        del req.headers["Host"]
        assert req.environ.get("SERVER_NAME") is None
        assert req.environ.get("SERVER_PORT") is None
        assert req.environ.get("HTTP_HOST") is None
        assert_raises(ValueError, req.send, client_app)
        req = Request.blank(server.url)
        req.environ["CONTENT_LENGTH"] = "not a number"
        assert req.send(client_app).status_code == 200
开发者ID:mvidner,项目名称:webob,代码行数:33,代码来源:test_client.py

示例12: test_create_source_validation

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
 def test_create_source_validation(self):
     c = Controller({'account_id': self.account_id, 'id': 'test1'},
                    self.mock_app)
     req = Request.blank('?size=2&volume_type_name=vtype&source_volume=%s' %
                         'backupnotfound')
     self.assertRaises(HTTPPreconditionFailed, c.create, req)
     source_vol = db.models.Volume(node=self.node0, account=self.account,
                                   status='NOTACTIVE', size=1)
     self.db.add(source_vol)
     self.db.commit()
     req = Request.blank('?size=2&volume_type_name=vtype&source_volume=%s' %
                         source_vol.id)
     self.assertRaises(HTTPPreconditionFailed, c.create, req)
     source_vol.status = 'ACTIVE'
     source_vol.node = None
     self.db.add(source_vol)
     self.db.commit()
     req = Request.blank('?size=2&volume_type_name=vtype&source_volume=%s' %
                         source_vol.id)
     self.assertRaises(HTTPPreconditionFailed, c.create, req)
     source_vol = db.models.Volume(node=self.node0, account=self.account,
                                   status='NOTACTIVE', size=1)
     self.db.add(source_vol)
     self.db.commit()
     req = Request.blank('?size=2&volume_type_name=vtype&source_volume=%s' %
                         source_vol.id)
     self.assertRaises(HTTPPreconditionFailed, c.create, req)
开发者ID:corystone,项目名称:lunr,代码行数:29,代码来源:test_volume.py

示例13: test_bucket_GET_max_keys

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
    def test_bucket_GET_max_keys(self):
        class FakeApp(object):
            def __call__(self, env, start_response):
                self.query_string = env["QUERY_STRING"]
                start_response("200 OK", [])
                return "[]"

        fake_app = FakeApp()
        local_app = swift3.filter_factory({})(fake_app)
        bucket_name = "junk"

        req = Request.blank(
            "/%s" % bucket_name,
            environ={"REQUEST_METHOD": "GET", "QUERY_STRING": "max-keys=5"},
            headers={"Authorization": "AWS test:tester:hmac"},
        )
        resp = local_app(req.environ, lambda *args: None)
        dom = xml.dom.minidom.parseString("".join(resp))
        self.assertEquals(dom.getElementsByTagName("MaxKeys")[0].childNodes[0].nodeValue, "5")
        args = dict(cgi.parse_qsl(fake_app.query_string))
        self.assert_(args["limit"] == "6")

        req = Request.blank(
            "/%s" % bucket_name,
            environ={"REQUEST_METHOD": "GET", "QUERY_STRING": "max-keys=5000"},
            headers={"Authorization": "AWS test:tester:hmac"},
        )
        resp = local_app(req.environ, lambda *args: None)
        dom = xml.dom.minidom.parseString("".join(resp))
        self.assertEquals(dom.getElementsByTagName("MaxKeys")[0].childNodes[0].nodeValue, "1000")
        args = dict(cgi.parse_qsl(fake_app.query_string))
        self.assertEquals(args["limit"], "1001")
开发者ID:lixmgl,项目名称:Intern_OpenStack_Swift,代码行数:34,代码来源:test_swift3.py

示例14: test_origin_db_post_fail

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
    def test_origin_db_post_fail(self):
        self.test_origin.app = FakeApp(
            iter([("204 No Content", {}, ""), ("404 Not Found", {}, "")])  # call to _get_cdn_data  # put to .hash
        )
        req = Request.blank("http://origin_db.com:8080/v1/acc/cont", environ={"REQUEST_METHOD": "PUT"})
        resp = req.get_response(self.test_origin)
        self.assertEquals(resp.status_int, 500)

        self.test_origin.app = FakeApp(
            iter(
                [
                    ("204 No Content", {}, ""),  # call to _get_cdn_data
                    ("204 No Content", {}, ""),  # put to .hash
                    ("404 Not Found", {}, ""),  # HEAD check to list container
                    ("404 Not Found", {}, ""),  # PUT to list container
                ]
            )
        )
        req = Request.blank("http://origin_db.com:8080/v1/acc/cont", environ={"REQUEST_METHOD": "PUT"})
        resp = req.get_response(self.test_origin)
        self.assertEquals(resp.status_int, 500)

        self.test_origin.app = FakeApp(
            iter(
                [
                    ("204 No Content", {}, ""),  # call to _get_cdn_data
                    ("204 No Content", {}, ""),  # put to .hash
                    ("204 No Content", {}, ""),  # HEAD check to list container
                    ("404 Not Found", {}, ""),  # PUT to list container
                ]
            )
        )
        req = Request.blank("http://origin_db.com:8080/v1/acc/cont", environ={"REQUEST_METHOD": "PUT"})
        resp = req.get_response(self.test_origin)
        self.assertEquals(resp.status_int, 500)
开发者ID:pandemicsyn,项目名称:sos,代码行数:37,代码来源:test_origin.py

示例15: test_GET_json_last_modified

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import blank [as 别名]
    def test_GET_json_last_modified(self):
        # make a container
        req = Request.blank('/sda1/p/a/jsonc', environ={'REQUEST_METHOD': 'PUT',
            'HTTP_X_TIMESTAMP': '0'})
        resp = self.controller.PUT(req)
        for i, d in [(0, 1.5),
                     (1, 1.0),]:
            req = Request.blank('/sda1/p/a/jsonc/%s'%i, environ=
                    {'REQUEST_METHOD': 'PUT',
                    'HTTP_X_TIMESTAMP': d,
                    'HTTP_X_CONTENT_TYPE': 'text/plain',
                    'HTTP_X_ETAG': 'x',
                    'HTTP_X_SIZE': 0})
            resp = self.controller.PUT(req)
            self.assertEquals(resp.status_int, 201)
        # test format
        # last_modified format must be uniform, even when there are not msecs
        json_body = [{"name":"0",
                    "hash":"x",
                    "bytes":0,
                    "content_type":"text/plain",
                    "last_modified":"1970-01-01T00:00:01.500000"},
                    {"name":"1",
                    "hash":"x",
                    "bytes":0,
                    "content_type":"text/plain",
                    "last_modified":"1970-01-01T00:00:01.000000"},]

        req = Request.blank('/sda1/p/a/jsonc?format=json',
                environ={'REQUEST_METHOD': 'GET'})
        resp = self.controller.GET(req)
        self.assertEquals(resp.content_type, 'application/json')
        self.assertEquals(eval(resp.body), json_body)
        self.assertEquals(resp.charset, 'utf-8')
开发者ID:DmitryMezhensky,项目名称:Hadoop-and-Swift-integration,代码行数:36,代码来源:test_server.py


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