def test_zcml_can_load(self): import zope.traversing XMLConfig('configure.zcml', zope.traversing)() request = TestRequest() res = zope.component.getMultiAdapter((self, request), ITraversable, 'lang') import zope.traversing.namespace self.failUnless(isinstance(res, zope.traversing.namespace.lang)) self.failUnless(res.context is self)
def test_utility_lookup(self): """Test that this queue provides IQueue interfaces.""" from briefy import common from briefy.common.queue import IQueue from zope.component import getUtility from zope.configuration.xmlconfig import XMLConfig XMLConfig('configure.zcml', common)() queue = getUtility(IQueue, self.utility_name) assert isinstance(queue, self.queue)
def test_Factory(self): import quotationtool.renderer XMLConfig('configure.zcml', quotationtool.renderer)() implemented = zope.component.getFactoryInterfaces('plaintext') from quotationtool.renderer.interfaces import ISource, IPlainText self.assertTrue(implemented.isOrExtends(ISource)) self.assertTrue(implemented.isOrExtends(IPlainText)) pt = zope.component.createObject('plaintext', 'Hello World!') from quotationtool.renderer.plaintext import PlainText self.assertTrue(isinstance(pt, PlainText))
def test_MyPlainText(self): import quotationtool.renderer XMLConfig('configure.zcml', quotationtool.renderer)() from quotationtool.renderer.plaintext import PlainText from quotationtool.renderer.interfaces import IPlainText, ISource, ISourceFactory from zope.component.interfaces import IFactory factory = zope.component.factory.Factory(PlainText, title=u"my plain text", interfaces=IMySource) zope.component.provideUtility(factory, IMySourceFactory, 'myplaintext') factories = zope.component.getUtilitiesFor(IMySourceFactory) self.assertTrue(len(list(factories)) == 1)
def defineDirectives(): from zope.configuration.xmlconfig import XMLConfig from zope.configuration.xmlconfig import xmlconfig import zope.security XMLConfig('meta.zcml', zope.security)() xmlconfig( io.StringIO(u"""<configure xmlns='http://namespaces.zope.org/zope' i18n_domain='zope'> <permission id="zope.Extravagant" title="extravagant" /> <permission id="zope.Paltry" title="paltry" /> </configure>"""))
def test_suite(): XMLConfig('meta.zcml', zope.component)() return unittest.TestSuite([ doctest.DocFileSuite( file, optionflags=optionflags, globs={ 'pprint': pprint, 'tempdir': tempdir, 'interact': interlude.interact }, ) for file in TESTFILES ])
def testMenuItemWithLayer(self): XMLConfig('tests/menus.zcml', zope.browsermenu)() menu = zope.browsermenu.menu.getMenu('test_id', TestObject(), TestRequest()) self.assertEqual(len(menu), 6) menu = zope.browsermenu.menu.getMenu('test_id', TestObject(), TestRequest(skin=IMyLayer)) self.assertEqual(len(menu), 2) menu = zope.browsermenu.menu.getMenu('test_id', TestObject(), TestRequest(skin=IMySkin)) self.assertEqual(len(menu), 8)
def setUpOnlySome(test): """ Register only some components.""" from quotationtool.quotation.source import plainTextQuotationFactory, restQuotationFactory from quotationtool.quotation.source import QuotationSourceTypesVocabulary from quotationtool.quotation.interfaces import IQuotationSourceFactory from zope.schema.interfaces import IVocabularyFactory import zope.component zope.component.provideUtility(plainTextQuotationFactory, IQuotationSourceFactory, 'plaintext') zope.component.provideUtility(restQuotationFactory, IQuotationSourceFactory, 'rest') zope.component.provideUtility(QuotationSourceTypesVocabulary, IVocabularyFactory, 'quotationtool.quotation.SourceTypes') import zope import quotationtool XMLConfig('meta.zcml', zope.component)() XMLConfig('meta.zcml', zope.security)() XMLConfig('configure.zcml', zope.security)() XMLConfig('configure.zcml', zope.app.schema)() XMLConfig('configure.zcml', zope.component)() XMLConfig('configure.zcml', zope.security)() XMLConfig('configure.zcml', zope.site)() XMLConfig('configure.zcml', zope.annotation)() XMLConfig('configure.zcml', zope.dublincore)() XMLConfig('configure.zcml', quotationtool.site)() # subscribers from quotationtool.site.interfaces import INewQuotationtoolSiteEvent import quotationtool.relation zope.component.provideHandler(quotationtool.relation.createRelationCatalog, adapts=[INewQuotationtoolSiteEvent]) zope.component.provideHandler( quotationtool.quotation.quotation.createRelationIndex, adapts=[INewQuotationtoolSiteEvent]) # container object annotation from zope.annotation.interfaces import IAttributeAnnotatable
def test_it(self): import zope.component # no registrations made if not present ADAPTERS_REGISTERED = 4 from zope.configuration.xmlconfig import _clearContext from zope.configuration.xmlconfig import _getContext from zope.configuration.xmlconfig import XMLConfig import zope.location _clearContext() context = _getContext() XMLConfig('configure.zcml', zope.location) adapters = ([ x for x in context.actions if x['discriminator'] is not None ]) self.assertEqual(len(adapters), ADAPTERS_REGISTERED)
def testMenusAndMenuItems(self): XMLConfig('tests/menus.zcml', zope.browsermenu)() menu = zope.browsermenu.menu.getMenu('test_id', TestObject(), TestRequest()) def d(n): return { 'action': "a%s" % n, 'title': "t%s" % n, 'description': u'', 'selected': '', 'submenu': None, 'icon': None, 'extra': None } self.assertEqual(menu[:-1], [d(5), d(6), d(3), d(2), d(1)]) self.assertEqual( menu[-1], { 'submenu': [{ 'submenu': None, 'description': u'', 'extra': None, 'selected': u'', 'action': u'a10', 'title': u't10', 'icon': None }], 'description': u'', 'extra': None, 'selected': u'', 'action': u'', 'title': u's1', 'icon': None }) first = zope.browsermenu.menu.getFirstMenuItem('test_id', TestObject(), TestRequest()) self.assertEqual(first, d(5))
def configurationSetUp(test): setUp() import zope.browserpage import zope.component import zope.container import zope.contentprovider import zope.security XMLConfig('meta.zcml', zope.security)() XMLConfig('meta.zcml', zope.component)() XMLConfig('meta.zcml', zope.browserpage)() XMLConfig('configure.zcml', zope.component)() XMLConfig('configure.zcml', zope.security)() XMLConfig('configure.zcml', zope.container)() XMLConfig('configure.zcml', zope.contentprovider)() XMLConfig('configure.zcml', plone.portlets)()
def test_suite(): XMLConfig('testing/dummy_workflow.zcml', cone.app.tests)() suite = unittest.TestSuite() suite.addTests([ layered( doctest.DocFileSuite( testfile, globs={ 'interact': interlude.interact, 'pprint': pprint.pprint, 'pp': pprint.pprint, }, optionflags=optionflags, ), layer=layer, ) for testfile in TESTFILES ]) return suite
def test_configure_should_register_n_components(self): from zope.component import getGlobalSiteManager from zope.configuration.xmlconfig import XMLConfig import zope.annotation as MUT gsm = getGlobalSiteManager() u_count = len(list(gsm.registeredUtilities())) a_count = len(list(gsm.registeredAdapters())) s_count = len(list(gsm.registeredSubscriptionAdapters())) h_count = len(list(gsm.registeredHandlers())) XMLConfig('configure.zcml', MUT)() self.assertEqual(u_count + 2, len(list(gsm.registeredUtilities()))) self.assertEqual(a_count + 1, len(list(gsm.registeredAdapters()))) self.assertEqual(s_count, len(list(gsm.registeredSubscriptionAdapters()))) self.assertEqual(h_count, len(list(gsm.registeredHandlers())))
def setUpSome(test): """ There are subscribers that need intid in the dependencies (zope.catalog)""" import zope # some dependencies XMLConfig('meta.zcml', zope.component)() XMLConfig('meta.zcml', zope.security)() XMLConfig('meta.zcml', zope.securitypolicy)() XMLConfig('configure.zcml', zope.component)() XMLConfig('configure.zcml', zope.security)() XMLConfig('configure.zcml', zope.site)() XMLConfig('configure.zcml', quotationtool.site)() # subscribers from quotationtool.site.interfaces import INewQuotationtoolSiteEvent zope.component.provideHandler( quotationtool.relation.createRelationCatalog, adapts=[INewQuotationtoolSiteEvent])
def testDefaultSkin(self): request = TestRequest() self.assertEqual( component.queryMultiAdapter((ob, request), name='test'), None) XMLConfig('meta.zcml', zope.app.component)() xmlconfig( StringIO(template % (''' <interface interface=" zope.app.publisher.browser.tests.test_directives.ITestSkin" type="zope.publisher.interfaces.browser.IBrowserSkinType" name="Test Skin" /> <browser:defaultSkin name="Test Skin" /> <browser:page name="test" class="zope.app.component.tests.views.VZMI" layer=" zope.app.publisher.browser.tests.test_directives.ITestLayer" for="zope.app.component.tests.views.IC" permission="zope.Public" attribute="index" /> <browser:page name="test" class="zope.app.component.tests.views.V1" for="zope.app.component.tests.views.IC" permission="zope.Public" attribute="index" /> '''))) # Simulate Zope Publication behavior in beforeTraversal() adapters = component.getSiteManager().adapters skin = adapters.lookup((providedBy(request), ), IDefaultSkin, '') directlyProvides(request, skin) v = component.queryMultiAdapter((ob, request), name='test') self.assert_(issubclass(v.__class__, VZMI))
def testDefaultSkin(self): request = TestRequest() self.assertEqual( component.queryMultiAdapter((ob, request), name='test'), None) XMLConfig('meta.zcml', component)() xmlconfig( templated(''' <interface interface=" zope.publisher.tests.test_zcml.ITestSkin" type="zope.publisher.interfaces.browser.IBrowserSkinType" name="Test Skin" /> <browser:defaultSkin name="Test Skin" /> <view for="zope.publisher.tests.test_zcml.IOb" type="zope.publisher.interfaces.browser.IDefaultBrowserLayer" name="test" factory="zope.publisher.tests.test_zcml.V1" /> <view for="zope.publisher.tests.test_zcml.IOb" type="zope.publisher.tests.test_zcml.ITestLayer" name="test" factory="zope.publisher.tests.test_zcml.V2" /> ''')) # Simulate Zope Publication behavior in beforeTraversal() adapters = component.getSiteManager().adapters skin = adapters.lookup((providedBy(request), ), IDefaultSkin, '') directlyProvides(request, skin) v = component.queryMultiAdapter((ob, request), name='test') self.assertTrue(isinstance(v, V2))
def setUp(self): clearZCML() import plone.resource XMLConfig('meta.zcml', plone.resource)()
def setUp(self): super(Test, self).setUp() XMLConfig('meta.zcml', zope.browserresource)() provideAdapter(DefaultTraversable, (None, ), ITraversable)
def testZCML(self): self.assertTrue(XMLConfig('configure.zcml', beispiel)() is None)
def setUpZCML(test): setUp(test) XMLConfig('configure.zcml', quotationtool.quotation)()
def setUp(self): super(SiteCreationTests, self).setUp() setUpOnlySome(self) import quotationtool.site XMLConfig('configure.zcml', quotationtool.site)
def setUpZCML(test): setUp(test) XMLConfig('dependencies.zcml', quotationtool.biblatex)() XMLConfig('configure.zcml', quotationtool.biblatex)() XMLConfig('latex.zcml', quotationtool.biblatex)()
def configurationSetUp(test): setUp() import zope.component XMLConfig('meta.zcml', zope.component)() import plone.memoize XMLConfig('configure.zcml', plone.memoize)()
def vocabSetUp(self): setUp() import plone.app.vocabularies XMLConfig('meta.zcml', zope.component)() XMLConfig('configure.zcml', plone.app.vocabularies)() hooks.setHooks()
def setUp(self): XMLConfig('meta.zcml', zope.component)() XMLConfig('meta.zcml', collective.monkeypatcher)() XMLConfig('configure.zcml', collective.monkeypatcher)() XMLConfig('dummypatch.zcml', collective.monkeypatcher.tests)() return
def test_addMenuItemDirectives(self): XMLConfig('tests/addmenuitems.zcml', zope.browsermenu)()
def _meta(self): from zope.configuration.xmlconfig import XMLConfig import zope.security XMLConfig('meta.zcml', zope.security)()
def setUp(self): super(TestFactorySubdirective, self).setUp() XMLConfig('meta.zcml', zope.security)()
def setUpZCML(test): XMLConfig('configure.zcml', quotationtool.commentary)() XMLConfig('configure.zcml', quotationtool.commentary.browser)()
def setUp(self): super(TestAddMenuItem, self).setUp() XMLConfig('meta.zcml', zope.component)() XMLConfig('meta.zcml', zope.browsermenu)()