def setUpZope(self, app, configurationContext):
        # Load any other ZCML that is required for your tests.
        # The z3c.autoinclude feature is disabled in the Plone fixture base
        # layer.
        import plone.restapi

        self.loadZCML(package=plone.restapi)

        import collective.elasticsearch

        self.loadZCML(package=collective.elasticsearch)

        import plone.app.fhirfield

        self.loadZCML(package=plone.app.fhirfield)

        import collective.MockMailHost

        self.loadZCML(package=collective.MockMailHost)

        import collective.fhirpath

        self.loadZCML(package=collective.fhirpath)
        # initialize method not calling automatically
        z2.installProduct(app, "collective.fhirpath")
        # Load Custom
        if str(EXAMPLE_RESTAPI_DIR) not in sys.path[:]:
            sys.path.append(str(EXAMPLE_RESTAPI_DIR))

        xmlconfig.string(TEST_ZCML, context=configurationContext)
    def testRegisterDistributedTranslations(self):
        from zope.configuration import xmlconfig
        self.assert_(queryUtility(ITranslationDomain, 'zope-i18n') is None)
        xmlconfig.string(
            template % '''
            <configure package="zope.i18n.tests">
            <i18n:registerTranslations directory="locale" />
            </configure>
            ''', self.context)
        xmlconfig.string(
            template % '''
            <configure package="zope.i18n.tests">
            <i18n:registerTranslations directory="locale2" />
            </configure>
            ''', self.context)
        path1 = os.path.join(os.path.dirname(zope.i18n.tests.__file__),
                             'locale', 'en', 'LC_MESSAGES', 'zope-i18n.mo')
        path2 = os.path.join(os.path.dirname(zope.i18n.tests.__file__),
                             'locale2', 'en', 'LC_MESSAGES', 'zope-i18n.mo')
        util = getUtility(ITranslationDomain, 'zope-i18n')
        self.assertEquals(util._catalogs.get('test'), ['test', 'test'])
        self.assertEquals(util._catalogs.get('en'),
                          [unicode(path1), unicode(path2)])

        msg = util.translate(u'Additional message', target_language='en')
        self.assertEquals(msg, u'Additional message translated')

        msg = util.translate(u'New Domain', target_language='en')
        self.assertEquals(msg, u'New Domain translated')

        msg = util.translate(u'New Language', target_language='en')
        self.assertEquals(msg, u'New Language translated')
Example #3
0
    def setUpZope(self, app, configurationContext):
        # load ZCML
        import plone.app.blocks
        self.loadZCML(package=plone.app.blocks)

        # Register directory for testing
        xmlconfig.string("""\
<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:plone="http://namespaces.plone.org/plone"
    i18n_domain="plone"
    package="plone.app.blocks.tests">

    <plone:static
        type="sitelayout"
        name="testlayout1"
        directory="resources/sitelayout/testlayout1"
        />

    <plone:static
        type="sitelayout"
        name="testlayout2"
        directory="resources/sitelayout/testlayout2"
        />

</configure>
""",
                         context=configurationContext)
        if 'virtual_hosting' not in app.objectIds():
            # If ZopeLite was imported, we have no default virtual
            # host monster
            from Products.SiteAccess.VirtualHostMonster \
                import manage_addVirtualHostMonster
            manage_addVirtualHostMonster(app, 'virtual_hosting')
Example #4
0
    def setUpZope(self, app, configurationContext):
        # do not install pas plugins (doesnt work in tests)
        from opengever.ogds.base import hooks
        hooks._setup_scriptable_plugin = lambda *a, **kw: None

        xmlconfig.string(
            '<configure xmlns="http://namespaces.zope.org/zope">'
            '  <include package="z3c.autoinclude" file="meta.zcml" />'
            '  <includePlugins package="plone" />'
            '  <includePluginsOverrides package="plone" />'
            '  <include package="opengever.ogds.base" file="tests.zcml" />'
            '  <include package="opengever.base.tests" file="tests.zcml" />'
            '  <include package="opengever.testing" file="tests.zcml" />'
            '  <include package="opengever.setup.tests" />'
            '</configure>',
            context=configurationContext)

        z2.installProduct(app, 'plone.app.versioningbehavior')
        z2.installProduct(app, 'collective.taskqueue.pasplugin')
        z2.installProduct(app, 'Products.CMFPlacefulWorkflow')

        setupCoreSessions(app)

        # Set max subobject limit to 0 -> unlimited
        # In tests this is set to 100 by default
        transient_object_container = app.temp_folder.session_data
        transient_object_container.setSubobjectLimit(0)

        os.environ['BUMBLEBEE_DEACTIVATE'] = "True"

        import opengever.base.tests.views
        xmlconfig.file('configure.zcml',
                       opengever.base.tests.views,
                       context=configurationContext)
