Esempio n. 1
0
def configure(arguments):
    # Enable venuasianconfiguration
    if HAS_VENUSIANCONFIGURATION:
        import venusianconfiguration
        venusianconfiguration.enable()

    # BBB: Support Zope's global configuration context
    if HAS_ZOPE:
        try:
            import Zope2.App.zcml
            config = Zope2.App.zcml._context or ConfigurationMachine()
        except (ImportError, AttributeError):
            config = ConfigurationMachine()
    else:
        config = ConfigurationMachine()

    # Parse and evaluate configuration and plugins
    registerCommonDirectives(config)

    import transmogrifier
    xmlconfig.include(config, package=transmogrifier, file='meta.zcml')
    xmlconfig.include(config, package=transmogrifier, file='configure.zcml')

    # Resolve includes
    for include in set(arguments.get('--include')):
        package, filename = parse_include(include)
        if package and filename:
            package = importlib.import_module(package)
            xmlconfig.include(config, package=package, file=filename)
        elif package and HAS_VENUSIANCONFIGURATION:
            # Support including single module in the current working directory
            import venusianconfiguration
            venusianconfiguration.venusianscan(package, config)

    config.execute_actions()
Esempio n. 2
0
 def test_w_file_passed(self):
     from zope.configuration import xmlconfig
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.xmlconfig import registerCommonDirectives
     from zope.configuration import tests
     from zope.configuration.tests import simple
     context = ConfigurationMachine()
     registerCommonDirectives(context)
     before_stack = context.stack[:]
     context.package = tests
     fqn = _packageFile(tests, 'simple.zcml')
     logger = LoggerStub()
     with _Monkey(xmlconfig, logger=logger):
         self._callFUT(context, 'simple.zcml')
     self.assertEqual(len(logger.debugs), 1)
     self.assertEqual(logger.debugs[0], ('include %s' % fqn, (), {}))
     self.assertEqual(len(context.actions), 3)
     action = context.actions[0]
     self.assertEqual(action['callable'], simple.file_registry.append)
     self.assertEqual(action['includepath'], (fqn, ))
     self.assertEqual(action['args'][0].path,
                      _packageFile(tests, 'simple.py'))
     action = context.actions[1]
     self.assertEqual(action['callable'], simple.file_registry.append)
     self.assertEqual(action['includepath'], (fqn, ))
     self.assertEqual(action['args'][0].path,
                      _packageFile(tests, 'simple.zcml'))
     action = context.actions[2]
     self.assertEqual(action['callable'], simple.file_registry.append)
     self.assertEqual(action['includepath'], (fqn, ))
     self.assertEqual(action['args'][0].path,
                      _packageFile(tests, '__init__.py'))
     self.assertEqual(context.stack, before_stack)
     self.assertEqual(len(context._seen_files), 1)
     self.assertIn(fqn, context._seen_files)
