Пример #1
0
    def test_authenticatedApplicationNavigation(self):
        """
        The I{applicationNavigation} renderer should add primary navigation
        elements to the tag it is passed if it is called on a
        L{_PublicPageMixin} being rendered for an authenticated user.
        """
        navigable = FakeNavigableElement(store=self.userStore)
        installOn(navigable, self.userStore)
        navigable.tabs = [Tab('foo', 123, 0, [Tab('bar', 432, 0)])]
        request = FakeRequest()

        page = self.createPage(self.username)
        navigationPattern = div[
            span(id='app-tab', pattern='app-tab'),
            span(id='tab-contents', pattern='tab-contents')]
        ctx = context.WebContext(tag=navigationPattern)
        ctx.remember(request)
        tag = page.render_applicationNavigation(ctx, None)
        self.assertEqual(tag.tagName, 'div')
        self.assertEqual(tag.attributes, {})
        children = [child for child in tag.children if child.pattern is None]
        self.assertEqual(children, [])
        self.assertEqual(len(tag.slotData['tabs']), 1)
        fooTab = tag.slotData['tabs'][0]
        self.assertEqual(fooTab.attributes, {'id': 'app-tab'})
        self.assertEqual(fooTab.slotData['name'], 'foo')
        fooContent = fooTab.slotData['tab-contents']
        self.assertEqual(fooContent.attributes, {'id': 'tab-contents'})
        self.assertEqual(fooContent.slotData['href'],
                         self.privateApp.linkTo(123))
Пример #2
0
 def test_classInit_beats_context(self):
     _ = i18n.Translator(translator=mockTranslator, domain='baz')
     ctx = context.WebContext()
     cfg = i18n.I18NConfig(domain='not-used')
     ctx.remember(cfg)
     s = _('foo')
     r = flat.ten.flatten(s, None)
     self.assertEquals(r, "MOCK(domain='baz')[foo]")
Пример #3
0
 def test_context(self):
     _ = i18n.Translator(translator=mockTranslator)
     ctx = context.WebContext()
     cfg = i18n.I18NConfig(domain='thud')
     ctx.remember(cfg)
     s = _('foo')
     r = flat.ten.flatten(s, ctx)
     self.assertEquals(r, "MOCK(domain='thud')[foo]")
Пример #4
0
 def test_unauthenticatedLogout(self):
     """
     The I{logout} renderer should remove the tag it is passed from the
     output if it is called on a L{_PublicPageMixin} being rendered for an
     authenticated user.
     """
     page = self.createPage(None)
     logoutPattern = div()
     ctx = context.WebContext(tag=logoutPattern)
     tag = page.render_logout(ctx, None)
     self.assertEqual(tag, '')
Пример #5
0
 def test_unauthenticatedApplicationNavigation(self):
     """
     The I{applicationNavigation} renderer should remove the tag it is
     passed from the output if it is called on a L{_PublicPageMixin} being
     rendered for an unauthenticated user.
     """
     page = self.createPage(None)
     navigationPattern = div()
     ctx = context.WebContext(tag=navigationPattern)
     tag = page.render_applicationNavigation(ctx, None)
     self.assertEqual(tag, '')
Пример #6
0
 def test_authenticatedLogout(self):
     """
     The I{logout} renderer should return the tag it is passed if it is
     called on a L{_PublicPageMixin} being rendered for an authenticated
     user.
     """
     page = self.createPage(self.username)
     logoutPattern = div()
     ctx = context.WebContext(tag=logoutPattern)
     tag = page.render_logout(ctx, None)
     self.assertIdentical(logoutPattern, tag)
Пример #7
0
 def test_authenticatedAuthenticateLinks(self):
     """
     The I{authenticateLinks} renderer should remove the tag it is passed
     from the output if it is called on a L{_PublicPageMixin} being rendered
     for an authenticated user.
     """
     page = self.createPage(self.username)
     authenticateLinksPattern = div()
     ctx = context.WebContext(tag=authenticateLinksPattern)
     tag = page.render_authenticateLinks(ctx, None)
     self.assertEqual(tag, '')