Example #5
0
    def test_viewlet_manager_in_same_zcml(self):
        assert_that(viewlets, does_not(has_property('ILeftColumn')))
        zcml = """
        <configure xmlns="http://namespaces.zope.org/zope"
                   xmlns:browser="http://namespaces.zope.org/browser">
          <include package="nti.nikola_chameleon" file="meta.zcml" />
          <include package="zope.viewlet" file="meta.zcml" />
          <browser:newViewletManager
              id="ILeftColumn" />
          <browser:viewletManager
              name="left_column"
              provides="nti.nikola_chameleon.viewlets.ILeftColumn"
              permission="zope.Public" />
        </configure>
        """

        xmlconfig.string(zcml)
        assert_that(viewlets, has_property('ILeftColumn'))

        context = object()
        from zope.publisher.browser import TestRequest
        request = TestRequest()
        from zope.publisher.browser import BrowserView
        view = BrowserView(context, request)

        import zope.component
        from zope.viewlet import interfaces
        zope.component.getMultiAdapter((context, request, view),
                                       interfaces.IViewletManager,
                                       name='left_column')

        zope.component.getMultiAdapter((context, request, view),
                                       viewlets.ILeftColumn,
                                       name='left_column')
def zcml(s, execute=True):
    from zope.app.appsetup.appsetup import __config_context as context
    try:
        xmlconfig.string(s, context, execute=execute)
    except:
        context.end()
        raise
Example #7
0
    def setUpZope(self, app, configurationContext):
        xmlconfig.string(
            '<configure xmlns="http://namespaces.zope.org/zope">'
            '  <include package="z3c.autoinclude" file="meta.zcml" />'
            '  <includePlugins package="plone" />'
            '  <includePluginsOverrides package="plone" />'
            '  <include package="Products.CMFPlacefulWorkflow" />'
            '</configure>',
            context=configurationContext)

        # DatagridField doesn't define the auto-include entry point
        import Products.DataGridField
        xmlconfig.file('configure.zcml',
                       Products.DataGridField,
                       context=configurationContext)

        z2.installProduct(app, 'ftw.workspace')
        z2.installProduct(app, 'ftw.file')
        z2.installProduct(app, 'ftw.meeting')
        z2.installProduct(app, 'Products.DataGridField')
        z2.installProduct(app, 'egov.contactdirectory')
        z2.installProduct(app, 'Products.CMFPlacefulWorkflow')
        # Dep. of egov.contactdirectory
        z2.installProduct(app, 'ftw.contentpage')
        z2.installProduct(app, 'simplelayout.types.common')
Example #8
0
def initialize_1(config_path=None):
    """First initialization step.

    * Zope component architecture
    * The configuration system
    * Run-time directories

    :param config_path: The path to the configuration file.
    :type config_path: string
    """
    zcml = resource_string('mailman.config', 'configure.zcml')
    xmlconfig.string(zcml)
    # By default, set the umask so that only owner and group can read and
    # write our files.  Specifically we must have g+rw and we probably want
    # o-rwx although I think in most cases it doesn't hurt if other can read
    # or write the files.
    os.umask(0o007)
    # Initialize configuration event subscribers.  This must be done before
    # setting up the configuration system.
    from mailman.app.events import initialize as initialize_events
    initialize_events()
    # config_path will be set if the command line argument -C is given.  That
    # case overrides all others.  When not given on the command line, the
    # configuration file is searched for in the file system.
    if config_path is None:
        config_path = search_for_configuration_file()
    elif config_path is INHIBIT_CONFIG_FILE:
        # For the test suite, force this back to not using a config file.
        config_path = None
    mailman.config.config.load(config_path)
    def setUpZope(self, app, configurationContext):
        # Load ZCML for this package

        # xmlconfig.file('configure.zcml', Products.DateRecurringIndex,
        #                context=configurationContext)
        # xmlconfig.file('configure.zcml', plone.app.event,
        #                context=configurationContext)

        z2.installProduct(app, 'Products.DateRecurringIndex')
        xmlconfig.file('configure.zcml', plone.app.contenttypes,
                       context=configurationContext)
        xmlconfig.file('configure.zcml', collective.tinymcetiles,
                       context=configurationContext)
        xmlconfig.file('configure.zcml', plone.app.contentlistingtile,
                       context=configurationContext)
        xmlconfig.string("""\
<configure package="collective.tinymcetiles"
           xmlns="http://namespaces.plone.org/plone">
    <tile
        name="dummy.tile"
        title="Dummy tile"
        description="dummy"
        add_permission="cmf.ModifyPortalContent"
        class=".testing.DummyTile"
        permission="zope2.View"
        for="*"
        />
</configure>
""", context=configurationContext)
Example #10
0
    def setUpZope(self, app, configurationContext):
        xmlconfig.string("""\
<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:plone="http://namespaces.plone.org/plone"
    i18n_domain="plone.app.blocks">

  <include package="plone.tiles" file="meta.zcml" />

  <plone:tile
      name="test.tile1"
      title="Test Tile"
      description=""
      add_permission="cmf.ModifyPortalContent"
      schema="plone.app.blocks.tests.test_tiles.ITestTile"
      class="plone.app.blocks.tests.test_tiles.TestTile"
      permission="zope2.View"
      for="*"
      />

  <plone:tile
      name="test.tile1.broken"
      title="Broken Test Tile"
      description=""
      add_permission="cmf.ModifyPortalContent"
      schema="plone.app.blocks.tests.test_tiles.ITestTile"
      class="plone.app.blocks.tests.test_tiles.TestTileBroken"
      permission="zope2.View"
      for="*"
      />

</configure>
""",
                         context=configurationContext)
