Ejemplo n.º 1
0
    def test_setTabURLs(self):
        """
        Check that L{webnav.setTabURLs} correctly sets the C{linkURL}
        attribute of L{webnav.Tab} instances to the result of
        passing tab.storeID to L{xmantissa.ixmantissa.IWebTranslator.linkTo}
        if C{linkURL} is not set, and that it leaves it alone if it is
        """

        s = Store()

        privapp = PrivateApplication(store=s)
        installOn(privapp,s)

        tabs = [webnav.Tab('PrivateApplication', privapp.storeID, 0),
                webnav.Tab('Something Else', None, 0, linkURL='/foo/bar')]

        webnav.setTabURLs(tabs, privapp)

        self.assertEqual(tabs[0].linkURL, privapp.linkTo(privapp.storeID))
        self.assertEqual(tabs[1].linkURL, '/foo/bar')
Ejemplo n.º 2
0
    def test_setTabURLs(self):
        """
        Check that L{webnav.setTabURLs} correctly sets the C{linkURL}
        attribute of L{webnav.Tab} instances to the result of
        passing tab.storeID to L{xmantissa.ixmantissa.IWebTranslator.linkTo}
        if C{linkURL} is not set, and that it leaves it alone if it is
        """

        s = Store()

        privapp = PrivateApplication(store=s)
        installOn(privapp, s)

        tabs = [
            webnav.Tab("PrivateApplication", privapp.storeID, 0),
            webnav.Tab("Something Else", None, 0, linkURL="/foo/bar"),
        ]

        webnav.setTabURLs(tabs, privapp)

        self.assertEqual(tabs[0].linkURL, privapp.linkTo(privapp.storeID))
        self.assertEqual(tabs[1].linkURL, "/foo/bar")
Ejemplo n.º 3
0
class PrivateApplicationTestCase(TestCase):
    """
    Tests for L{PrivateApplication}.
    """
    def setUp(self):
        self.siteStore = Store(filesdir=self.mktemp())
        Mantissa().installSite(self.siteStore, u"example.com", u"", False)

        self.userAccount = Create().addAccount(
            self.siteStore, u'testuser', u'example.com', u'password')
        self.userStore = self.userAccount.avatars.open()

        self.privapp = PrivateApplication(store=self.userStore)
        installOn(self.privapp, self.userStore)
        self.webViewer = IWebViewer(self.userStore)


    def test_createResourceUsername(self):
        """
        L{PrivateApplication.createResourceWith} should figure out the
        right username and pass it to L{_PrivateRootPage}.
        """
        rootPage = self.privapp.createResourceWith(self.webViewer)
        self.assertEqual(rootPage.username, u'*****@*****.**')


    def test_getDocFactory(self):
        """
        L{PrivateApplication.getDocFactory} finds a document factory for
        the specified template name from among the installed themes.
        """
        # Get something from the Mantissa theme
        self.assertNotIdentical(self.privapp.getDocFactory('shell'), None)

        # Get rid of the Mantissa offering and make sure the template is no
        # longer found.
        self.siteStore.query(InstalledOffering).deleteFromStore()

        # And flush the cache. :/ -exarkun
        theThemeCache.emptyCache()

        self.assertIdentical(self.privapp.getDocFactory('shell'), None)


    def test_powersUpWebViewer(self):
        """
        L{PrivateApplication} should provide an indirected L{IWebViewer}
        powerup, and its indirected powerup should be the default provider of
        that interface.
        """
        webViewer = IWebViewer(self.privapp.store)
        self.assertIsInstance(webViewer, _AuthenticatedWebViewer)
        self.assertIdentical(webViewer._privateApplication, self.privapp)


    def test_producePrivateRoot(self):
        """
        L{PrivateApplication.produceResource} should return a
        L{_PrivateRootPage} when asked for '/private'.
        """
        rsrc, segments = self.privapp.produceResource(FakeRequest(),
                                                     tuple(['private']), None)
        self.assertIsInstance(rsrc, _PrivateRootPage)
        self.assertEqual(segments, ())


    def test_produceRedirect(self):
        """
        L{_PrivateRootPage.produceResource} should return a redirect to
        '/private/<default-private-id>' when asked for '/'.

        This is a bad way to do it, because it isn't optional; all logged-in
        users are instantly redirected to their private page, even if the
        application has something interesting to display. See ticket #2708 for
        details.
        """
        item = FakeModelItem(store=self.userStore)
        class TabThingy(object):
            implements(INavigableElement)
            def getTabs(self):
                return [Tab("supertab", item.storeID, 1.0)]
        tt = TabThingy()
        self.userStore.inMemoryPowerUp(tt, INavigableElement)
        rsrc, segments = self.privapp.produceResource(
            FakeRequest(), tuple(['']), None)
        self.assertIsInstance(rsrc, _PrivateRootPage)
        self.assertEqual(segments, tuple(['']))
        url, newSegs = rsrc.locateChild(FakeRequest(), ('',))
        self.assertEqual(newSegs, ())
        req = FakeRequest()
        target = self.privapp.linkTo(item.storeID)
        self.assertEqual('/'+url.path, target)


    def test_produceNothing(self):
        """
        L{_PrivateRootPage.produceResource} should return None when asked for a
        resources other than '/' and '/private'.
        """
        self.assertIdentical(
            self.privapp.produceResource(FakeRequest(),
                                        tuple(['hello', 'world']),
                                        None),
            None)


    def test_privateRootHasWebViewer(self):
        """
        The L{_PrivateRootPage} returned from
        L{PrivateApplication.produceResource} should refer to an
        L{IWebViewer}.
        """
        webViewer = object()
        rsrc, segments = self.privapp.produceResource(
            FakeRequest(),
            tuple(['private']), webViewer)
        self.assertIdentical(webViewer,
                             rsrc.webViewer)