• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python test_web.DummyRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中twisted.web.test.test_web.DummyRequest的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest类的具体用法?Python DummyRequest怎么用?Python DummyRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: mk_request

 def mk_request(self, user=None, password=None):
     request = DummyRequest([''])
     if user is not None:
         request.headers["authorization"] = (
             "Basic %s" % base64.b64encode("%s:%s" % (user, password))
         )
     return request
开发者ID:ChrisNolan1992,项目名称:vumi-go,代码行数:7,代码来源:test_auth.py


示例2: test_getChild

    def test_getChild(self):
        """
        L{NameVirtualHost.getChild} returns correct I{Resource} based off
        the header and modifies I{Request} to ensure proper prepath and
        postpath are set.
        """
        virtualHostResource = NameVirtualHost()
        leafResource = Data(b"leaf data", "")
        leafResource.isLeaf = True
        normResource = Data(b"norm data", "")
        virtualHostResource.addHost(b'leaf.example.org', leafResource)
        virtualHostResource.addHost(b'norm.example.org', normResource)

        request = DummyRequest([])
        request.requestHeaders.addRawHeader(b'host', b'norm.example.org')
        request.prepath = [b'']

        self.assertIsInstance(virtualHostResource.getChild(b'', request),
                              NoResource)
        self.assertEqual(request.prepath, [b''])
        self.assertEqual(request.postpath, [])

        request = DummyRequest([])
        request.requestHeaders.addRawHeader(b'host', b'leaf.example.org')
        request.prepath = [b'']

        self.assertIsInstance(virtualHostResource.getChild(b'', request),
                              Data)
        self.assertEqual(request.prepath,  [])
        self.assertEqual(request.postpath, [b''])
开发者ID:Architektor,项目名称:PySnip,代码行数:30,代码来源:test_vhost.py


示例3: test_renderWithHost

    def test_renderWithHost(self):
        """
        L{NameVirtualHost.render} returns the result of rendering the resource
        which is the value in the instance's C{host} dictionary corresponding
        to the key indicated by the value of the I{Host} header in the request.
        """
        virtualHostResource = NameVirtualHost()
        virtualHostResource.addHost('example.org', Data("winner", ""))

        request = DummyRequest([''])
        request.headers['host'] = 'example.org'
        d = _render(virtualHostResource, request)
        def cbRendered(ignored, request):
            self.assertEqual(''.join(request.written), "winner")
        d.addCallback(cbRendered, request)

        # The port portion of the Host header should not be considered.
        requestWithPort = DummyRequest([''])
        requestWithPort.headers['host'] = 'example.org:8000'
        dWithPort = _render(virtualHostResource, requestWithPort)
        def cbRendered(ignored, requestWithPort):
            self.assertEqual(''.join(requestWithPort.written), "winner")
        dWithPort.addCallback(cbRendered, requestWithPort)

        return gatherResults([d, dWithPort])
开发者ID:Almad,项目名称:twisted,代码行数:25,代码来源:test_vhost.py


示例4: test_receipt_processing

 def test_receipt_processing(self):
     """it should be able to process an incoming XML receipt via HTTP"""
     publisher = TestPublisher()
     resource = transport.OperaReceiptResource(publisher)
     request = DummyRequest('/api/v1/sms/opera/receipt.xml')
     request.content = StringIO("""
     <?xml version="1.0"?>
     <!DOCTYPE receipts>
     <receipts>
       <receipt>
         <msgid>26567958</msgid>
         <reference>001efc31</reference>
         <msisdn>+27123456789</msisdn>
         <status>D</status>
         <timestamp>20080831T15:59:24</timestamp>
         <billed>NO</billed>
       </receipt>
     </receipts>
     """.strip())
     resource.render_POST(request)
     self.assertEquals(publisher.queue.pop(), (Message(**{
             'transport_name': 'Opera',
             'transport_msg_id': '001efc31',
             'transport_status': 'D',  # OK / delivered, opera specific
             'transport_delivered_at': datetime(2008, 8, 31, 15, 59, 24),
         }), {
             'routing_key': 'sms.receipt.opera'
         })
     )
开发者ID:dmaclay,项目名称:vumi,代码行数:29,代码来源:test_opera.py


示例5: test_renderSecureRequest

 def test_renderSecureRequest(self):
     """
     When the rendered request is over HTTPS, L{WebSocketsResource} wraps
     the protocol of the C{TLSMemoryBIOProtocol} instance.
     """
     request = DummyRequest("/")
     request.requestHeaders = Headers()
     transport = StringTransportWithDisconnection()
     secureProtocol = TLSMemoryBIOProtocol(Factory(), Protocol())
     transport.protocol = secureProtocol
     request.transport = transport
     request.headers.update({
         "upgrade": "Websocket",
         "connection": "Upgrade",
         "sec-websocket-key": "secure",
         "sec-websocket-version": "13"})
     result = self.resource.render(request)
     self.assertEqual(NOT_DONE_YET, result)
     self.assertEqual(
         {"connection": "Upgrade",
          "upgrade": "WebSocket",
          "sec-websocket-accept": "oYBv54i42V5dw6KnZqOFroecUTc="},
         request.outgoingHeaders)
     self.assertEqual([""], request.written)
     self.assertEqual(101, request.responseCode)
     self.assertIdentical(None, request.transport)
     self.assertIsInstance(
         transport.protocol.wrappedProtocol, WebSocketsProtocol)
     self.assertIsInstance(
         transport.protocol.wrappedProtocol._receiver,
         SavingEchoReceiver)