Example #11
0
    def setUpZope(self, app, configurationContext):
        xmlconfig.string(
            '<configure xmlns="http://namespaces.zope.org/zope">'
            '  <include package="z3c.autoinclude" file="meta.zcml" />'
            '  <includePlugins package="plone" />'
            '  <includePluginsOverrides package="plone" />'
            '</configure>',
            context=configurationContext)

        # Load ZCML
        import ftw.subsite
        xmlconfig.file('configure.zcml', ftw.subsite,
                       context=configurationContext)

        xmlconfig.file('overrides.zcml', ftw.subsite,
                       context=configurationContext)

        # import plone.app.portlets
        # xmlconfig.file('configure.zcml', plone.app.portlets,
        #                context=configurationContext)

        # import collective.MockMailHost
        # xmlconfig.file('configure.zcml', collective.MockMailHost,
        #                context=configurationContext)

        # installProduct() is *only* necessary for packages outside
        # the Products.* namespace which are also declared as Zope 2 products,
        # using <five:registerPackage /> in ZCML.
        z2.installProduct(app, 'plone.app.portlets')
        z2.installProduct(app, 'ftw.subsite')
        z2.installProduct(app, 'ftw.simplelayout')
        z2.installProduct(app, 'collective.MockMailHost')
Example #12
0
    def setUpZope(self, app, configurationContext):
        xmlconfig.string(
            '<configure xmlns="http://namespaces.zope.org/zope">'
            '  <include package="z3c.autoinclude" file="meta.zcml" />'
            '  <includePlugins package="plone" />'
            '  <includePluginsOverrides package="plone" />'
            "</configure>",
            context=configurationContext,
        )

        import Products.CMFPlacefulWorkflow

        xmlconfig.file("configure.zcml", Products.CMFPlacefulWorkflow, context=configurationContext)

        try:
            # Plone >= 4.3.x
            import Products.DataGridField

            xmlconfig.file("configure.zcml", Products.DataGridField, context=configurationContext)
        except:
            pass

        z2.installProduct(app, "ftw.file")
        z2.installProduct(app, "ftw.meeting")
        z2.installProduct(app, "ftw.mail")
        z2.installProduct(app, "ftw.workspace")
Example #13
0
    def setUpProducts(self, app):
        super(ZopeLayer, self).setUpProducts(app)
        configurationContext = self['configurationContext']

        # Plone < 4.3
        import Products.GenericSetup
        xmlconfig.file('meta.zcml', Products.GenericSetup,
                       context=configurationContext)

        import Products.CMFPlacefulWorkflow
        xmlconfig.file('configure.zcml', Products.CMFPlacefulWorkflow,
                       context=configurationContext)

        if IS_PLONE_5:
            xmlconfig.string('''
            <configure>
            <include package="plone.app.caching" />
            <include package="plonetheme.barceloneta" />
            </configure>''', context=configurationContext)

        z2.installProduct(app, 'Products.CMFPlacefulWorkflow')

        import Products.Five
        xmlconfig.file('meta.zcml', Products.Five,
                       context=configurationContext)

        import ftw.inflator
        xmlconfig.file('configure.zcml', ftw.inflator,
                       context=configurationContext)
        xmlconfig.file('overrides.zcml', ftw.inflator,
                       context=configurationContext)
        xmlconfig.file('configure.zcml', ftw.inflator.tests,
                       context=configurationContext)

        apply_patches()
Example #14
0
    def setUpZope(self, app, configurationContext):
        import Products.CMFPlacefulWorkflow
        xmlconfig.file('configure.zcml', Products.CMFPlacefulWorkflow,
                       context=configurationContext)

        z2.installProduct(app, 'Products.CMFPlacefulWorkflow')

        if IS_PLONE_APP_MULTILINGUAL_2:
            z2.installProduct(app, 'Products.DateRecurringIndex')

        import ftw.inflator
        xmlconfig.file('configure.zcml', ftw.inflator,
                       context=configurationContext)

        xmlconfig.file('configure.zcml', ftw.inflator.tests,
                       context=configurationContext)

        import plone.app.multilingual
        xmlconfig.file('configure.zcml', plone.app.multilingual,
                       context=configurationContext)

        import plone.app.dexterity
        xmlconfig.file('configure.zcml', plone.app.dexterity,
                       context=configurationContext)

        xmlconfig.string(
            '<configure xmlns="http://namespaces.zope.org/zope">'
            '  <include package="z3c.autoinclude" file="meta.zcml" />'
            '  <includePlugins package="plone" />'
            '  <includePluginsOverrides package="plone" />'
            '</configure>',
            context=configurationContext)

        setupCoreSessions(app)
