def setUp(self): """ Create a L{Store} with a fake L{IOfferingTechnician} powerup which allows fine-grained control of template name resolution. """ self.offeringTech = FakeOfferingTechnician() self.store = Store() self.store.inMemoryPowerUp(self.offeringTech, IOfferingTechnician) self.siteResolver = SiteTemplateResolver(self.store)
def test_headRenderer(self): """ The I{head} renderer gets the head section for each installed theme by calling their C{head} method with the request being rendered and adds the result to the tag it is passed. """ headCalls = [] customHead = object() class CustomHeadTheme(object): priority = 0 themeName = "custom" def head(self, request, site): headCalls.append((request, site)) return customHead def getDocFactory(self, name, default): return default tech = FakeOfferingTechnician() tech.installOffering( Offering( name=u"fake", description=u"", siteRequirements=[], appPowerups=[], installablePowerups=[], loginInterfaces=[], themes=[CustomHeadTheme()], ) ) self.siteStore.inMemoryPowerUp(tech, IOfferingTechnician) # Flush the cache, which is global, else the above fake-out is # completely ignored. theThemeCache.emptyCache() page = self.createPage(self.username) tag = div() ctx = context.WebContext(tag=tag) request = FakeRequest() ctx.remember(request, inevow.IRequest) result = page.render_head(ctx, None) self.assertEqual(result.tagName, "div") self.assertEqual(result.attributes, {}) self.assertIn(customHead, result.children) self.assertEqual(headCalls, [(request, ISiteURLGenerator(self.siteStore))])
def test_headRenderer(self): """ The I{head} renderer gets the head section for each installed theme by calling their C{head} method with the request being rendered and adds the result to the tag it is passed. """ headCalls = [] customHead = object() class CustomHeadTheme(object): priority = 0 themeName = "custom" def head(self, request, site): headCalls.append((request, site)) return customHead def getDocFactory(self, name, default): return default tech = FakeOfferingTechnician() tech.installOffering( Offering(name=u'fake', description=u'', siteRequirements=[], appPowerups=[], installablePowerups=[], loginInterfaces=[], themes=[CustomHeadTheme()])) self.siteStore.inMemoryPowerUp(tech, IOfferingTechnician) # Flush the cache, which is global, else the above fake-out is # completely ignored. theThemeCache.emptyCache() page = self.createPage(self.username) tag = div() ctx = context.WebContext(tag=tag) request = FakeRequest() ctx.remember(request, inevow.IRequest) result = page.render_head(ctx, None) self.assertEqual(result.tagName, 'div') self.assertEqual(result.attributes, {}) self.assertIn(customHead, result.children) self.assertEqual(headCalls, [(request, ISiteURLGenerator(self.siteStore))])
class TestSiteTemplateResolver(TestCase): """ Tests for L{SiteTemplateResolver} """ def setUp(self): """ Create a L{Store} with a fake L{IOfferingTechnician} powerup which allows fine-grained control of template name resolution. """ self.offeringTech = FakeOfferingTechnician() self.store = Store() self.store.inMemoryPowerUp(self.offeringTech, IOfferingTechnician) self.siteResolver = SiteTemplateResolver(self.store) def getDocFactoryWithoutCaching(self, templateName): """ Use C{self.siteResolver} to get a loader for the named template, flushing the template cache first in order to make the result reflect any changes which in offering or theme availability which may have happened since the last call. """ webtheme.theThemeCache.emptyCache() return self.siteResolver.getDocFactory(templateName) def test_getDocFactory(self): """ L{SiteTemplateResolver.getDocFactory} should return only installed themes for its store. """ class FakeTheme(object): priority = 0 def getDocFactory(self, templateName, default=None): if templateName == 'shell': return object() return default self.assertIdentical(self.getDocFactoryWithoutCaching('shell'), None) self.offeringTech.installOffering( Offering( u'an offering', None, [], [], [], [], [FakeTheme()])) self.assertNotIdentical(self.getDocFactoryWithoutCaching('shell'), None)
class TestSiteTemplateResolver(TestCase): """ Tests for L{SiteTemplateResolver} """ def setUp(self): """ Create a L{Store} with a fake L{IOfferingTechnician} powerup which allows fine-grained control of template name resolution. """ self.offeringTech = FakeOfferingTechnician() self.store = Store() self.store.inMemoryPowerUp(self.offeringTech, IOfferingTechnician) self.siteResolver = SiteTemplateResolver(self.store) def getDocFactoryWithoutCaching(self, templateName): """ Use C{self.siteResolver} to get a loader for the named template, flushing the template cache first in order to make the result reflect any changes which in offering or theme availability which may have happened since the last call. """ webtheme.theThemeCache.emptyCache() return self.siteResolver.getDocFactory(templateName) def test_getDocFactory(self): """ L{SiteTemplateResolver.getDocFactory} should return only installed themes for its store. """ class FakeTheme(object): priority = 0 def getDocFactory(self, templateName, default=None): if templateName == 'shell': return object() return default self.assertIdentical(self.getDocFactoryWithoutCaching('shell'), None) self.offeringTech.installOffering( Offering(u'an offering', None, [], [], [], [], [FakeTheme()])) self.assertNotIdentical(self.getDocFactoryWithoutCaching('shell'), None)