Esempio n. 3
0
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('grokcore.site.meta', config)
    zcml.do_grok('grokcore.catalog.meta', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
Esempio n. 4
0
def grok(*module_names):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.compat', config)
    zcml.do_grok('grokcore.component.meta', config)
    for module_name in module_names:
        zcml.do_grok(module_name, config)
    config.execute_actions()
Esempio n. 5
0
 def test_w_files_passed_and_package(self):
     from zope.configuration import xmlconfig
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.xmlconfig import registerCommonDirectives
     from zope.configuration.tests import samplepackage
     from zope.configuration.tests.samplepackage import foo
     context = ConfigurationMachine()
     registerCommonDirectives(context)
     before_stack = context.stack[:]
     fqn1 = _packageFile(samplepackage, 'baz1.zcml')
     fqn2 = _packageFile(samplepackage, 'baz2.zcml')
     fqn3 = _packageFile(samplepackage, 'baz3.zcml')
     logger = LoggerStub()
     with _Monkey(xmlconfig, logger=logger):
         self._callFUT(context, package=samplepackage, files='baz*.zcml')
     self.assertEqual(len(logger.debugs), 3)
     self.assertEqual(logger.debugs[0], ('include %s', (fqn1, ), {}))
     self.assertEqual(logger.debugs[1], ('include %s', (fqn2, ), {}))
     self.assertEqual(logger.debugs[2], ('include %s', (fqn3, ), {}))
     self.assertEqual(len(context.actions), 2)
     action = context.actions[0]
     self.assertEqual(action['callable'], foo.data.append)
     self.assertEqual(action['includepath'], (fqn2, ))
     self.assertIsInstance(action['args'][0], foo.stuff)
     self.assertEqual(action['args'][0].args, (('x', (b'foo')), ('y', 2)))
     action = context.actions[1]
     self.assertEqual(action['callable'], foo.data.append)
     self.assertEqual(action['includepath'], (fqn3, ))
     self.assertIsInstance(action['args'][0], foo.stuff)
     self.assertEqual(action['args'][0].args, (('x', (b'foo')), ('y', 3)))
     self.assertEqual(context.stack, before_stack)
     self.assertEqual(len(context._seen_files), 3)
     self.assertIn(fqn1, context._seen_files)
     self.assertIn(fqn2, context._seen_files)
     self.assertIn(fqn3, context._seen_files)
Esempio n. 6
0
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('grokcore.security.meta', config)
    zcml.do_grok('grokcore.security.testing', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
Esempio n. 7
0
def grok(module_name=None):
    """Grok a module.

    Test helper to 'grok' a module named by `module_name`, a dotted
    path to a module like ``'mypkg.mymodule'``. 'grokking' hereby
    means to do all the ZCML configurations triggered by directives
    like ``grok.context()`` etc. This is only needed if your module
    was not `grokked` during test setup time as it normally happens
    with functional tests.
    """
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('grokcore.security.meta', config)
    zcml.do_grok('grokcore.view.meta', config)
    zcml.do_grok('grokcore.view.templatereg', config)
    zcml.do_grok('grokcore.viewlet.meta', config)
    zcml.do_grok('grokcore.formlib.meta', config)
    zcml.do_grok('grokcore.annotation.meta', config)
    zcml.do_grok('grokcore.site.meta', config)
    zcml.do_grok('grokcore.catalog.meta', config)
    zcml.do_grok('grokcore.traverser.meta', config)
    zcml.do_grok('grokcore.rest.meta', config)
    zcml.do_grok('grokcore.xmlrpc.meta', config)
    if module_name is not None:
        zcml.do_grok(module_name, config)
    config.execute_actions()
Esempio n. 8
0
    def test_after_outside_forms_context(self):
        import webob.multidict
        import schemaish
        from pyramid.view import render_view_to_response
        from pyramid_formish.zcml import FormAction
        from zope.configuration.config import ConfigurationMachine
        context = ConfigurationMachine()
        context.route_prefix = ''
        context.autocommit = True
        context.registry = self.config.registry
        request = testing.DummyRequest()
        request.registry = self.config.registry
        title = schemaish.String()
        factory = make_controller_factory(fields=[('title', title)])
        directive = self._makeOne(context, factory)
        directive._actions = [FormAction('submit', 'title', True)]
        directive.after()
        display = render_view_to_response(None, request, '')
        self.assertEqual(display.body, '123')

        request = testing.DummyRequest()
        request.params = webob.multidict.MultiDict()
        request.params['submit'] = True
        display = render_view_to_response(None, request, '')
        self.assertEqual(display.body, 'submitted')
Esempio n. 9
0
    def test_after_render_controller_curriedview(self):
        from pyramid.view import render_view_to_response
        from zope.configuration.config import ConfigurationMachine
        from pyramid_formish import ValidationError
        from pyramid.response import Response

        def view(context, request):
            return Response('response')

        context = ConfigurationMachine()
        context.route_prefix = ''
        context.autocommit = True
        context.registry = self.config.registry
        directive = self._makeOne(context, view=view)
        formdirective = DummyFormDirective()
        formdirective.controller = make_controller_factory(
            exception=ValidationError)
        directive.forms = [formdirective]
        directive.actions = []
        directive.after()
        request = testing.DummyRequest()
        request.params = {'__formish_form__': 'form_id', 'submit': True}
        display = render_view_to_response(None, request, '')
        self.assertEqual(display.body, 'response')
        self.assertEqual(len(request.forms), 1)
Esempio n. 10
0
    def testSetUp(cls, test=None):
        cls.context = ConfigurationMachine()
        registerCommonDirectives(cls.context)

        import transmogrifier
        xmlconfig.file('meta.zcml', transmogrifier, context=cls.context)
        xmlconfig.file('configure.zcml', transmogrifier, context=cls.context)

        cls.tempdir = tempfile.mkdtemp('transmogrifierTestConfigs')
Esempio n. 11
0
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('grokcore.security.meta', config)
    zcml.do_grok('grokcore.view.meta', config)
    zcml.do_grok('grokcore.view.templatereg', config)
    zcml.do_grok('grokcore.json', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
Esempio n. 12
0
def setup_module(module):
    config = ConfigurationMachine()
    testing.grok('grokcore.component.meta')
    testing.grok('dolmen.forms.base')
    testing.grok('dolmen.forms.ztk')
    testing.grok('dolmen.view.meta')
    testing.grok('ul.browser')
    testing.grok('ul.auth.browser')
    config.execute_actions()
    provideAdapter(echo_layout, (IRequest, Interface), ILayout, name='')
Esempio n. 13
0
 def test_neither_file_nor_files_passed(self):
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.tests import samplepackage
     context = ConfigurationMachine()
     context.package = samplepackage
     fqn = _packageFile(samplepackage, 'configure.zcml')
     self._callFUT(context)
     self.assertEqual(len(context.actions), 0)
     self.assertEqual(len(context._seen_files), 1)
     self.assertIn(fqn, context._seen_files)
Esempio n. 14
0
 def test_w_file_passed(self):
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration import tests
     context = ConfigurationMachine()
     context.package = tests
     fqn = _packageFile(tests, 'simple.zcml')
     self._callFUT(context, 'simple.zcml')
     self.assertEqual(len(context.actions), 0)
     self.assertEqual(len(context._seen_files), 1)
     self.assertIn(fqn, context._seen_files)
Esempio n. 15
0
 def test_w_empty_xml(self):
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.xmlconfig import registerCommonDirectives
     from zope.configuration.xmlconfig import ZopeSAXParseException
     from zope.configuration._compat import StringIO
     context = ConfigurationMachine()
     registerCommonDirectives(context)
     exc = self.assertRaises(ZopeSAXParseException,
                             self._callFUT, StringIO(), context)
     self.assertEqual(str(exc._v), '<string>:1:0: no element found')
Esempio n. 16
0
    def test_w_empty_xml(self):
        from io import StringIO
        from zope.configuration.config import ConfigurationMachine
        from zope.configuration.xmlconfig import registerCommonDirectives
        from zope.configuration.xmlconfig import ZopeSAXParseException

        context = ConfigurationMachine()
        registerCommonDirectives(context)
        with self.assertRaises(ZopeSAXParseException) as exc:
            self._callFUT(StringIO(), context)
        self.assertEqual(str(exc.exception.evalue),
                         '<string>:1:0: no element found')
Esempio n. 17
0
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('grokcore.view.meta.views', config)
    zcml.do_grok('grokcore.view.meta.templates', config)
    zcml.do_grok('grokcore.view.meta.skin', config)
    # Use the Five override for the page template factory
    # zcml.do_grok('grokcore.view.templatereg', config)
    zcml.do_grok('five.grok.templatereg', config)
    zcml.do_grok('five.grok.meta', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
Esempio n. 18
0
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('grokcore.security.meta', config)
    zcml.do_grok('grokcore.view.meta', config)
    zcml.do_grok('grokcore.view.templatereg', config)
    zcml.do_grok('grokcore.viewlet.meta', config)
    zcml.do_grok('grokcore.formlib.meta', config)
    zcml.do_grok('grokcore.annotation.meta', config)
    zcml.do_grok('grokcore.site.meta', config)
    zcml.do_grok('grok.meta', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
Esempio n. 19
0
 def test_w_files_passed_and_package(self):
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.tests import samplepackage
     context = ConfigurationMachine()
     fqn1 = _packageFile(samplepackage, 'baz1.zcml')
     fqn2 = _packageFile(samplepackage, 'baz2.zcml')
     fqn3 = _packageFile(samplepackage, 'baz3.zcml')
     self._callFUT(context, package=samplepackage, files='baz*.zcml')
     self.assertEqual(len(context.actions), 0)
     self.assertEqual(len(context._seen_files), 3)
     self.assertIn(fqn1, context._seen_files)
     self.assertIn(fqn2, context._seen_files)
     self.assertIn(fqn3, context._seen_files)
Esempio n. 20
0
def file(name, package=None, context=None, execute=True):
    """Execute a zcml file
    """

    if context is None:
        context = ConfigurationMachine()
        registerCommonDirectives(context)
        context.package = package

    include(context, name, package)
    if execute:
        context.execute_actions()

    return context
Esempio n. 21
0
 def test_w_subpackage(self):
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.tests import excludedemo
     from zope.configuration.tests.excludedemo import sub
     context = ConfigurationMachine()
     fqne_spam = _packageFile(excludedemo, 'spam.zcml')
     fqne_config = _packageFile(excludedemo, 'configure.zcml')
     fqns_config = _packageFile(sub, 'configure.zcml')
     self._callFUT(context, package=sub)
     self.assertEqual(len(context.actions), 0)
     self.assertEqual(len(context._seen_files), 1)
     self.assertFalse(fqne_spam in context._seen_files)
     self.assertFalse(fqne_config in context._seen_files)
     self.assertIn(fqns_config, context._seen_files)
Esempio n. 22
0
    def test_actions_have_parents_includepath(self):
        from zope.configuration import xmlconfig
        from zope.configuration.config import ConfigurationMachine
        from zope.configuration.xmlconfig import registerCommonDirectives
        from zope.configuration import tests
        from zope.configuration.tests import simple
        context = ConfigurationMachine()
        fqp = _packageFile(tests, 'configure.zcml')
        registerCommonDirectives(context)
        before_stack = context.stack[:]
        context.package = tests
        # dummy action, path from "previous" include
        context.includepath = (fqp, )

        def _callable():
            pass

        context.actions.append({
            'discriminator': None,
            'callable': _callable,
        })
        fqn = _packageFile(tests, 'simple.zcml')
        logger = LoggerStub()
        with _Monkey(xmlconfig, logger=logger):
            self._callFUT(context, 'simple.zcml')
        self.assertEqual(len(logger.debugs), 1)
        self.assertEqual(logger.debugs[0], ('include %s' % fqn, (), {}))
        self.assertEqual(len(context.actions), 4)
        action = context.actions[0]
        self.assertEqual(action['discriminator'], None)
        self.assertEqual(action['callable'], _callable)
        action = context.actions[1]
        self.assertEqual(action['callable'], simple.file_registry.append)
        self.assertEqual(action['includepath'], (fqp, ))
        self.assertEqual(action['args'][0].path,
                         _packageFile(tests, 'simple.py'))
        action = context.actions[2]
        self.assertEqual(action['callable'], simple.file_registry.append)
        self.assertEqual(action['includepath'], (fqp, ))
        self.assertEqual(action['args'][0].path,
                         _packageFile(tests, 'simple.zcml'))
        action = context.actions[3]
        self.assertEqual(action['callable'], simple.file_registry.append)
        self.assertEqual(action['includepath'], (fqp, ))
        self.assertEqual(action['args'][0].path,
                         _packageFile(tests, '__init__.py'))
        self.assertEqual(context.stack, before_stack)
        self.assertEqual(len(context._seen_files), 1)
        self.assertIn(fqn, context._seen_files)
Esempio n. 23
0
def string(s, context=None, name="<string>", execute=True):
    """Execute a zcml string
    """
    if context is None:
        context = ConfigurationMachine()
        registerCommonDirectives(context)

    f = StringIO(s)
    f.name = name
    processxmlfile(f, context)

    if execute:
        context.execute_actions()

    return context
Esempio n. 24
0
def get_configuration_context(package=None):
    """Get configuration context.

    Various functions take a configuration context as argument.
    From looking at zope.configuration.xmlconfig.file the following seems about right.

    Note: this is a copy of a function in plone.autoinclude.tests.utils.
    The duplication is deliberate: I don't want one package to import code from the other, for now.
    """
    context = ConfigurationMachine()
    registerCommonDirectives(context)
    if package is not None:
        # When you set context.package, context.path(filename) works nicely.
        context.package = package
    return context
Esempio n. 25
0
 def test_neither_file_nor_files_passed_already_seen(self):
     from zope.configuration import xmlconfig
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.xmlconfig import registerCommonDirectives
     from zope.configuration.tests import samplepackage
     context = ConfigurationMachine()
     registerCommonDirectives(context)
     context.package = samplepackage
     fqn = _packageFile(samplepackage, 'configure.zcml')
     context._seen_files.add(fqn)
     logger = LoggerStub()
     with _Monkey(xmlconfig, logger=logger):
         self._callFUT(context)  #skips
     self.assertEqual(len(logger.debugs), 0)
     self.assertEqual(len(context.actions), 0)
Esempio n. 26
0
 def test_wo_execute_w_context(self):
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.xmlconfig import registerCommonDirectives
     from zope.configuration.tests.samplepackage import foo
     context = ConfigurationMachine()
     registerCommonDirectives(context)
     file_name = path("samplepackage", "configure.zcml")
     with open(file_name) as f:
         xml = f.read()
     ret = self._callFUT(xml, context=context, execute=False)
     self.assertTrue(ret is context)
     self.assertEqual(len(foo.data), 0)
     self.assertEqual(len(context.actions), 1)
     action = context.actions[0]
     self.assertEqual(action['discriminator'], (('x', (b'blah')), ('y', 0)))
     self.assertEqual(action['callable'], foo.data.append)
Esempio n. 27
0
        def xmlconfig(s, config=config):
            from zope.configuration.config import ConfigurationMachine
            from zope.configuration.xmlconfig import registerCommonDirectives
            from zope.configuration.xmlconfig import string

            context = ConfigurationMachine()
            context.config_class = type(config)
            context.autocommit = True
            context.registry = config.registry
            context.route_prefix = None
            context.actions = config.action_state.actions
            context.introspection = False

            registerCommonDirectives(context)

            string(s, context=context, execute=False)
            config.commit()
Esempio n. 28
0
    def test_after_render_controller_submission(self):
        from pyramid.view import render_view_to_response
        from zope.configuration.config import ConfigurationMachine

        context = ConfigurationMachine()
        context.route_prefix = ''
        context.registry = self.config.registry
        context.autocommit = True
        directive = self._makeOne(context, view=None)
        directive.forms = [DummyFormDirective()]
        directive.actions = []
        directive.after()
        request = testing.DummyRequest()
        request.params = {'__formish_form__': 'form_id', 'submit': True}
        display = render_view_to_response(None, request, '')
        self.assertEqual(display.body, 'submitted')
        self.assertEqual(len(request.forms), 1)
Esempio n. 29
0
    def test_after_render_view(self):
        from pyramid.view import render_view_to_response
        from zope.configuration.config import ConfigurationMachine
        from pyramid.response import Response

        def view(context, request):
            return Response('response')

        context = ConfigurationMachine()
        context.route_prefix = ''
        context.registry = self.config.registry
        context.autocommit = True
        directive = self._makeOne(context, view=view)
        directive.forms = [DummyFormDirective()]
        directive.actions = []
        directive.after()
        request = testing.DummyRequest()
        display = render_view_to_response(None, request, '')
        self.assertEqual(display.body, 'response')
        self.assertEqual(len(request.forms), 1)
Esempio n. 30
0
def grok_component(name, component,
                   context=None, module_info=None, templates=None, dotted_name=None):
    if module_info is None:
        if dotted_name is None:
            dotted_name = getattr(component, '__grok_module__', None)
            if dotted_name is None:
                dotted_name = getattr(component, '__module__', None)
            module_info = scan.module_info_from_dotted_name(dotted_name)
        module_info = scan.module_info_from_dotted_name(dotted_name)

    module = module_info.getModule()
    if context is not None:
        grokcore.component.context.set(module, context)
    if templates is not None:
        module.__grok_templates__ = templates
    config = ConfigurationMachine()
    result = zcml.the_multi_grokker.grok(name, component,
                                         module_info=module_info,
                                         config=config)
    config.execute_actions()    
    return result