Example #15
0
    def setUpZope(self, app, configurationContext):
        # load ZCML
        import plone.app.blocks
        self.loadZCML(package=plone.app.blocks)
        
        # Register directory for testing
        xmlconfig.string("""\
<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:plone="http://namespaces.plone.org/plone"
    i18n_domain="plone"
    package="plone.app.blocks.tests">
    
    <plone:static
        type="sitelayout"
        name="testlayout1"
        directory="resources/sitelayout/testlayout1"
        />
    
    <plone:static
        type="sitelayout"
        name="testlayout2"
        directory="resources/sitelayout/testlayout2"
        />

</configure>
""", context=configurationContext)
Example #16
0
    def test_configure(self):
        _ = xmlconfig.string(r"""
        <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope">
        <include package="zope.browsermenu" file="meta.zcml" />
        <menu
          id="zmi_views"
          title="Views"
          />

        <menu
          id="zmi_actions"
          title="Actions"
        />
        </configure>
        """)

        xmlconfig.string(r"""
        <configure xmlns="http://namespaces.zope.org/zope">
          <include package="zope.app.broken" />
        </configure>
        """)
        from zope import component
        from zope.interface import implementer

        from zope.publisher.interfaces.browser import IDefaultBrowserLayer
        @implementer(IDefaultBrowserLayer)
        class Layer(object):
            pass

        self.assertIsNotNone(component.getMultiAdapter(
            (Broken(), Layer()),
            name='index.html'))
Example #17
0
    def setUpZCML(self):
        """Load the basic ZCML configuration from Five. Exposes a resource
        ``configurationContext`` which can be used to load further ZCML.
        """

        # Push a new global registry so that we can cleanly tear down all ZCML
        from plone.testing import zca
        zca.pushGlobalRegistry()

        # Load something akin to the default site.zcml without actually auto-
        # loading products

        self['configurationContext'] = context = zca.stackConfigurationContext(
            self.get('configurationContext'))

        from zope.configuration import xmlconfig
        xmlconfig.string("""\
<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:meta="http://namespaces.zope.org/meta">

    <include package="Products.Five" />
    <meta:redefinePermission from="zope2.Public" to="zope.Public" />

    <securityPolicy component="Products.Five.security.FiveSecurityPolicy" />

</configure>
""",
                         context=context)
Example #18
0
    def setUpZope(self, app, configurationContext):
        # load ZCML
        import plone.app.blocks
        self.loadZCML(package=plone.app.blocks)

        # Register directory for testing
        xmlconfig.string("""\
<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:plone="http://namespaces.plone.org/plone"
    i18n_domain="plone"
    package="plone.app.blocks.tests">

    <plone:static
        type="sitelayout"
        name="testlayout1"
        directory="resources/sitelayout/testlayout1"
        />

    <plone:static
        type="sitelayout"
        name="testlayout2"
        directory="resources/sitelayout/testlayout2"
        />

</configure>
""", context=configurationContext)
        if 'virtual_hosting' not in app.objectIds():
            # If ZopeLite was imported, we have no default virtual
            # host monster
            from Products.SiteAccess.VirtualHostMonster \
                import manage_addVirtualHostMonster
            manage_addVirtualHostMonster(app, 'virtual_hosting')
Example #19
0
def zcml(s, execute=True):
    from zope.app.appsetup.appsetup import __config_context as context
    try:
        xmlconfig.string(s, context, execute=execute)
    except:
        context.end()
        raise
Example #20
0
    def testRegisterDistributedTranslations(self):
        from zope.configuration import xmlconfig
        self.assert_(queryUtility(ITranslationDomain, 'zope-i18n') is None)
        xmlconfig.string(
            template % '''
            <configure package="zope.i18n.tests">
            <i18n:registerTranslations directory="locale" />
            </configure>
            ''', self.context)
        xmlconfig.string(
            template % '''
            <configure package="zope.i18n.tests">
            <i18n:registerTranslations directory="locale2" />
            </configure>
            ''', self.context)
        path1 = os.path.join(os.path.dirname(zope.i18n.tests.__file__),
                             'locale', 'en', 'LC_MESSAGES', 'zope-i18n.mo')
        path2 = os.path.join(os.path.dirname(zope.i18n.tests.__file__),
                             'locale2', 'en', 'LC_MESSAGES', 'zope-i18n.mo')
        util = getUtility(ITranslationDomain, 'zope-i18n')
        self.assertEquals(util._catalogs.get('test'), ['test', 'test'])
        self.assertEquals(util._catalogs.get('en'),
                          [unicode(path1), unicode(path2)])

        msg = util.translate(u'Additional message', target_language='en')
        self.assertEquals(msg, u'Additional message translated')

        msg = util.translate(u'New Domain', target_language='en')
        self.assertEquals(msg, u'New Domain translated')

        msg = util.translate(u'New Language', target_language='en')
        self.assertEquals(msg, u'New Language translated')
