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


Python requesthelper.DummyRequest类代码示例

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


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

示例1: test_returns_the_key_as_json_if_found

    def test_returns_the_key_as_json_if_found(self):
        request = DummyRequest(['/keys'])
        request.addArg('search', '[email protected]')
        when(self.keymanager).fetch_key('[email protected]').thenReturn(defer.succeed(OpenPGPKey('[email protected]')))

        d = self.web.get(request)

        expected = {
            u'address': u'[email protected]',
            u'encr_used': False,
            u'fingerprint': u'',
            u'last_audited_at': 0,
            u'private': False,
            u'sign_used': False,
            u'tags': [u'keymanager-active'],
            u'type': u'OpenPGPKey-active',
            u'validation': u'Weak_Chain',
            u'version': 1,
        }

        def assert_response(_):
            actual = json.loads(ast.literal_eval(request.written[0]))
            self.assertEquals(expected, actual)

        d.addCallback(assert_response)
        return d
开发者ID:Meistache,项目名称:pixelated-user-agent,代码行数:26,代码来源:test_keys_resources.py

示例2: CallbackResourceTest

class CallbackResourceTest(TestCase):
    def setUp(self):
        self.resource = CallbackResource()
        self.resource.factory = DecoupledRequestFactory()
        self.request = DummyRequest([''])
        self.request.method = 'POST'
        self.request.content = StringIO()

    def test_no_request_id(self):
        def on_rendered(_):
            self.assertEqual(self.request.responseCode, 503)
            self.assertEqual(['No request_id given'], self.request.written)

        return _render(self.resource, self.request).addCallback(on_rendered)

    def test_unknown_request_id(self):
        self.request.addArg('request_id', 'xxx')

        def on_rendered(_):
            self.assertEqual(self.request.responseCode, 503)
            self.assertEqual(['Request not found'], self.request.written)

        return _render(self.resource, self.request).addCallback(on_rendered)

    def test_success(self):
        self.request.addArg('request_id', 'xxx')
        self.resource.factory.requests['xxx'] = DecoupledRequest(
            self.resource.factory, 'xxx', DummyRequest(['']))

        def on_rendered(_):
            self.assertEqual(['ok'], self.request.written)

        return _render(self.resource, self.request).addCallback(on_rendered)
开发者ID:jaxer,项目名称:thinking-exercise,代码行数:33,代码来源:test_callback_resource.py

示例3: test_returns_the_key_as_json_if_found

    def test_returns_the_key_as_json_if_found(self):
        request = DummyRequest(['/keys'])
        request.addArg('search', '[email protected]')
        when(self.keymanager).fetch_key('[email protected]').thenReturn(defer.succeed(OpenPGPKey('[email protected]')))

        d = self.web.get(request)

        expected = {
            "tags": ["keymanager-key"],
            "fingerprint": '',
            "private": False,
            'sign_used': False,
            'refreshed_at': 0,
            "expiry_date": 0,
            "address": '[email protected]',
            'encr_used': False,
            'last_audited_at': 0,
            'key_data': '',
            'length': 0,
            'key_id': '',
            'validation': 'Weak_Chain',
            'type': 'OpenPGPKey',
        }

        def assert_response(_):
            actual = json.loads(ast.literal_eval(request.written[0]))
            self.assertEquals(expected, actual)

        d.addCallback(assert_response)
        return d
开发者ID:sw00,项目名称:pixelated-user-agent,代码行数:30,代码来源:test_keys_resources.py

示例4: test_returns_the_key_as_json_if_found

    def test_returns_the_key_as_json_if_found(self):
        request = DummyRequest(["/keys"])
        request.addArg("search", "[email protected]")
        when(self.keymanager).fetch_key("[email protected]").thenReturn(defer.succeed(OpenPGPKey("[email protected]")))

        d = self.web.get(request)

        expected = {
            u"address": u"[email protected]",
            u"encr_used": False,
            u"fingerprint": u"",
            u"last_audited_at": 0,
            u"private": False,
            u"sign_used": False,
            u"tags": [u"keymanager-active"],
            u"type": u"OpenPGPKey-active",
            u"validation": u"Weak_Chain",
            u"version": 1,
        }

        def assert_response(_):
            actual = json.loads(ast.literal_eval(request.written[0]))
            self.assertEquals(expected, actual)

        d.addCallback(assert_response)
        return d
开发者ID:akjones,项目名称:pixelated-user-agent,代码行数:26,代码来源:test_keys_resources.py

示例5: test_render_exceptions

    def test_render_exceptions(self):
        """
        `SmsNotificationService.render_POST` logs any exceptions that occur
        during processing and writes a SOAP fault back to the request.
        """
        def process(*a, **kw):
            raise ValueError('What is this')
        service = SmsNotificationService(None, None)
        service.process = process
        request = DummyRequest([])
        request.content = StringIO(tostring(soap_envelope('hello')))
        d = request.notifyFinish()

        service.render_POST(request)
        self.successResultOf(d)
        self.assertEqual(http.INTERNAL_SERVER_ERROR, request.responseCode)
        failures = self.flushLoggedErrors(ValueError)
        self.assertEqual(1, len(failures))
        self.assertEqual(
            {str(SOAP_ENV.Envelope): {
                str(SOAP_ENV.Body): {
                    str(SOAP_ENV.Fault): {
                        'faultcode': 'soapenv:Server',
                        'faultstring': 'What is this'}}}},
            element_to_dict(fromstring(''.join(request.written))))
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:25,代码来源:test_server.py

