Exemplo n.º 1
0
 def test01_wrap_http(self):
     resource = CardstoriesResource(self.service)
     self.site = CardstoriesSite(resource, {}, [])
     request = server.Request(self.Channel(self.site), True)
     request.site = self.site
     request.method = 'GET'
     d = resource.wrap_http(request)
     def finish(result):
         self.assertSubstring('\r\n\r\n"handle"', request.transport.getvalue())
     d.addCallback(finish)
     return d
Exemplo n.º 2
0
 def test01_wrap_http_disconnected(self):
     resource = CardstoriesResource(self.service)
     self.site = CardstoriesSite(resource, {}, [])
     request = server.Request(self.Channel(self.site), True)
     request.site = self.site
     request.method = 'GET'
     request._disconnected = True
     d = resource.wrap_http(request)
     def finish(result):
         self.assertEquals('', request.transport.getvalue())
     d.addCallback(finish)
     return d
Exemplo n.º 3
0
 def test03_wrap_http_fail(self):
     resource = CardstoriesResource(self.service)
     fail_string = 'FAIL STRING'
     def fail(result, request):
         raise Exception(fail_string)
     resource.handle = fail
     self.site = CardstoriesSite(resource, {}, [])
     request = server.Request(self.Channel(self.site), True)
     request.site = self.site
     d = resource.wrap_http(request)
     def finish(result):
         self.assertSubstring(fail_string, request.transport.getvalue())
     d.addCallback(finish)
     return d
Exemplo n.º 4
0
 def test02_wrap_http_plugin_postprocess_fail(self):
     plugins = CardstoriesPlugins({ 'plugins-dir': '..',
                                    'plugins': 'plugin_fail'})
     plugins.load(True)
     resource = CardstoriesResource(self.service)
     self.site = CardstoriesSite(resource, { 'plugins-post-process': 'plugin_fail' }, plugins.plugins)
     request = server.Request(self.Channel(self.site), True)
     request.site = self.site
     request.method = 'GET'
     d = resource.wrap_http(request)
     def finish(result):
         self.assertSubstring('Internal Server Error', request.transport.getvalue())
         self.assertSubstring('POSTPROCESS', request.transport.getvalue())
     d.addCallback(finish)
     return d
Exemplo n.º 5
0
    def test02_wrap_http_plugin(self):
        class MyService:
            def handle(self, result, args):
                return result

        plugins = CardstoriesPlugins({ 'plugins-dir': '..',
                                       'plugins': 'plugin_site'})
        plugins.load(True)
        resource = CardstoriesResource(MyService())
        self.site = CardstoriesSite(resource, { 'plugins-pre-process': 'plugin_site',
                                                'plugins-post-process': 'plugin_site' }, plugins.plugins)
        request = server.Request(self.Channel(self.site), True)
        request.site = self.site
        request.args = {}
        request.method = 'GET'
        d = resource.wrap_http(request)
        def finish(result):
            self.assertSubstring('"preprocess": ["PREPROCESS"]', request.transport.getvalue())
            self.assertSubstring('"postprocess": "POSTPROCESS"', request.transport.getvalue())
        d.addCallback(finish)
        return d