Example #21
0
    def setUpZope(self, app, configurationContext):
        xmlconfig.string("""\
<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:plone="http://namespaces.plone.org/plone"
    i18n_domain="plone.app.blocks">

  <include package="plone.tiles" file="meta.zcml" />

  <plone:tile
      name="test.tile1"
      title="Test Tile"
      description=""
      add_permission="cmf.ModifyPortalContent"
      schema="plone.app.blocks.tests.test_tiles.ITestTile"
      class="plone.app.blocks.tests.test_tiles.TestTile"
      permission="zope2.View"
      for="*"
      />

  <plone:tile
      name="test.tile1.broken"
      title="Broken Test Tile"
      description=""
      add_permission="cmf.ModifyPortalContent"
      schema="plone.app.blocks.tests.test_tiles.ITestTile"
      class="plone.app.blocks.tests.test_tiles.TestTileBroken"
      permission="zope2.View"
      for="*"
      />

</configure>
""", context=configurationContext)
Example #22
0
    def setUpZCML(self):
        """Load the basic ZCML configuration from Five. Exposes a resource
        ``configurationContext`` which can be used to load further ZCML.
        """

        # Push a new global registry so that we can cleanly tear down all ZCML
        from plone.testing import zca
        zca.pushGlobalRegistry()

        # Load something akin to the default site.zcml without actually auto-
        # loading products

        self['configurationContext'] = context = zca.stackConfigurationContext(self.get('configurationContext'))

        from zope.configuration import xmlconfig
        xmlconfig.string("""\
<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:meta="http://namespaces.zope.org/meta">

    <include package="Products.Five" />
    <meta:redefinePermission from="zope2.Public" to="zope.Public" />

    <securityPolicy component="Products.Five.security.FiveSecurityPolicy" />

</configure>
""", context=context)
Example #23
0
def setUp(test):
    print "\n---------- SETUP ----------", test
    placelesssetup.setUp()
    xmlconfig.string(zcml_slug)
    metadata.create_all(checkfirst=True)
    # placelesssetup.tearDown() clears the registry
    print "\n---------- register_generic_workflow_adapters -------------", test
    adapters.register_generic_workflow_adapters()
    def test_scan_no_name(self):
        class O(object):
            __external_can_create__ = True

        self._addFactory(O)
        xmlconfig.string(self.SCAN_THIS_MODULE.replace('PLACEHOLDER', ''))
        factory = component.getUtility(IClassObjectFactory, 'O')
        assert_that(factory, has_property('_callable', equal_to(O)))
Example #25
0
def apply_customization_ui():
    """Called from ui.app.on_wsgi_application_created_event -- must be called
    AFTER custom types have been catalysed.
    """
    # combine config string and execute it
    zcml = ZCML_SLUG.format(ui_zcml_decls="".join([zd for zd in UI_ZC_DECLS]))
    log.debug("Executing UI feature configuration:\n%s" % (zcml))
    xmlconfig.string(zcml)
    def test_scan_module_with_factory_no_mime(self):
        class O(object):
            __external_can_create__ = True

        self._addFactory(O)
        xmlconfig.string(self.SCAN_THIS_MODULE)
        gsm = component.getGlobalSiteManager()
        assert_that(list(gsm.registeredUtilities()), is_empty())
Example #27
0
def setUp(test):
    print "\n---------- SETUP ----------", test
    placelesssetup.setUp()
    xmlconfig.string(zcml_slug)
    metadata.create_all(checkfirst=True)
    # placelesssetup.tearDown() clears the registry
    print "\n---------- register_generic_workflow_adapters -------------", test
    adapters.register_generic_workflow_adapters()
Example #28
0
 def setUpZope(self, app, configurationContext):
     xmlconfig.string(
         '<configure xmlns="http://namespaces.zope.org/zope">'
         '  <include package="z3c.autoinclude" file="meta.zcml" />'
         '  <includePlugins package="plone" />'
         '  <includePluginsOverrides package="plone" />'
         '</configure>',
         context=configurationContext)
Example #29
0
 def setUpZope(self, app, configurationContext):
     xmlconfig.string(
         '<configure xmlns="http://namespaces.zope.org/zope">'
         '  <include package="z3c.autoinclude" file="meta.zcml" />'
         '  <includePlugins package="plone" />'
         '  <includePluginsOverrides package="plone" />'
         '</configure>',
         context=configurationContext)
Example #30
0
def apply_customization_ui():
    """Called from ui.app.on_wsgi_application_created_event -- must be called
    AFTER custom types have been catalysed.
    """
    # combine config string and execute it
    zcml = ZCML_SLUG.format(ui_zcml_decls="".join([ zd for zd in UI_ZC_DECLS ]))
    log.debug("Executing UI feature configuration:\n%s" % (zcml))
    xmlconfig.string(zcml)