开发者ID:codecats,项目名称:kitty,代码行数:31,代码来源:test_websockets.py


示例6: test_renderIProtocol

    def test_renderIProtocol(self):
        """
        If the protocol returned by C{lookupProtocol} isn't a
        C{WebSocketsProtocol}, L{WebSocketsResource} wraps it automatically
        with L{WebSocketsProtocolWrapper}.
        """

        def lookupProtocol(names, otherRequest):
            return AccumulatingProtocol(), None

        self.resource = WebSocketsResource(lookupProtocol)

        request = DummyRequest("/")
        request.requestHeaders = Headers()
        transport = StringTransportWithDisconnection()
        transport.protocol = Protocol()
        request.transport = transport
        request.headers.update({
            "upgrade": "Websocket",
            "connection": "Upgrade",
            "sec-websocket-key": "secure",
            "sec-websocket-version": "13"})
        result = self.resource.render(request)
        self.assertEqual(NOT_DONE_YET, result)
        self.assertIsInstance(transport.protocol, WebSocketsProtocolWrapper)
        self.assertIsInstance(transport.protocol.wrappedProtocol,
                              AccumulatingProtocol)
开发者ID:codecats,项目名称:kitty,代码行数:27,代码来源:test_websockets.py


示例7: test_render

 def test_render(self):
     """
     When rendering a request, L{WebSocketsResource} uses the
     C{Sec-WebSocket-Key} header to generate a C{Sec-WebSocket-Accept}
     value. It creates a L{WebSocketsProtocol} instance connected to the
     protocol provided by the user factory.
     """
     request = DummyRequest("/")
     request.requestHeaders = Headers()
     transport = StringTransportWithDisconnection()
     transport.protocol = Protocol()
     request.transport = transport
     request.headers.update({
         "upgrade": "Websocket",
         "connection": "Upgrade",
         "sec-websocket-key": "secure",
         "sec-websocket-version": "13"})
     result = self.resource.render(request)
     self.assertEqual(NOT_DONE_YET, result)
     self.assertEqual(
         {"connection": "Upgrade",
          "upgrade": "WebSocket",
          "sec-websocket-accept": "oYBv54i42V5dw6KnZqOFroecUTc="},
         request.outgoingHeaders)
     self.assertEqual([""], request.written)
     self.assertEqual(101, request.responseCode)
     self.assertIdentical(None, request.transport)
     self.assertIsInstance(transport.protocol._receiver,
                           SavingEchoReceiver)
开发者ID:codecats,项目名称:kitty,代码行数:29,代码来源:test_websockets.py


示例8: test_renderProtocol

    def test_renderProtocol(self):
        """
        If protocols are specified via the C{Sec-WebSocket-Protocol} header,
        L{WebSocketsResource} passes them to its C{lookupProtocol} argument,
        which can decide which protocol to return, and which is accepted.
        """

        def lookupProtocol(names, otherRequest):
            self.assertEqual(["foo", "bar"], names)
            self.assertIdentical(request, otherRequest)
            return self.echoProtocol, "bar"

        self.resource = WebSocketsResource(lookupProtocol)

        request = DummyRequest("/")
        request.requestHeaders = Headers(
            {"sec-websocket-protocol": ["foo", "bar"]})
        transport = StringTransportWithDisconnection()
        transport.protocol = Protocol()
        request.transport = transport
        request.headers.update({
            "upgrade": "Websocket",
            "connection": "Upgrade",
            "sec-websocket-key": "secure",
            "sec-websocket-version": "13"})
        result = self.resource.render(request)
        self.assertEqual(NOT_DONE_YET, result)
        self.assertEqual(
            {"connection": "Upgrade",
             "upgrade": "WebSocket",
             "sec-websocket-protocol": "bar",
             "sec-websocket-accept": "oYBv54i42V5dw6KnZqOFroecUTc="},
            request.outgoingHeaders)
        self.assertEqual([""], request.written)
        self.assertEqual(101, request.responseCode)
开发者ID:codecats,项目名称:kitty,代码行数:35,代码来源:test_websockets.py


示例9: __init__

    def __init__(self, postpath, params, session=None):
        self.content = StringIO()
        self.content.write(urllib.urlencode(params))
        self.content.seek(0, 0)
        self.requestHeaders = Headers()

        DummyRequest.__init__(self, postpath, session)