Пример #8
0
 def test_unauthenticatedStartmenu(self):
     """
     The I{startmenu} renderer should remove the tag it is passed from the
     output if it is called on a L{_PublicPageMixin} being rendered for an
     unauthenticated user.
     """
     page = self.createPage(None)
     startMenuTag = div()
     ctx = context.WebContext(tag=startMenuTag)
     tag = page.render_startmenu(ctx, None)
     self.assertEqual(tag, '')
Пример #9
0
 def test_urchin(self):
     """
     When an Urchin API key is present, the code for enabling Google
     Analytics tracking should be inserted into the shell template.
     """
     keyString = u"UA-99018-11"
     APIKey.setKeyForAPI(self.siteStore, APIKey.URCHIN, keyString)
     page = self.createPage(None)
     t = div()
     result = page.render_urchin(context.WebContext(tag=t), None)
     self.assertEqual(result.slotData['urchin-key'], keyString)
Пример #10
0
 def test_title(self):
     """
     The I{title} renderer should add the wrapped fragment's title
     attribute, if any, or the default "Divmod".
     """
     page = self.createPage(self.username)
     titleTag = title()
     tag = page.render_title(context.WebContext(tag=titleTag), None)
     self.assertIdentical(tag, titleTag)
     flattened = flatten(tag)
     self.assertSubstring(
         flatten(getattr(page.fragment, 'title', 'Divmod')), flattened)
Пример #11
0
 def test_rootChild(self):
     """
     When no default offering has been selected,
     L{PublicFrontPage.locateChild} returns an L{_OfferingsFragment} wrapped by
     the L{IWebViewer}.
     """
     frontPage = FrontPage(store=self.siteStore)
     resource = _PublicFrontPage(frontPage, self.webViewer)
     request = FakeRequest()
     ctx = context.WebContext()
     ctx.remember(request, inevow.IRequest)
     result, segments = resource.locateChild(ctx, ('', ))
     self.assertIsInstance(result, PublicPage)
     self.assertIsInstance(result.fragment, _OfferingsFragment)
Пример #12
0
 def test_rootURL(self):
     """
     The I{base} renderer should add the website's root URL to the tag it is
     passed.
     """
     page = self.createPage(self.username)
     baseTag = div()
     request = FakeRequest(headers={'host': 'example.com'})
     ctx = context.WebContext(tag=baseTag)
     ctx.remember(request, inevow.IRequest)
     tag = page.render_rootURL(ctx, None)
     self.assertIdentical(tag, baseTag)
     self.assertEqual(tag.attributes, {})
     self.assertEqual(tag.children, [self.rootURL(request)])
Пример #13
0
    def _renderAppNav(self, tabs, template=None):
        """
        Render application navigation and return the resulting tag.

        @param template: a Tag containing a template for navigation.
        """
        if template is None:
            template = tags.span[
                tags.div(pattern='app-tab'),
                tags.div(pattern='tab-contents')]
        ctx = context.WebContext(tag=template)
        request = FakeRequest()
        ctx.remember(request)
        return webnav.applicationNavigation(ctx, FakeTranslator(), tabs)
Пример #14
0
    def test_nonExistentChild(self):
        """
        L{_PublicFrontPage.locateChild} returns L{rend.NotFound} for a child
        segment which does not exist.
        """
        store = Store()
        frontPage = FrontPage(store=store)
        resource = _PublicFrontPage(frontPage, IWebViewer(self.siteStore))

        request = FakeRequest()
        ctx = context.WebContext()
        ctx.remember(request, inevow.IRequest)

        result = resource.locateChild(ctx, ('foo', ))
        self.assertIdentical(result, rend.NotFound)
Пример #15
0
 def test_authenticatedSettingsLink(self):
     """
     The I{settingsLink} renderer should add the URL of the settings item to
     the tag it is passed if it is called on a L{_PublicPageMixin} being
     rendered for an authenticated user.
     """
     page = self.createPage(self.username)
     settingsLinkPattern = div()
     ctx = context.WebContext(tag=settingsLinkPattern)
     tag = page.render_settingsLink(ctx, None)
     self.assertEqual(tag.tagName, 'div')
     self.assertEqual(tag.attributes, {})
     self.assertEqual(tag.children, [
         self.privateApp.linkTo(
             self.userStore.findUnique(PreferenceAggregator).storeID)
     ])
