예제 #1
0
파일: testing.py 프로젝트: py361/grok
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()
예제 #2
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()
예제 #3
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()
예제 #4
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')
예제 #5
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)
예제 #6
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)
예제 #7
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()
예제 #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')
 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)
예제 #10
0
파일: testing.py 프로젝트: CGTIC/Plone_SP
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()
예제 #11
0
def grok(*modules):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('dolmen.viewlet.meta', config)
    for name in modules:
        zcml.do_grok(name, config)
    config.execute_actions()
예제 #12
0
파일: testing.py 프로젝트: clozinski/grok
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()
예제 #13
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()
예제 #14
0
 def load_zcml(self, zcml_asset_specification):
     def _get_site_manager(context=None):
         return self
     if ':' not in zcml_asset_specification:
         import alpaca
         config_package = alpaca
         config_file = zcml_asset_specification
     else:
         package_name, config_file = zcml_asset_specification.split(':')
         __import__(package_name)
         config_package = sys.modules[package_name]
     context = ConfigurationMachine()
     context.package = config_package
     xmlconfig.registerCommonDirectives(context)
     xmlconfig.file(
         config_file,
         package=config_package,
         context=context,
         execute=False
     )
     getSiteManager.sethook(_get_site_manager)
     try:
         context.execute_actions()
     finally:
         getSiteManager.reset()
예제 #15
0
def __main__():
    # Enable logging
    logging.basicConfig(level=logging.INFO)

    # Parse cli arguments
    arguments = docopt(__doc__)

    # Parse and evaluate configuration and plugins
    config = ConfigurationMachine()
    registerCommonDirectives(config)
    xmlconfig.include(config, package=collective.transmogrifier,
                      file='meta.zcml')
    xmlconfig.include(config, package=collective.transmogrifier,
                      file='configure.zcml')
    config.execute_actions()

    if arguments.get('--list'):
        blueprints = dict(getUtilitiesFor(ISectionBlueprint))
        pipelines = map(configuration_registry.getConfiguration,
                        configuration_registry.listConfigurationIds())
        print """
Available blueprints
--------------------
{0:s}

Available pipelines
-------------------
{1:s}
""".format('\n'.join(sorted(blueprints.keys())),
           '\n'.join(['{0:s}\n    {1:s}: {2:s}'.format(
                      p['id'], p['title'], p['description'])
                      for p in pipelines]))
        return

    # Load optional overrides
    overrides = {}
    overrides_path = arguments.get('--overrides')
    if overrides_path and not os.path.isabs(overrides_path):
        overrides_path = os.path.join(os.getcwd(), overrides_path)
    if overrides_path:
        parser = ConfigParser.RawConfigParser()
        parser.optionxform = str  # case sensitive
        with open(overrides_path) as fp:
            parser.readfp(fp)
        overrides.update(dict(((section, dict(parser.items(section)))
                               for section in parser.sections())))

    # Initialize optional context
    context_path = arguments.get('--context')
    if context_path is None:
        context = dict()
    else:
        context_module_path, context_class_name = context_path.rsplit('.', 1)
        context_module = importlib.import_module(context_module_path)
        context = getattr(context_module, context_class_name)()

    # Transmogrify
    for pipeline in arguments.get('<pipeline>'):
        ITransmogrifier(context)(pipeline, **overrides)
예제 #16
0
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('dolmen.view.meta', config)
    zcml.do_grok("dolmen.location", config)
    zcml.do_grok("dolmen.forms.base", config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
예제 #17
0
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('dolmen.view.meta', config)
    if HAS_SECURITY:
        zcml.do_grok('grokcore.security.meta', config)
        zcml.do_grok('dolmen.view.security', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
예제 #18
0
def grok(module_name):
    config = ConfigurationMachine()
    zcml.do_grok('grokcore.component.meta', config)
    zcml.do_grok('dolmen.viewlet.meta', config)
    zcml.do_grok('dolmen.location', config)
    zcml.do_grok('dolmen.menu.meta', config)
    zcml.do_grok('dolmen.menu.components', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
예제 #19
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.permission', config)
    zcml.do_grok(module_name, config)
    config.execute_actions()
예제 #20
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()
 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)
 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)
예제 #23
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)
예제 #24
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='')
예제 #25
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)
예제 #26
0
 def configure(self):
     gsm = component.getGlobalSiteManager
     component.getGlobalSiteManager = get_current_registry
     manager.push({'registry': self.registry})
     try:
         context = ConfigurationMachine()
         for action in self():
             context.action(*action)
         context.execute_actions()
     finally:
         component.getGlobalSiteManager = gsm
         manager.pop()