开发者ID:nicholasamorim,项目名称:mamba,代码行数:7,代码来源:test_controller.py


示例10: test_invalidMethod

 def test_invalidMethod(self):
     """
     L{UserDirectory.render} raises L{UnsupportedMethod} in response to a
     non-I{GET} request.
     """
     request = DummyRequest([""])
     request.method = "POST"
     self.assertRaises(server.UnsupportedMethod, self.directory.render, request)
开发者ID:RockySteveJobs,项目名称:python-for-android,代码行数:8,代码来源:test_distrib.py


示例11: __init__

    def __init__(self, method, url, args=None):
        DummyRequest.__init__(self, url.split('/'))
        self.method = method

        # set args
        args = args or {}
        for k, v in args.items():
            self.addArg(k, v)
开发者ID:AVert,项目名称:jasmin,代码行数:8,代码来源:twisted_web_test_utils.py


示例12: __init__

 def __init__(self, postpath, params):
     DummyRequest.__init__(self, postpath, None)
     self.content = StringIO()
     self.content.write(json.dumps(params))
     self.content.seek(0, 0)
     self.requestHeaders = Headers()
     self.method = 'POST'
     self.requestHeaders.addRawHeader('content-type', 'application/json')
开发者ID:DamnWidget,项目名称:BlackMamba,代码行数:8,代码来源:test_controller_contact.py


示例13: create_request

def create_request(params={}, path='/', method='POST'):
    """
    Creates a dummy Vas2Nets request for testing our resources with
    """
    request = DummyRequest(path)
    request.method = method
    request.args = params
    return request
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:8,代码来源:test_vas2nets_stubs.py


示例14: test_song_id_does_not_exist

 def test_song_id_does_not_exist(self):
     raise SkipTest("Twisted using deferToThread seems to break the test db connection that django establishes.  However, with the real django db connection this works fine...")
     r = web.Song(1)
     request = DummyRequest([""])
     d = request.notifyFinish()
     d.addCallback(self._assert_song_does_not_exist, request)
     result = r.render_GET(request)
     self.assertEqual(result, server.NOT_DONE_YET)
     return d
开发者ID:steder,项目名称:zilla,代码行数:9,代码来源:test_web.py


示例15: request_generator

def request_generator(url, method='GET', content=True, headers=True):
    request = DummyRequest(url)
    request.method = method
    if content:
        request.content = StringIO()
    if headers:
        request.requestHeaders = Headers()

    return request
开发者ID:DamnWidget,项目名称:mamba,代码行数:9,代码来源:test_web.py


示例16: makeRequest

 def makeRequest(self, method='GET', clientAddress=None):
     """
     Create a L{DummyRequest} (change me to create a
     L{twisted.web.http.Request} instead).
     """
     request = DummyRequest('/')
     request.method = method
     request.client = clientAddress
     return request
开发者ID:jxta,项目名称:cc,代码行数:9,代码来源:test_httpauth.py


示例17: test_handles_defaults_correctly

def test_handles_defaults_correctly():
    u2m = {}
    u2m["/doesn/t/exist"] = root.__default__
    u2m["/sub/doesn/t/exist"] = root.sub.__default__

    for path, method in u2m.items():
        request = DummyRequest([])
        request.path = path
        action = site.routeRequest(request)
        assert getattr(action, "func", None) == method, "Expecting %s but got %s for URL %s" % (method, action, path)
开发者ID:devdave,项目名称:txWeb,代码行数:10,代码来源:test_core.py


示例18: test_renderHEAD

 def test_renderHEAD(self):
     """
     The rendering behavior of L{UnauthorizedResource} for a I{HEAD} request
     is like its handling of a I{GET} request, but no response body is
     written.
     """
     request = DummyRequest([''])
     request.method = 'HEAD'
     self._unauthorizedRenderTest(request)
     self.assertEqual('', ''.join(request.written))
开发者ID:0004c,项目名称:VTK,代码行数:10,代码来源:test_httpauth.py


示例19: __init__

 def __init__(self, method, url, args=None, headers=None):
     DummyRequest.__init__(self, url.split('/'))
     self.uri    = url
     self.method = method
     self.headers.update(headers or {})
     
     # set args
     args = args or {}
     for k, v in args.items():
         self.addArg(k, v)
开发者ID:DevMaurice,项目名称:moringa-demo,代码行数:10,代码来源:twisted_web_test_utils.py


示例20: test_hook_bad_ip

    def test_hook_bad_ip(self):
        """
        An error is raised when request is comming from an untrusted IP.
        """
        request = DummyRequest([])
        request.client = IPv4Address('TCP', '111.0.0.0', 2345)
        result = hook(request, 'hook_name')

        self.assertEqual(403, request.code)
        self.assertTrue(result.startswith('Error:001: '))
开发者ID:chevah,项目名称:github-hooks-server,代码行数:10,代码来源:test_hooks_server.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.formatFailure函数代码示例发布时间:2022-05-27
下一篇:
Python requesthelper.DummyRequest类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap