def test_create_bundle(self): from naaya.core.fsbundles import get_filesystem_bundle_factory factory = get_filesystem_bundle_factory(self.site) bundle = factory() self.assertEqual(bundle.__name__, 'FooSites-bar') self.assertEqual(os.listdir(self.tmp), ['FooSites-bar.bundle']) self.assertEqual(self.site.get_bundle(), bundle)
def can_write_to_bundle(self): """ Check if we can find (or create) any bundle to write templates. """ site = self.getSite() if fsbundles.get_writable_bundle(site) is not None: return True elif fsbundles.get_filesystem_bundle_factory(site) is not None: return True else: return False
def test_bundle_cfg(self): from naaya.core.fsbundles import get_filesystem_bundle_factory factory = get_filesystem_bundle_factory(self.site) bundle = factory() cfg_path = os.path.join(self.tmp, 'FooSites-bar.bundle', 'bundle.cfg') f = open(cfg_path, 'rb') data = list(f) f.close() self.assertTrue('parent-bundle = Foo\n') in data
def move_to_bundle(self, REQUEST=None): """ Move templates to a writable bundle. """ site = self.getSite() user = site.getAuthenticationTool().get_current_userid() bundle = fsbundles.get_writable_bundle(site) if bundle is None: factory = fsbundles.get_filesystem_bundle_factory(site) assert factory is not None, "No writable bundle found!" bundle = factory() if REQUEST is not None: msg = ("IMPORTANT: new bundle %r created. If multiple Zope " "instances are sharing the same ZEO database, make " "sure they all load the new bundle." % bundle) self.setSessionInfo([msg]) bundle_name = bundle.__name__ gsm = getGlobalSiteManager() writer = gsm.queryUtility(IFilesystemTemplateWriter, name=bundle_name) template_names = [] for template in self.objectValues(): content = get_template_source(template) name = template.getId() writer.write_zpt(name, content) self._delObject(template.getId()) log.info("Template %r moved to bundle %r by %r", name, bundle_name, user) template_names.append(name) # TODO reload the bundle in all zope instances # TODO in case of failure, print what has been written to disk if REQUEST is not None: self.setSessionInfo([ "Moved templates bundle %r: %r" % (bundle_name, template_names) ]) return REQUEST.RESPONSE.redirect('%s/manage_overview' % self.absolute_url())
def move_to_bundle(self, REQUEST=None): """ Move templates to a writable bundle. """ site = self.getSite() user = site.getAuthenticationTool().get_current_userid() bundle = fsbundles.get_writable_bundle(site) if bundle is None: factory = fsbundles.get_filesystem_bundle_factory(site) assert factory is not None, "No writable bundle found!" bundle = factory() if REQUEST is not None: msg = ("IMPORTANT: new bundle %r created. If multiple Zope " "instances are sharing the same ZEO database, make " "sure they all load the new bundle." % bundle) self.setSessionInfo([msg]) bundle_name = bundle.__name__ gsm = getGlobalSiteManager() writer = gsm.queryUtility(IFilesystemTemplateWriter, name=bundle_name) template_names = [] for template in self.objectValues(): content = get_template_source(template) name = template.getId() writer.write_zpt(name, content) self._delObject(template.getId()) log.info("Template %r moved to bundle %r by %r", name, bundle_name, user) template_names.append(name) # TODO reload the bundle in all zope instances # TODO in case of failure, print what has been written to disk if REQUEST is not None: self.setSessionInfo(["Moved templates bundle %r: %r" % (bundle_name, template_names)]) return REQUEST.RESPONSE.redirect('%s/manage_overview' % self.absolute_url())
def test_wrong_site_bundle(self): from naaya.core.fsbundles import get_filesystem_bundle_factory self.site.set_bundle(bundles.get('Baz')) factory = get_filesystem_bundle_factory(self.site) self.assertTrue(factory is None)
def test_create_preexisting_bundle(self): from naaya.core.fsbundles import get_filesystem_bundle_factory factory = get_filesystem_bundle_factory(self.site) bundle = factory() self.assertRaises(ValueError, factory)