Example #31
0
    def test_five_product(self):
        basket = self._makeOne()

        basket.pdist_fname = os.path.join(self.fixtures,
                                          'pdist-fiveproduct.txt')

        sys.path.append(self.fixtures)
        self.working_set.add_entry(self.fixtures)

        self.failIf(sys.modules.has_key('Products.fiveproduct'))

        productcontext = DummyProductContext('Basket')

        basket.preinitialize()

        result = basket.initialize(productcontext)

        import Products.fiveproduct

        self.failUnless(sys.modules.has_key('Products.fiveproduct'))

        from Products.Five.fiveconfigure import findProducts
        from Products.Five.fiveconfigure import loadProducts
        from zope.configuration import xmlconfig

        products = findProducts()
        self.assert_(Products.fiveproduct in products)

        # do what Five.loadProduct does
        sitezcml = """\
        <configure xmlns="http://namespaces.zope.org/zope"
           xmlns:five="http://namespaces.zope.org/five">
           <include package="Products.Five" />
           <include package="Products.fiveproduct"/>
        </configure>"""

        xmlconfig.string(sitezcml)

        # verify that the zcml had the correct effect

        from Products.fiveproduct.module import SampleAdapter
        from Products.fiveproduct.module import ISampleAdapter
        from Products.fiveproduct.module import ExtraSampleAdapter
        from Products.fiveproduct.module import IExtraSampleAdapter

        context = None

        adapter = ISampleAdapter(context)
        self.assertEqual(adapter.__class__, SampleAdapter)
        self.assertEqual(adapter.context, context)

        adapter = IExtraSampleAdapter(context)
        self.assertEqual(adapter.__class__, ExtraSampleAdapter)
        self.assertEqual(adapter.context, context)

        view = getView(object(), 'example_view', FakeRequest())

        self.failUnless(view is not None)
Example #32
0
    def setUpZope(self, app, configurationContext):
        path = os.path.normpath(os.path.join(
            os.path.dirname(__file__), os.path.pardir, 'resources'))
        xmlconfig.string("""\
<configure xmlns="http://namespaces.zope.org/zope"
           xmlns:plone="http://namespaces.plone.org/plone">
  <plone:static directory="%s" />
</configure>
""" % path, context=configurationContext)
    def test_scan_module_with_factory_legacy(self):
        class O(object):
            __external_can_create__ = True
            mime_type = 'application/foo'

        self._addFactory(O)
        xmlconfig.string(self.SCAN_THIS_MODULE)
        assert_that(component.getUtility(IMimeObjectFactory, name=O.mime_type),
                    is_not(none()))
    def test_scan_package_inherited(self):
        # Issue #97: When interface tags are inherited,
        # we don't double register.
        import sys
        from zope.interface.interfaces import IInterface
        from ..interfaces import IInternalObjectIOFinder

        class IPublic(interface.Interface):
            pass

        class IPrivate(IPublic):
            pass

        @interface.implementer(IPublic)
        class Public(object):
            pass

        @interface.implementer(IPrivate)
        class Private(object):
            pass

        to_reg = (
            IPublic,
            IPrivate,
            Public,
            Private,
        )
        for r in to_reg:
            setattr(sys.modules[__name__], r.__name__, r)
        sys.modules[__name__].Alias = Private  # The alias triggers issue #97
        try:
            xmlconfig.string(self.SCAN_THIS_MODULE_TMPL % {
                'mod': __name__,
                'root': IPublic.__name__,
            })
            gsm = component.getGlobalSiteManager()

            ifaces = list(gsm.getAllUtilitiesRegisteredFor(IInterface))
            assert_that(
                set(ifaces),
                is_({
                    _ILegacySearchModuleFactory,
                    IInternalObjectIOFinder,
                    IPublic,
                    IMimeObjectFactory,
                }))
            mime_factories = list(
                gsm.getAllUtilitiesRegisteredFor(IMimeObjectFactory))
            assert_that(mime_factories, has_length(1))
            # The root interface was registered
            adapters = list(gsm.registeredAdapters())
            assert_that(adapters, has_length(1))
            assert_that(adapters[0], has_property('required', (IPublic, )))
        finally:
            for r in to_reg:
                delattr(sys.modules[__name__], r.__name__)
            del sys.modules[__name__].Alias
 def _runSnippet(self, snippet):
     from zope.configuration import xmlconfig
     template = """\
     <configure xmlns='http://namespaces.zope.org/zope'
                i18n_domain="zope">
        <include package="zope.component" file="meta.zcml" />
        %s
     </configure>""" % snippet
     xmlconfig.string(template)
    def test_scan_no_create(self):
        class O(object):
            pass

        self._addFactory(O)
        with self.assertRaisesRegex(
                xmlconfig.ZopeXMLConfigurationError,
                "must set __external_can_create__ to true"):
            xmlconfig.string(self.SCAN_THIS_MODULE)
    def test_scan_not_callable(self):
        class O(object):
            __external_can_create__ = True

        self._addFactory(O())

        with self.assertRaisesRegex(xmlconfig.ZopeXMLConfigurationError,
                                    "must be callable"):
            xmlconfig.string(self.SCAN_THIS_MODULE)
