Central Components ****************** .. :doctest: .. :layer: waeup.ikoba.testing.IkobaUnitTestLayer .. module:: waeup.ikoba.app Creating `Company` instances ============================ As :class:`Company` instances make use of the Zope Component Architecture (ZCA), we have to setup the basic component registries, before we can create instances. We do this by simply grokking the whole :mod:`waeup` package. This way all interfaces, utilities and adapters defined in the package are looked up and registered with the global registries (this is done by the testlayer automatically). Now we can import the :class:`Company` class and create an instance: >>> from waeup.ikoba.app import Company >>> mycompany = Company() >>> mycompany Instances of `Company` comply with the interface `waeup.ikoba.interfaces.ICompany`: >>> from zope.interface.verify import verifyClass >>> from waeup.ikoba.interfaces import ICompany >>> verifyClass(ICompany, Company) True A freshly created instance provides the attributes promised by the interface: >>> from waeup.ikoba.app import Company >>> mycompany = Company() >>> mycompany['configuration'].name u'Sample Company' >>> mycompany['users'] >>> mycompany['datacenter'] >>> mycompany['configuration'] Ikoba plugins ============= waeup.ikoba provides an API to 'plugin' components. Things that should be setup at creation time of a Ikoba application can indicate that by providing a utility providing IIkobaPlugin. The plugins are looked up by an created app, which then will call the ``setup()`` method of each plugin. >>> from waeup.ikoba.interfaces import IIkobaPluggable >>> from zope.component import getAdapters, getUtilitiesFor >>> sorted(list(getUtilitiesFor(IIkobaPluggable))) [(u'documents', >> import grok >>> from waeup.ikoba.interfaces import IIkobaPluggable >>> class MyPlugin(grok.GlobalUtility): ... grok.implements(IIkobaPluggable) ... def setup(self, site, name, logger): ... print "Setup was called for" ... print site ... def update(self, site, name, logger): ... pass When we register the plugin >>> grok.testing.grok_component('MyPlugin', MyPlugin) True and setup a new Ikoba instance, we will get a message: >>> from waeup.ikoba.app import Company >>> site = Company() Setup was called for Apparently the plugin can do with the Company object whatever it likes. That's what plugins are for.