def makeLivePage(self): """ Create a MantissaLivePage instance for testing. """ siteStore = Store(filesdir=self.mktemp()) Mantissa().installSite(siteStore, self.hostname.decode('ascii'), u"", False) return MantissaLivePage(ISiteURLGenerator(siteStore))
def _renderPage(): page = MantissaLivePage(FakeWebSite()) element = LiveElement( stan(tags.span(render=tags.directive('liveElement')))) element.setFragmentParent(page) element.jsClass = u'Mantissa.Test.Dummy.DummyWidget' page.docFactory = stan( [tags.span(render=tags.directive('liveglue')), element]) ctx = WovenContext() req = FakeRequest(headers={'host': self.hostname}) ctx.remember(req, IRequest) page.beforeRender(ctx) page.renderHTTP(ctx) page._messageDeliverer.close()
def test_getJSModuleURL(self): """ L{MantissaLivePage.getJSModuleURL} should return a child of its C{_moduleRoot} attribute of the form:: _moduleRoot/<SHA1 digest of module contents>/Package.ModuleName """ module = 'Mantissa' url = URL(scheme='https', netloc='example.com', pathsegs=['foo']) page = MantissaLivePage(None) page._moduleRoot = url jsDir = FilePath(__file__).parent().parent().child("js") modulePath = jsDir.child(module).child("__init__.js") moduleContents = modulePath.open().read() expect = sha.new(moduleContents).hexdigest() self.assertEqual(page.getJSModuleURL(module), url.child(expect).child(module))
def test_beforeRenderSetsModuleRoot(self): """ L{MantissaLivePage.beforeRender} should set I{_moduleRoot} to the C{__jsmodule__} child of the URL returned by the I{rootURL} method of the L{WebSite} it wraps. """ receivedRequests = [] root = URL(netloc='example.com', pathsegs=['a', 'b']) class FakeWebSite(object): def rootURL(self, request): receivedRequests.append(request) return root request = FakeRequest() page = MantissaLivePage(FakeWebSite()) page.beforeRender(request) self.assertEqual(receivedRequests, [request]) self.assertEqual(page._moduleRoot, root.child('__jsmodule__'))