Exemple #1
0
def makeService(settings):
    service_collection = service.MultiService()
    cardstories_service = CardstoriesService(settings)
    plugins = CardstoriesPlugins(settings)
    plugins.load(cardstories_service)
    cardstories_service.setServiceParent(service_collection)

    site = CardstoriesSite(CardstoriesTree(cardstories_service), settings,
                           plugins.plugins)

    if settings.get('manhole', None):
        internet.TCPServer(
            2222,
            getManholeFactory(locals(), user="******"),
            interface='127.0.0.1').setServiceParent(service_collection)

    internet.TCPServer(settings['port'],
                       site,
                       interface=settings.get(
                           'interface',
                           '127.0.0.1')).setServiceParent(service_collection)

    # if settings.has_key('ssl-port') and settings['ssl-port']:
    #     internet.SSLServer(settings['ssl-port'], site, SSLContextFactory(settings)
    #                        ).setServiceParent(service_collection)

    return service_collection
Exemple #2
0
 def test00_path(self):
     plugins = CardstoriesPlugins({ 'plugins-dir': '..' })
     self.assertEquals(plugins.path('../plugin_one/plugin_one.py'), '../plugin_one/plugin_one.py')
     self.assertEquals(plugins.path('plugin_one'), '../plugin_one/plugin_one.py')
     caught = False
     try:
         plugins.path('WTF')
     except UserWarning, e:
         self.failUnlessSubstring('WTF', e.args[0])
         caught = True
Exemple #3
0
 def test01_load(self):
     plugins = CardstoriesPlugins({ 'plugins-dir': '..',
                                    'plugins': 'plugin_one plugin_two'})
     class Service:
         def __init__(self):
             self.pollable_plugins = []
     service = Service()
     plugins.load(service)
     self.assertEquals(plugins.plugins[0].service, service)
     self.assertEquals(plugins.plugins[1].service, service)
     self.assertEquals(service.pollable_plugins[0], plugins.plugins[1])
     self.assertEquals(len(service.pollable_plugins), 1)
Exemple #4
0
 def test00_init(self):
     plugins = CardstoriesPlugins({ 'plugins-dir': '..',
                                    'plugins': 'plugin_one plugin_two'})
     class Service:
         def __init__(self):
             self.pollable_plugins = []
     service = Service()
     plugins.load(service)
     site = CardstoriesSite(resource.Resource(), { 'plugins-pre-process': 'plugin_one plugin_two',
                                                   'plugins-post-process': 'plugin_two plugin_one' }, plugins.plugins)
     self.assertEqual(site.preprocess[0], site.postprocess[1])
     self.assertEqual(site.preprocess[1], site.postprocess[0])
Exemple #5
0
 def test02_auth_plugin(self):
     '''Auth plugins must be registered on the service object'''
     
     plugins = CardstoriesPlugins({ 'plugins-dir': '..',
                                    'plugins': 'plugin_auth'})
     class Service:
         def __init__(self):
             self.auth = None
     service = Service()
     plugins.load(service)
     self.assertEquals(plugins.plugins[0].service, service)
     self.assertEquals(service.auth, plugins.plugins[0])
     self.assertIsInstance(service.auth, Auth)
Exemple #6
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
Exemple #7
0
    def test01_load(self):
        plugins = CardstoriesPlugins({
            'plugins-dir': '..',
            'plugins': 'plugin_one plugin_two'
        })

        class Service:
            def __init__(self):
                self.pollable_plugins = []

        service = Service()
        plugins.load(service)
        self.assertEquals(plugins.plugins[0].service, service)
        self.assertEquals(plugins.plugins[1].service, service)
        self.assertEquals(service.pollable_plugins[0], plugins.plugins[1])
        self.assertEquals(len(service.pollable_plugins), 1)
Exemple #8
0
    def test02_auth_plugin(self):
        '''Auth plugins must be registered on the service object'''

        plugins = CardstoriesPlugins({
            'plugins-dir': '..',
            'plugins': 'plugin_auth'
        })

        class Service:
            def __init__(self):
                self.auth = None

        service = Service()
        plugins.load(service)
        self.assertEquals(plugins.plugins[0].service, service)
        self.assertEquals(service.auth, plugins.plugins[0])
        self.assertIsInstance(service.auth, Auth)
Exemple #9
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
Exemple #10
0
def makeService(settings):
    service_collection = service.MultiService()
    cardstories_service = CardstoriesService(settings)
    plugins = CardstoriesPlugins(settings)
    plugins.load(cardstories_service)
    cardstories_service.setServiceParent(service_collection)

    site = CardstoriesSite(CardstoriesTree(cardstories_service), settings, plugins.plugins)

    if settings.get("manhole", None):
        internet.TCPServer(2222, getManholeFactory(locals(), user="******"), interface="127.0.0.1").setServiceParent(
            service_collection
        )

    internet.TCPServer(settings["port"], site, interface=settings.get("interface", "127.0.0.1")).setServiceParent(
        service_collection
    )

    # if settings.has_key('ssl-port') and settings['ssl-port']:
    #     internet.SSLServer(settings['ssl-port'], site, SSLContextFactory(settings)
    #                        ).setServiceParent(service_collection)

    return service_collection
Exemple #11
0
 def test00_path(self):
     plugins = CardstoriesPlugins({'plugins-dir': '..'})
     self.assertEquals(plugins.path('../plugin_one/plugin_one.py'),
                       '../plugin_one/plugin_one.py')
     self.assertEquals(plugins.path('plugin_one'),
                       '../plugin_one/plugin_one.py')
     caught = False
     try:
         plugins.path('WTF')
     except UserWarning, e:
         self.failUnlessSubstring('WTF', e.args[0])
         caught = True