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


Python test_web.DummyRequest方法代码示例

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


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

示例1: _logoutTest

# 需要导入模块: from twisted.web.test import test_web [as 别名]
# 或者: from twisted.web.test.test_web import DummyRequest [as 别名]
def _logoutTest(self):
        """
        Issue a request for an authentication-protected resource using valid
        credentials and then return the C{DummyRequest} instance which was
        used.

        This is a helper for tests about the behavior of the logout
        callback.
        """
        self.credentialFactories.append(BasicCredentialFactory('example.com'))

        class SlowerResource(Resource):
            def render(self, request):
                return NOT_DONE_YET

        self.avatar.putChild(self.childName, SlowerResource())
        request = self.makeRequest([self.childName])
        child = self._authorizedBasicLogin(request)
        request.render(child)
        self.assertEqual(self.realm.loggedOut, 0)
        return request 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:test_httpauth.py

示例2: test_renderWithHost

# 需要导入模块: from twisted.web.test import test_web [as 别名]
# 或者: from twisted.web.test.test_web import DummyRequest [as 别名]
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(b'example.org', Data(b"winner", ""))

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

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

        return gatherResults([d, dWithPort]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:27,代码来源:test_vhost.py

示例3: test_withRequest

# 需要导入模块: from twisted.web.test import test_web [as 别名]
# 或者: from twisted.web.test.test_web import DummyRequest [as 别名]
def test_withRequest(self):
        """
        When an XML-RPC method is called and the implementation is
        decorated with L{withRequest}, the request object is passed as
        the first argument.
        """
        request = DummyRequest('/RPC2')
        request.method = "POST"
        request.content = NativeStringIO(xmlrpclib.dumps(
            ("foo",), 'withRequest'))
        def valid(n, request):
            data = xmlrpclib.loads(request.written[0])
            self.assertEqual(data, (('POST foo',), None))
        d = request.notifyFinish().addCallback(valid, request)
        self.resource.render_POST(request)
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_xmlrpc.py

示例4: assertForwardsResponse

# 需要导入模块: from twisted.web.test import test_web [as 别名]
# 或者: from twisted.web.test.test_web import DummyRequest [as 别名]
def assertForwardsResponse(self, request, code, message, headers, body):
        """
        Assert that C{request} has forwarded a response from the server.

        @param request: A L{DummyRequest}.
        @param code: The expected HTTP response code.
        @param message: The expected HTTP message.
        @param headers: The expected HTTP headers.
        @param body: The expected response body.
        """
        self.assertEqual(request.responseCode, code)
        self.assertEqual(request.responseMessage, message)
        receivedHeaders = list(request.responseHeaders.getAllRawHeaders())
        receivedHeaders.sort()
        expectedHeaders = headers[:]
        expectedHeaders.sort()
        self.assertEqual(receivedHeaders, expectedHeaders)
        self.assertEqual(b''.join(request.written), body) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_proxy.py

示例5: test_useReactorArgument

# 需要导入模块: from twisted.web.test import test_web [as 别名]
# 或者: from twisted.web.test.test_web import DummyRequest [as 别名]
def test_useReactorArgument(self):
        """
        L{twcgi.FilteredScript.runProcess} uses the reactor passed as an
        argument to the constructor.
        """
        class FakeReactor:
            """
            A fake reactor recording whether spawnProcess is called.
            """
            called = False
            def spawnProcess(self, *args, **kwargs):
                """
                Set the C{called} flag to C{True} if C{spawnProcess} is called.

                @param args: Positional arguments.
                @param kwargs: Keyword arguments.
                """
                self.called = True

        fakeReactor = FakeReactor()
        request = DummyRequest(['a', 'b'])
        resource = twcgi.FilteredScript("dummy-file", reactor=fakeReactor)
        _render(resource, request)

        self.assertTrue(fakeReactor.called) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:27,代码来源:test_cgi.py

示例6: test_notFoundChild

# 需要导入模块: from twisted.web.test import test_web [as 别名]
# 或者: from twisted.web.test.test_web import DummyRequest [as 别名]
def test_notFoundChild(self):
        """
        L{twcgi.CGIDirectory.getChild} returns a resource which renders an
        response with the HTTP I{NOT FOUND} status code if the indicated child
        does not exist as an entry in the directory used to initialized the
        L{twcgi.CGIDirectory}.
        """
        path = self.mktemp()
        os.makedirs(path)
        resource = twcgi.CGIDirectory(path)
        request = DummyRequest(['foo'])
        child = resource.getChild("foo", request)
        d = _render(child, request)
        def cbRendered(ignored):
            self.assertEqual(request.responseCode, NOT_FOUND)
        d.addCallback(cbRendered)
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_cgi.py

示例7: test_logFailed

# 需要导入模块: from twisted.web.test import test_web [as 别名]
# 或者: from twisted.web.test.test_web import DummyRequest [as 别名]
def test_logFailed(self):
        """
        When a request fails, the string form of the failure is logged.
        """
        logObserver = proto_helpers.EventLoggingObserver.createWithCleanup(
            self,
            globalLogPublisher
        )

        f = failure.Failure(ArbitraryError())
        request = DummyRequest([b''])
        issue = distrib.Issue(request)
        issue.failed(f)
        self.assertEquals(1, len(logObserver))
        self.assertIn(
            "Failure instance",
            logObserver[0]["log_format"]
        ) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:20,代码来源:test_distrib.py

示例8: test_connectionFailed

# 需要导入模块: from twisted.web.test import test_web [as 别名]
# 或者: from twisted.web.test.test_web import DummyRequest [as 别名]
def test_connectionFailed(self):
        """
        Check that L{ProxyClientFactory.clientConnectionFailed} produces
        a B{501} response to the parent request.
        """
        request = DummyRequest([b'foo'])
        factory = ProxyClientFactory(b'GET', b'/foo', b'HTTP/1.0',
                                     {b"accept": b"text/html"}, '', request)

        factory.clientConnectionFailed(None, None)
        self.assertEqual(request.responseCode, 501)
        self.assertEqual(request.responseMessage, b"Gateway error")
        self.assertEqual(
            list(request.responseHeaders.getAllRawHeaders()),
            [(b"Content-Type", [b"text/html"])])
        self.assertEqual(
            b''.join(request.written),
            b"<H1>Could not connect</H1>")
        self.assertEqual(request.finished, 1) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:21,代码来源:test_proxy.py

示例9: test_notFoundChild

# 需要导入模块: from twisted.web.test import test_web [as 别名]
# 或者: from twisted.web.test.test_web import DummyRequest [as 别名]
def test_notFoundChild(self):
        """
        L{ResourceScriptDirectory.getChild} returns a resource which renders an
        response with the HTTP I{NOT FOUND} status code if the indicated child
        does not exist as an entry in the directory used to initialized the
        L{ResourceScriptDirectory}.
        """
        path = self.mktemp()
        os.makedirs(path)
        resource = ResourceScriptDirectory(path)
        request = DummyRequest(['foo'])
        child = resource.getChild("foo", request)
        d = _render(child, request)
        def cbRendered(ignored):
            self.assertEqual(request.responseCode, NOT_FOUND)
        d.addCallback(cbRendered)
        return d 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:19,代码来源:test_script.py

示例10: test_connectionLost

# 需要导入模块: from twisted.web.test import test_web [as 别名]
# 或者: from twisted.web.test.test_web import DummyRequest [as 别名]
def test_connectionLost(self):
        """
        If there is an error issuing the request to the remote publisher, an
        error response is returned.
        """
        # Using pb.Root as a publisher will cause request calls to fail with an
        # error every time.  Just what we want to test.
        self.f1 = serverFactory = PBServerFactory(pb.Root())
        self.port1 = serverPort = reactor.listenTCP(0, serverFactory)

        self.sub = subscription = distrib.ResourceSubscription(
            "127.0.0.1", serverPort.getHost().port)
        request = DummyRequest([''])
        d = _render(subscription, request)
        def cbRendered(ignored):
            self.assertEqual(request.responseCode, 500)
            # This is the error we caused the request to fail with.  It should
            # have been logged.
            self.assertEqual(len(self.flushLoggedErrors(pb.NoSuchMethod)), 1)
        d.addCallback(cbRendered)
        return d 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:test_distrib.py

示例11: _logoutTest

# 需要导入模块: from twisted.web.test import test_web [as 别名]
# 或者: from twisted.web.test.test_web import DummyRequest [as 别名]
def _logoutTest(self):
        """
        Issue a request for an authentication-protected resource using valid
        credentials and then return the C{DummyRequest} instance which was
        used.

        This is a helper for tests about the behavior of the logout
        callback.
        """
        self.credentialFactories.append(BasicCredentialFactory('example.com'))

        class SlowerResource(Resource):
            def render(self, request):
                return NOT_DONE_YET

        self.avatar.putChild(self.childName, SlowerResource())
        request = self.makeRequest([self.childName])
        child = self._authorizedBasicLogin(request)
        request.render(child)
        self.assertEquals(self.realm.loggedOut, 0)
        return request 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:test_httpauth.py

示例12: test_renderWithHost

# 需要导入模块: from twisted.web.test import test_web [as 别名]
# 或者: from twisted.web.test.test_web import DummyRequest [as 别名]
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:kuri65536,项目名称:python-for-android,代码行数:27,代码来源:test_vhost.py

示例13: assertForwardsResponse

# 需要导入模块: from twisted.web.test import test_web [as 别名]
# 或者: from twisted.web.test.test_web import DummyRequest [as 别名]
def assertForwardsResponse(self, request, code, message, headers, body):
        """
        Assert that C{request} has forwarded a response from the server.

        @param request: A L{DummyRequest}.
        @param code: The expected HTTP response code.
        @param message: The expected HTTP message.
        @param headers: The expected HTTP headers.
        @param body: The expected response body.
        """
        self.assertEquals(request.responseCode, code)
        self.assertEquals(request.responseMessage, message)
        receivedHeaders = list(request.responseHeaders.getAllRawHeaders())
        receivedHeaders.sort()
        expectedHeaders = headers[:]
        expectedHeaders.sort()
        self.assertEquals(receivedHeaders, expectedHeaders)
        self.assertEquals(''.join(request.written), body) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:20,代码来源:test_proxy.py

示例14: test_render_GET_400_when_no_local_addr

# 需要导入模块: from twisted.web.test import test_web [as 别名]
# 或者: from twisted.web.test.test_web import DummyRequest [as 别名]
def test_render_GET_400_when_no_local_addr(self):
        path = factory.make_name("path")
        ip = factory.make_ip_address()
        request = DummyRequest([path.encode("utf-8")])
        request.requestHeaders = Headers(
            {
                "X-Forwarded-For": [ip],
                "X-Forwarded-Port": ["%s" % factory.pick_port()],
            }
        )

        self.patch(http.log, "info")
        mock_deferLater = self.patch(http, "deferLater")
        mock_deferLater.side_effect = always_succeed_with(None)

        resource = http.HTTPBootResource()
        yield self.render_GET(resource, request)

        self.assertEquals(400, request.responseCode)
        self.assertEquals(
            b"Missing X-Server-Addr and X-Forwarded-For HTTP headers.",
            b"".join(request.written),
        ) 
开发者ID:maas,项目名称:maas,代码行数:25,代码来源:test_http.py

示例15: test_render_GET_400_when_no_remote_addr

# 需要导入模块: from twisted.web.test import test_web [as 别名]
# 或者: from twisted.web.test.test_web import DummyRequest [as 别名]
def test_render_GET_400_when_no_remote_addr(self):
        path = factory.make_name("path")
        request = DummyRequest([path.encode("utf-8")])
        request.requestHeaders = Headers(
            {"X-Server-Addr": ["192.168.1.1"], "X-Server-Port": ["5248"]}
        )

        self.patch(http.log, "info")
        mock_deferLater = self.patch(http, "deferLater")
        mock_deferLater.side_effect = always_succeed_with(None)

        resource = http.HTTPBootResource()
        yield self.render_GET(resource, request)

        self.assertEquals(400, request.responseCode)
        self.assertEquals(
            b"Missing X-Server-Addr and X-Forwarded-For HTTP headers.",
            b"".join(request.written),
        ) 
开发者ID:maas,项目名称:maas,代码行数:21,代码来源:test_http.py


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