示例6: test_render_soap_fault

    def test_render_soap_fault(self):
        """
        `SmsNotificationService.render_POST` logs any exceptions that occur
        during processing and writes a SOAP fault back to the request. If the
        logged exception is a `SoapFault` its ``to_element`` method is invoked
        to serialize the fault.
        """
        service = SmsNotificationService(None, None)
        service.process = lambda *a, **kw: L.done()
        request = DummyRequest([])
        request.content = StringIO(tostring(L.hello()))
        d = request.notifyFinish()

        service.render_POST(request)
        self.successResultOf(d)
        self.assertEqual(http.INTERNAL_SERVER_ERROR, request.responseCode)
        failures = self.flushLoggedErrors(SoapFault)
        self.assertEqual(1, len(failures))
        self.assertEqual(
            {str(SOAP_ENV.Envelope): {
                str(SOAP_ENV.Body): {
                    str(SOAP_ENV.Fault): {
                        'faultcode': 'soapenv:Client',
                        'faultstring': 'Malformed SOAP request'}}}},
            element_to_dict(fromstring(''.join(request.written))))
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:25,代码来源:test_server.py

示例7: _create_request

 def _create_request(self, number_of_commits):
     body = {
         "commits": [{"rev": i} for i in range(number_of_commits)]
     }
     request = DummyRequest([b"/"])
     request.method = "POST"
     request.args["payload"] = [json.dumps(body)]
     return request
开发者ID:aether-space,项目名称:trompet,代码行数:8,代码来源:test_webhook.py

示例8: request_same_or_different_thread_thread

    def request_same_or_different_thread_thread(self):

        hr = HendrixWSGIResource(reactor, self.tp, self.wsgi_thing)
        request1 = DummyRequest('r1')
        request1.isSecure = lambda: False
        request1.content = "llamas"
        d = deferToThreadPool(reactor, self.tp, hr.render, request1)
        return d
开发者ID:citruspi,项目名称:hendrix,代码行数:8,代码来源:test_crosstown_traffic.py

示例9: request_same_or_different_thread_thread

 def request_same_or_different_thread_thread(self):
     hr = HendrixWSGIResource(reactor, self.tp, self.wsgi_thing)
     request1 = DummyRequest([b'r1'])
     request1.isSecure = lambda: False
     request1.content = b"llamas"
     request1.client = IPv4Address("TCP", b"50.0.50.0", 5000)
     d = deferToThreadPool(reactor, self.tp, hr.render, request1)
     d.addCallback(lambda _: request1.notifyFinish())
     return d
开发者ID:hendrix,项目名称:hendrix,代码行数:9,代码来源:test_crosstown_traffic.py

示例10: test_defaultHEAD

 def test_defaultHEAD(self):
     """
     When not otherwise overridden, L{Resource.render} treats a I{HEAD}
     request as if it were a I{GET} request.
     """
     expected = b"insert response here"
     request = DummyRequest([])
     request.method = b'HEAD'
     resource = BytesReturnedRenderable(expected)
     self.assertEqual(expected, resource.render(request))
开发者ID:Architektor,项目名称:PySnip,代码行数:10,代码来源:test_resource.py

示例11: test_get

    def test_get(self):
        request = DummyRequest(['/account-recovery'])
        request.method = 'GET'
        d = self.web.get(request)

        def assert_200_when_user_logged_in(_):
            self.assertEqual(200, request.responseCode)
            self.assertIn("DOCTYPE html", request.written[0])

        d.addCallback(assert_200_when_user_logged_in)
        return d
开发者ID:pixelated,项目名称:pixelated-user-agent,代码行数:11,代码来源:test_account_recovery_resource.py

示例12: test_success

    def test_success(self):
        def on_rendered(_):
            self.assertEqual(['backend reply'], self.request.written)

        d = _render(self.resource, self.request).addCallback(on_rendered)

        callback_request = DummyRequest([''])
        callback_request.content = StringIO('backend reply')

        self.resource.factory.requests.values()[0].notify(callback_request)
        return d
开发者ID:jaxer,项目名称:thinking-exercise,代码行数:11,代码来源:test_exported_resource.py

示例13: test_returns_404_if_key_not_found

    def test_returns_404_if_key_not_found(self):
        request = DummyRequest(['/keys'])
        request.addArg('search', '[email protected]')
        when(self.keymanager).get_key_from_cache('[email protected]', OpenPGPKey).thenRaise(KeyNotFound())

        d = self.web.get(request)

        def assert_404(_):
            self.assertEquals(404, request.code)

        d.addCallback(assert_404)
        return d
开发者ID:EderRoger,项目名称:pixelated-user-agent,代码行数:12,代码来源:test_keys_resources.py

示例14: test_returns_404_if_key_not_found

    def test_returns_404_if_key_not_found(self):
        request = DummyRequest(['/keys'])
        request.addArg('search', '[email protected]')
        when(self.keymanager).fetch_key('[email protected]').thenReturn(defer.fail(KeyNotFound()))

        d = self.web.get(request)

        def assert_404(_):
            self.assertEquals(404, request.code)

        d.addCallback(assert_404)
        return d
开发者ID:Meistache,项目名称:pixelated-user-agent,代码行数:12,代码来源:test_keys_resources.py

示例15: test_returns_unauthorized_if_key_is_private

    def test_returns_unauthorized_if_key_is_private(self):
        request = DummyRequest(['/keys'])
        request.addArg('search', '[email protected]')
        when(self.keymanager).fetch_key('[email protected]').thenReturn(defer.succeed(OpenPGPKey('[email protected]', private=True)))

        d = self.web.get(request)

        def assert_response(_):
            self.assertEquals(401, request.code)

        d.addCallback(assert_response)
        return d
开发者ID:Meistache,项目名称:pixelated-user-agent,代码行数:12,代码来源:test_keys_resources.py


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