Пример #16
0
    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))])
Пример #17
0
    def usernameRenderingTest(self, username, hostHeader, expectedUsername):
        """
        Verify that the username will be rendered appropriately given the host
        of the HTTP request.

        @param username: the user's full login identifier.
        @param hostHeader: the value of the 'host' header.
        @param expectedUsername: the expected value of the rendered username.
        """
        page = self.createPage(username)
        userTag = span()
        req = FakeRequest(headers={'host': hostHeader})
        ctx = context.WebContext(tag=userTag)
        ctx.remember(req, inevow.IRequest)
        tag = page.render_username(ctx, None)
        self.assertEqual(tag.tagName, 'span')
        self.assertEqual(tag.children, [expectedUsername])
Пример #18
0
 def test_unauthenticatedAuthenticateLinks(self):
     """
     The I{authenticateLinks} renderer should add login and signup links to
     the tag it is passed, if it is called on a L{_PublicPageMixin} being
     rendered for an unauthenticated user.
     """
     page = self.createPage(None)
     authenticateLinksPattern = div[span(pattern='signup-link')]
     ctx = context.WebContext(tag=authenticateLinksPattern)
     tag = page.render_authenticateLinks(ctx, None)
     self.assertEqual(tag.tagName, 'div')
     self.assertEqual(tag.attributes, {})
     children = [child for child in tag.children if child.pattern is None]
     self.assertEqual(len(children), 1)
     self.assertEqual(children[0].slotData, {
         'prompt': self.signupPrompt,
         'url': '/' + self.signupURL
     })
Пример #19
0
    def test_authenticatedStartmenu(self):
        """
        The I{startmenu} renderer should add navigation elements to the tag it
        is passed if it is called on a L{_PublicPageMixin} being rendered for an
        authenticated user.
        """
        navigable = FakeNavigableElement(store=self.userStore)
        installOn(navigable, self.userStore)
        navigable.tabs = [Tab('foo', 123, 0, [Tab('bar', 432, 0)])]

        page = self.createPage(self.username)
        startMenuTag = div[h1(pattern='tab'), h2(pattern='subtabs')]

        ctx = context.WebContext(tag=startMenuTag)
        tag = page.render_startmenu(ctx, None)
        self.assertEqual(tag.tagName, 'div')
        self.assertEqual(tag.attributes, {})
        children = [child for child in tag.children if child.pattern is None]
        self.assertEqual(len(children), 0)
        # This structure seems overly complex.
        tabs = list(tag.slotData.pop('tabs'))
        self.assertEqual(len(tabs), 1)
        fooTab = tabs[0]
        self.assertEqual(fooTab.tagName, 'h1')
        self.assertEqual(fooTab.attributes, {})
        self.assertEqual(fooTab.children, [])
        self.assertEqual(fooTab.slotData['href'], self.privateApp.linkTo(123))
        self.assertEqual(fooTab.slotData['name'], 'foo')
        self.assertEqual(fooTab.slotData['kids'].tagName, 'h2')
        subtabs = list(fooTab.slotData['kids'].slotData['kids'])
        self.assertEqual(len(subtabs), 1)
        barTab = subtabs[0]
        self.assertEqual(barTab.tagName, 'h1')
        self.assertEqual(barTab.attributes, {})
        self.assertEqual(barTab.children, [])
        self.assertEqual(barTab.slotData['href'], self.privateApp.linkTo(432))
        self.assertEqual(barTab.slotData['name'], 'bar')
        self.assertEqual(barTab.slotData['kids'], '')
Пример #20
0
 def flattenUrl(self, urlObj, page):
     ctx = context.WebContext(tag=page)
     ctx.remember(testutil.AccumulatingFakeRequest())
     return ''.join(
         [i for i in url.URLOverlaySerializer(urlObj, ctx).next()])
Пример #21
0
 def test_remember(self):
     ctx = context.WebContext()
     cfg = i18n.I18NConfig(domain='foo')
     ctx.remember(cfg)