Example #38
0
 def setUpZope(self, app, configurationContext):
     import z3c.autoinclude
     xmlconfig.file('meta.zcml', z3c.autoinclude,
                    context=configurationContext)
     xmlconfig.string(
         '<configure xmlns="http://namespaces.zope.org/zope">'
         '  <includePlugins package="plone" />'
         '</configure>',
         context=configurationContext)
 def test_zcml_import_settings_works(self):
    context = xmlconfig.file('meta.zcml', collective.websocketclient)
    xmlconfig.string('''
       <configure xmlns:websocketclient="http://namespaces.plone.org/websocketclient">
           <websocketclient:connection name="test" host="127.0.0.1" port="9000"/>
       </configure>
    ''', context=context)
    cfg = queryUtility(IZCMLWebSocketConnectionConfig)
    self.assertEqual((cfg.name, cfg.host, cfg.port), ('test', '127.0.0.1',9000))
    def test_scan_not_direct(self):
        class O(object):
            __external_can_create__ = True

        self._addFactory(O)
        zcml = self.SCAN_THIS_MODULE.replace("ISchema", 'IDerived')

        with self.assertRaisesRegex(xmlconfig.ZopeXMLConfigurationError,
                                    "is not directly part of the interface"):
            xmlconfig.string(zcml)
Example #41
0
def zcml(s, execute=True, clear=(), site=None):
    zope.component.hooks.setSite(site)
    for i in clear:
        del resourcelibrary.library_info[i]
    from zope.app.appsetup.appsetup import __config_context as context
    try:
        xmlconfig.string(s, context, execute=execute)
    except:
        context.end()
        raise
Example #42
0
 def setUpZope(self, app, configurationContext):
     xmlconfig.string(
         '<configure xmlns="http://namespaces.zope.org/zope">'
         '  <include package="z3c.autoinclude" file="meta.zcml" />'
         '  <includePlugins package="plone" />'
         '  <includePluginsOverrides package="plone" />'
         '</configure>',
         context=configurationContext)
     setupCoreSessions(app)
     z2.installProduct(app, 'ftw.shop')
 def test_principal_and_role_not_allowed(self):
     with self.assertRaises(ConfigurationError):
         xmlconfig.string('''
              <configure xmlns="http://namespaces.zope.org/zope">
                <grantAll
                    role="zope.Bar"
                    principal="zope.Blah"
                    />
              </configure>
         ''', context=self.context)
 def test_PermRoleMap_does_not_allow_permission_and_permissions(self):
     with self.assertRaises(ConfigurationError):
         xmlconfig.string('''
              <configure xmlns="http://namespaces.zope.org/zope">
                <deny
                    permission="zope.Foo"
                    permissions="zope.Qwer zope.Qux"
                    />
              </configure>
         ''', context=self.context)
 def test_ZCMLconfigured_connection_creation(self):
    context = xmlconfig.file('meta.zcml', collective.websocketclient)
    xmlconfig.string('''
       <configure xmlns:websocketclient="http://namespaces.plone.org/websocketclient">
           <websocketclient:connection name="test" host="127.0.0.1" port="9000"/>
       </configure>
    ''', context=context)
    manager = queryUtility(IWebSocketConnectionManager)
    wsc_connection = manager.getConnection()
    self.assertEqual((wsc_connection.host, wsc_connection.port), ('127.0.0.1',9000))
 def test_default_layer(self):
     # By default all navigation classes are registered for
     # IDefaultBrowserLayer.
     directive = """ 
         <browser:navigation
             module="%(this)s" classes="ThingNavigation"/>
         """ % dict(this=this)
     xmlconfig.string(zcml_configure % directive)
     navigation = getMultiAdapter(
         (Thing(), DefaultBrowserLayer()), IBrowserPublisher, name='')
     self.assertIsInstance(navigation, ThingNavigation)
Example #47
0
    def setUpZope(self, app, configurationContext):
        xmlconfig.string(
            '<configure xmlns="http://namespaces.zope.org/zope">'
            '  <include package="z3c.autoinclude" file="meta.zcml" />'
            '  <includePlugins package="plone" />'
            '  <includePluginsOverrides package="plone" />'
            '</configure>',
            context=configurationContext)

        z2.installProduct(app, 'ftw.task')
        z2.installProduct(app, 'egov.contactdirectory')
Example #48
0
    def setUpZope(self, app, configurationContext):
        xmlconfig.string(
            '<configure xmlns="http://namespaces.zope.org/zope">'
            '  <include package="z3c.autoinclude" file="meta.zcml" />'
            '  <includePlugins package="plone" />'
            '  <includePluginsOverrides package="plone" />'
            '</configure>',
            context=configurationContext)

        z2.installProduct(app, 'ftw.linkchecker')
        z2.installProduct(app, 'ftw.simplelayout')
Example #49
0
    def setUpZope(self, app, configurationContext):
        xmlconfig.string(
            '<configure xmlns="http://namespaces.zope.org/zope">'
            '  <include package="z3c.autoinclude" file="meta.zcml" />'
            '  <includePlugins package="plone" />'
            '  <includePluginsOverrides package="plone" />'
            '</configure>',
            context=configurationContext)

        z2.installProduct(app, 'Products.PloneFormGen')
        z2.installProduct(app, 'ftw.xlsxsaveadapter')
