def test_factory_registered_on_scan(self): self.config.scan("voteit.feed.models") factory = self.config.registry.queryUtility(IFactory, "FeedEntry") self.failUnless(IFactory.providedBy(factory)) obj = factory("uid", "message") self.failUnless(obj) obj = createObject("FeedEntry", "uid", "message") self.failUnless(obj)
def test_factory_registered_on_scan(self): self.config.scan('voteit.core.models.logs') factory = self.config.registry.queryUtility(IFactory, 'LogEntry') self.failUnless(IFactory.providedBy(factory)) obj = factory('uid', 'message') self.failUnless(obj) obj = createObject('LogEntry', 'uid', 'message') self.failUnless(obj)
def test_PlainText(self): from quotationtool.renderer.plaintext import PlainText, plainTextFactory from quotationtool.renderer.interfaces import IPlainText pt = PlainText('Hello World!') self.assertTrue(pt == u'Hello World!') self.assertTrue(IPlainText.providedBy(pt)) pt = plainTextFactory('Hello World!') self.assertTrue(isinstance(pt, PlainText)) self.assertTrue(IPlainText.providedBy(pt)) from zope.component.interfaces import IFactory self.assertTrue(IFactory.providedBy(plainTextFactory)) implemented = plainTextFactory.getInterfaces() from quotationtool.renderer.interfaces import ISource self.assertTrue(implemented.isOrExtends(ISource))
def getFactoryInfoDictionary(reg): """Return a PT-friendly info dictionary for a factory.""" factory = reg.component callable = factory # Usually only zope.component.factory.Factory instances have this attribute if IFactory.providedBy(factory) and hasattr(factory, '_callable'): callable = factory._callable elif hasattr(callable, '__class__'): callable = callable.__class__ path = getPythonPath(callable) return {'name': six.text_type(reg.name) or _('<i>no name</i>'), 'title': getattr(factory, 'title', u''), 'description': renderText(getattr(factory, 'description', u''), module=callable.__module__), 'url': isReferencable(path) and path.replace('.', '/') or None}