예제 #27
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()
예제 #28
0
파일: zcml.py 프로젝트: markramm/pyramid
def zcml_configure(name, package):
    """ Given a ZCML filename as ``name`` and a Python package as
    ``package`` which the filename should be relative to, load the
    ZCML into the current ZCML registry.

    """
    context = ConfigurationMachine()
    xmlconfig.registerCommonDirectives(context)
    context.package = package
    xmlconfig.include(context, name, package)
    context.execute_actions(clear=False) # the raison d'etre
    return context.actions
예제 #29
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()
예제 #30
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()
예제 #31
0
파일: xmlconfig.py 프로젝트: aregee/Mailman
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
예제 #32
0
def load_zcml(*args):
    """We rely on grok to load the configuration for our modules, but we depend on some libraries which
    have only zcml based configuration, thus we need to load only those we need."""

    from zope.configuration.config import ConfigurationMachine
    from zope.configuration import xmlconfig

    context = ConfigurationMachine()
    xmlconfig.registerCommonDirectives(context)

    for i in args:
        xmlconfig.include(context, "configure.zcml", context.resolve(i))

    context.execute_actions()
예제 #33
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
예제 #34
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)
예제 #35
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)
 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)
예제 #37
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.autocommit = True
            context.registry = config.registry
            context.route_prefix = None
            context.actions = config.action_state.actions

            registerCommonDirectives(context)

            string(s, context=context, execute=False)
            config.commit()
예제 #38
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
예제 #39
0
파일: xmlconfig.py 프로젝트: aregee/Mailman
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
예제 #40
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
예제 #41
0
def register_skin_view(relative_path, path, kwargs):
    registry = get_current_registry()

    for inst in registry.getAllUtilitiesRegisteredFor(ISkinObject):
        if inst.path == path:
            break
    else:
        raise RuntimeError("Skin object not found: %s." % relative_path)

    name = type(inst).component_name(relative_path).replace('/', '_')

    context = ConfigurationMachine()
    register_bfg_view(
        context, name=name, view=inst, **kwargs)
    context.execute_actions()
예제 #42
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)
예제 #43
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)
예제 #44
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)
 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():
         raise AssertionError("should not be called")
     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)
예제 #46
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()
예제 #47
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')
예제 #48
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)
예제 #49
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')
예제 #50
0
def grok_component(name, component,
                   context=None, module_info=None, templates=None):
    if module_info is None:
        obj_module = getattr(component, '__grok_module__', None)
        if obj_module is None:
            obj_module = getattr(component, '__module__', None)
        module_info = scan.module_info_from_dotted_name(obj_module)

    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
예제 #51
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)
예제 #52
0
 def test_w_valid_xml_fp(self):
     # Integration test, really
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.xmlconfig import registerCommonDirectives
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     file = open(path("samplepackage", "configure.zcml"))
     context = ConfigurationMachine()
     registerCommonDirectives(context)
     self._callFUT(file, context)
     self.assertEqual(foo.data, [])
     context.execute_actions()
     data = foo.data.pop()
     self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
     self.assertEqual(clean_info_path(repr(data.info)),
             'File "tests/samplepackage/configure.zcml", line 12.2-12.29')
     self.assertEqual(clean_info_path(str(data.info)),
             'File "tests/samplepackage/configure.zcml", line 12.2-12.29\n'
             + '    <test:foo x="blah" y="0" />')
     self.assertEqual(data.package, None)
     self.assertEqual(data.basepath, None)
예제 #53
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')
예제 #54
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
예제 #55
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)
예제 #56
0
 def test_neither_file_nor_files_passed(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[:]
     context.package = samplepackage
     fqn = _packageFile(samplepackage, 'configure.zcml')
     logger = LoggerStub()
     with _Monkey(xmlconfig, logger=logger):
         self._callFUT(context)
     self.assertEqual(len(logger.debugs), 1)
     self.assertEqual(logger.debugs[0], ('include %s' % fqn, (), {}))
     self.assertEqual(len(context.actions), 1)
     action = context.actions[0]
     self.assertEqual(action['callable'], foo.data.append)
     self.assertEqual(action['includepath'], (fqn, ))
     self.assertEqual(context.stack, before_stack)
     self.assertEqual(len(context._seen_files), 1)
     self.assertIn(fqn, context._seen_files)
예제 #57
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)