Example #50
0
 def createTempDatabase(self, configurationContext):
     """Create database and update ZCML"""
     fileno, self.dbFileName = tempfile.mkstemp(suffix='.twquizdb.db')
     xmlconfig.string("""
       <configure xmlns="http://namespaces.zope.org/zope"
                  xmlns:db="http://namespaces.zope.org/db">
         <include package="z3c.saconfig" file="meta.zcml" />
         <db:engine name="tutorweb.quizdb" url="sqlite:///%s" />
         <db:session engine="tutorweb.quizdb" />
       </configure>
     """ % self.dbFileName, context=configurationContext)
    def test_scan_module_with_factory_imported(self):
        class O(object):
            __external_can_create__ = True
            mimeType = 'application/foo'

        O.__module__ = '__dynamic__'

        self._addFactory(O)
        xmlconfig.string(self.SCAN_THIS_MODULE)
        gsm = component.getGlobalSiteManager()
        assert_that(list(gsm.registeredUtilities()), is_empty())
Example #52
0
    def setUpZope(self, app, configurationContext):
        xmlconfig.string(
            '<configure xmlns="http://namespaces.zope.org/zope">'
            '  <include package="z3c.autoinclude" file="meta.zcml" />'
            '  <includePlugins package="plone" />'
            '  <includePluginsOverrides package="plone" />'
            '</configure>',
            context=configurationContext)

        z2.installProduct(app, 'ftw.task')
        z2.installProduct(app, 'egov.contactdirectory')
    def test_in_place(self):
        class O(object):
            __external_can_create__ = True

        self._addFactory(O)

        xmlconfig.string(self.SCAN_THIS_MODULE)

        obj = component.createObject(
            'nti.externalization.tests.test_zcml.ISchema:field2', self)
        assert_that(obj, is_(self))
Example #54
0
    def setUpZope(self, app, configurationContext):
        xmlconfig.string(
            '<configure xmlns="http://namespaces.zope.org/zope">'
            '  <include package="z3c.autoinclude" file="meta.zcml" />'
            '  <includePlugins package="plone" />'
            '  <includePluginsOverrides package="plone" />'
            '  <include package="plone.app.relationfield" />'
            '</configure>',
            context=configurationContext)

        z2.installProduct(app, 'ftw.servicenavigation')
 def test_cannot_specify_all_three_object_types(self):
     with self.assertRaises(ConfigurationError):
         xmlconfig.string('''
              <configure xmlns="http://namespaces.zope.org/zope">
                <deny
                    role="zope.Bar"
                    principal="zope.Blah"
                    permission="zope.Foo"
                    />
              </configure>
         ''', context=self.context)
Example #56
0
    def setUpZope(self, app, configurationContext):
        xmlconfig.string(
            '<configure xmlns="http://namespaces.zope.org/zope">'
            '  <include package="z3c.autoinclude" file="meta.zcml" />'
            '  <includePlugins package="plone" />'
            '  <includePluginsOverrides package="plone" />'
            '</configure>',
            context=configurationContext)

        z2.installProduct(app, 'Products.DateRecurringIndex')
        z2.installProduct(app, 'ftw.simplelayout')
Example #57
0
    def setUpZope(self, app, configurationContext):
        xmlconfig.string(
            '<configure xmlns="http://namespaces.zope.org/zope">'
            '  <include package="z3c.autoinclude" file="meta.zcml" />'
            '  <includePlugins package="plone" />'
            '  <includePluginsOverrides package="plone" />'
            '</configure>',
            context=configurationContext)

        z2.installProduct(app, 'ftw.zipextract')
        z2.installProduct(app, 'Products.DateRecurringIndex')
Example #58
0
    def setUpZCML(self):
        """Include imio.dms.mail i18n locales before Plone to override plone messages."""
        pr = list(self.products)
        pr.insert(-2, ('imio.dms.mail', {
            'loadZCML': True,
            'load_only': {
                'configure.zcml': 'testing_locales.zcml'
            }
        }))
        self.products = tuple(pr)

        # Create a new global registry
        zca.pushGlobalRegistry()

        from zope.configuration import xmlconfig
        self['configurationContext'] = context = zca.stackConfigurationContext(
            self.get('configurationContext'))

        # Turn off z3c.autoinclude
        xmlconfig.string("""\
<configure xmlns="http://namespaces.zope.org/zope" xmlns:meta="http://namespaces.zope.org/meta">
    <meta:provides feature="disable-autoinclude" />
</configure>
""",
                         context=context)

        from zope.dottedname.resolve import resolve

        def loadAll(filename):
            for p, config in self.products:
                if not config['loadZCML']:
                    continue
                # we don't want to load overrides.zcml now !
                if 'load_only' in config and filename not in config[
                        'load_only']:
                    continue
                try:
                    package = resolve(p)
                except ImportError:
                    continue
                try:
                    if 'load_only' in config and filename in config[
                            'load_only']:
                        xmlconfig.file(config['load_only'][filename],
                                       package,
                                       context=context)
                    else:
                        xmlconfig.file(filename, package, context=context)
                except IOError:
                    pass

        loadAll('meta.zcml')
        loadAll('configure.zcml')
        loadAll('overrides.zcml')