def run(): """ ./bin/agx dev/agx.transform.xmi2uml/referencemodels/examplegg.uml -p dev/agx.transform.xmi2uml/referencemodels/pyegg.profile.uml -o /opt/agxtest/ """ XMLConfig('configure.zcml', agx.dev)() agx.core.main.run()
def setUp(self): super(TestClassDirective, self).setUp() XMLConfig('meta.zcml', zope.security)() try: del ExampleClass.__implements__ except AttributeError: pass
def test_Renderer(self): import quotationtool.renderer XMLConfig('configure.zcml', quotationtool.renderer)() pt = zope.component.createObject('plaintext', 'hello world') from quotationtool.renderer.interfaces import IHTMLRenderer r = IHTMLRenderer(pt) self.assertTrue(r.render() == u'hello world') self.assertTrue(r.render(limit=5) == u'hello...')
def setUpZCML(test): """ >>> XMLConfig('configure.zcml', quotationtool.biblatex.browser)() """ setUp(test) XMLConfig('configure.zcml', quotationtool.biblatex.browser)() return
def clearZCML(test=None): from zope.configuration.xmlconfig import XMLConfig import zope.component from zope.component.testing import setUp from zope.component.testing import tearDown tearDown() setUp() XMLConfig('meta.zcml', zope.component)()
def setup_class(cls): """Setup test class.""" class MockEndpoint(botocore.endpoint.Endpoint): def __init__(self, host, *args, **kwargs): super().__init__(queue_url(), *args, **kwargs) botocore.endpoint.Endpoint = MockEndpoint XMLConfig('configure.zcml', common)()
def testMenuItemsPermission(self): XMLConfig('tests/menus-permissions.zcml', zope.browsermenu)() menu = zope.component.getUtility(IBrowserMenu, 'test_id') # This is a bit icky, but the menu hides too much stuff from us. items = zope.component.getAdapters((C2(), TestRequest()), menu.getMenuItemType()) item = list(items)[0][1] self.assertEquals("zope.View", item.permission)
def setUpZCML(self): """ We test ZCML here: >>> from zope.configuration.xmlconfig import XMLConfig >>> import quotationtool.commentary >>> XMLConfig('configure.zcml', quotationtool.commentary)() We also use this to bring up the config: """ XMLConfig('configure.zcml', quotationtool.commentary)()
def defineDirectives(): XMLConfig('meta.zcml', zope.security)() xmlconfig( StringIO("""<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(): setUp() import zope.app.component XMLConfig('meta.zcml', zope.app.component)() #import Products.Five #XMLConfig('meta.zcml', Products.Five)() import cornerstone.browser XMLConfig('base.zcml', cornerstone.browser)() return unittest.TestSuite([ doctest.DocFileSuite( file, package="cornerstone.browser", optionflags=optionflags, globs=dict(interact=interlude.interact, pprint=pprint), ) for file in TESTFILES ]) tearDown()
def setUpZCML(test): """ >>> import quotationtool.bibliography >>> from zope.configuration.xmlconfig import XMLConfig >>> XMLConfig('configure.zcml', quotationtool.bibliography)() """ setUp(test) XMLConfig('configure.zcml', quotationtool.bibliography)()
def configurationSetUp(self): """Set up Zope 3 test environment """ placelesssetup.setUp() # Ensure that the ZCML registrations in CMFonFive and PloneGetPaid are in effect # Also ensure the Five directives and permissions are available import Products.Five if not PLONE3: import Products.CMFonFive import Products.PloneGetPaid XMLConfig('configure.zcml', Products.Five)() XMLConfig('meta.zcml', Products.Five)() XMLConfig('configure.zcml', Products.PloneGetPaid)()
def setUpZCML(test): """ >>> import quotationtool.categorization >>> from zope.configuration.xmlconfig import XMLConfig >>> XMLConfig('configure.zcml', quotationtool.categorization)() """ setUp(test) XMLConfig('configure.zcml', quotationtool.categorization)()
def __call__(self): XMLConfig('configure.zcml', agx.generator.uml)() XMLConfig('configure.zcml', agx.generator.pyegg)() XMLConfig('configure.zcml', agx.generator.zca)() XMLConfig('configure.zcml', agx.generator.sql)() XMLConfig('configure.zcml', agx.generator.plone)() XMLConfig('configure.zcml', agx.generator.dexterity)() XMLConfig('configure.zcml', agx.generator.buildout)()
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_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_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_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 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_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 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 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 setUpZCML(test): XMLConfig('configure.zcml', quotationtool.commentary)() XMLConfig('configure.zcml', quotationtool.commentary.browser)()