Esempio n. 1
0
    def test_rssGeneration(self):
        """
        Test that the RSS generator produces the desired output.
        """
        BLOG_TITLE = u'Awesome! A Blog.'
        BLOG_DESC = u'A blog about stuff.'
        POST_TITLE = u'awesome title'
        POST_BODY = u'<div>body</div>'
        blurb = MockBlurb(flavor=hyperblurb.FLAVOR.BLOG,
                          title=BLOG_TITLE, body=BLOG_DESC,
                          author=self.BLOG_AUTHOR,
                          children=[MockBlurb(flavor=hyperblurb.FLAVOR.BLOG_POST,
                                              title=POST_TITLE,
                                              body=POST_BODY,
                                              author=self.BLOG_AUTHOR,
                                              children=[])])
        def checkData(rssData):
            def assertPathEqual(path, data):
                self.assertEqual(evaluateXPath(path, rssData)[0], data)
            assertPathEqual('/rss/channel/title/text()', BLOG_TITLE)
            assertPathEqual('/rss/channel/link/text()', self.BLOG_URL)
            assertPathEqual('/rss/channel/description/text()', BLOG_DESC)

            self.assertEqual(
                len(evaluateXPath('/rss/channel/item', rssData)), 1)
            assertPathEqual('/rss/channel/item[1]/title/text()', POST_TITLE)
            assertPathEqual('/rss/channel/item[1]/description/text()',
                            POST_BODY)
        rssView = hyperbola_view.blurbViewDispatcher(blurb).child_rss(None)
        return renderPage(rssView).addCallback(checkData)
Esempio n. 2
0
    def _getBlurb(self, flavor):
        self._setUpStore()
        share = self._shareAndGetProxy(self._makeBlurb(flavor))

        f = hyperbola_view.blurbViewDispatcher(share)
        f.setFragmentParent(self)
        f.docFactory = getLoader(f.fragmentName)

        return f
Esempio n. 3
0
    def test_htmlBlurbBody(self):
        """
        Test that we can set and retrieve a blurb body containing HTML through
        the view APIs
        """
        share = self._shareAndGetProxy(
            self._makeBlurb(
                hyperblurb.FLAVOR.BLOG))

        parent = hyperbola_view.blurbViewDispatcher(share)
        parent.customizeFor(self.role.externalID)

        commenter = hyperbola_view.addCommentDispatcher(parent)
        commenter.addComment(u'title', u'<div>body</div>', ())

        (post,) = share.view(self.role)
        postFragment = hyperbola_view.blurbViewDispatcher(post)
        result = postFragment.body(None, None)
        self.assertEqual(flatten(result), '<div>body</div><br />')
Esempio n. 4
0
 def test_blurbViewDispatch(self):
     """
     Test that we can pass a blurb of any flavor to
     L{hyperbola.hyperbola_view.blurbViewDispatcher} and then render the
     result
     """
     deferreds = list()
     for flavor in hyperblurb.ALL_FLAVORS:
         proxy = self._shareAndGetProxy(self._makeBlurb(flavor))
         deferreds.append(self._renderFragment(
             hyperbola_view.blurbViewDispatcher(proxy)))
     return defer.gatherResults(deferreds)
Esempio n. 5
0
 def test_blurbViewDispatch(self):
     """
     Test that we can pass a blurb of any flavor to
     L{hyperbola.hyperbola_view.blurbViewDispatcher} and then render the
     result
     """
     deferreds = list()
     for flavor in hyperblurb.ALL_FLAVORS:
         proxy = self._shareAndGetProxy(self._makeBlurb(flavor))
         deferreds.append(
             self._renderFragment(
                 hyperbola_view.blurbViewDispatcher(proxy)))
     return defer.gatherResults(deferreds)
Esempio n. 6
0
    def test_emptyRSS(self):
        """
        Test that RSS generation works properly for blurbs with no children.
        """
        blurb = MockBlurb(flavor=hyperblurb.FLAVOR.BLOG,
                          title=u"blog title", body=u"blog desc",
                          children=[], author=self.BLOG_AUTHOR)

        def checkData(rssData):
            rssDoc = minidom.parseString(rssData)
            self.assertEqual(evaluateXPath('/rss/channel/item', rssData), [])
        rssView = hyperbola_view.blurbViewDispatcher(blurb).child_rss(None)
        return renderPage(rssView).addCallback(checkData)
Esempio n. 7
0
    def test_htmlifyLineBreaks(self):
        """
        Test that L{hyperbola.hyperbola_view.BlurbViewer._htmlifyLineBreaks}
        replaces new lines with <br> elements
        """
        share = self._shareAndGetProxy(
            self._makeBlurb(
                hyperblurb.FLAVOR.BLOG_POST,
                body=u'foo\nbar\r\nbaz'))

        frag = hyperbola_view.blurbViewDispatcher(share)
        self.assertEquals(
            flatten(frag._htmlifyLineBreaks(frag.original.body)),
            'foo<br />bar<br />baz<br />')
Esempio n. 8
0
    def test_emptyRSS(self):
        """
        Test that RSS generation works properly for blurbs with no children.
        """
        blurb = MockBlurb(flavor=hyperblurb.FLAVOR.BLOG,
                          title=u"blog title",
                          body=u"blog desc",
                          children=[],
                          author=self.BLOG_AUTHOR)

        def checkData(rssData):
            rssDoc = minidom.parseString(rssData)
            self.assertEqual(evaluateXPath('/rss/channel/item', rssData), [])

        rssView = hyperbola_view.blurbViewDispatcher(blurb).child_rss(None)
        return renderPage(rssView).addCallback(checkData)
Esempio n. 9
0
    def test_addCommentWithTags(self):
        """
        Same as L{test_addComment}, but specify some tags to be applied to the
        comment
        """
        for flavor in hyperblurb.ALL_FLAVORS:
            share = self._shareAndGetProxy(self._makeBlurb(flavor))

            parent = hyperbola_view.blurbViewDispatcher(share)
            parent.customizeFor(self.role.externalID)

            frag = hyperbola_view.addCommentDispatcher(parent)
            frag.addComment(u'title', u'body!', (u't', u'a', u'gs'))

            (comment,) = share.view(self.role)
            self.assertEquals(set(comment.tags()), set(('t', 'a', 'gs')))
Esempio n. 10
0
    def test_editLinkIfEditable(self):
        """
        Test that L{hyperbola_view.BlogPostBlurbViewer} renders an 'edit' link
        if the underlying blurb is editable.
        """
        post = self._makeBlurb(hyperblurb.FLAVOR.BLOG_POST)

        authorShareID = sharing.shareItem(
            post, toRole=sharing.getSelfRole(self.userStore),
            interfaces=[ihyperbola.IEditable]).shareID
        authorPostShare = sharing.getShare(
            self.userStore, sharing.getSelfRole(self.userStore), authorShareID)

        authorPostView = hyperbola_view.blurbViewDispatcher(authorPostShare)
        tag = tags.invisible(foo='bar')
        result = authorPostView.editLink(None, tag)
        self.assertIdentical(result, tag)
Esempio n. 11
0
 def test_blurbViewColumn(self):
     """
     Verify the L{xmantissa.ixmantissa.IColumn} implementation of
     L{hyperbola_view.BlurbViewColumn}.
     """
     col = hyperbola_view.BlurbViewColumn()
     self.assertEqual(col.attributeID, 'blurbView')
     self.assertEqual(col.getType(), scrolltable.TYPE_WIDGET)
     model = athena.LivePage()
     frag = col.extractValue(model, self.blogPostSharedToEveryone)
     fragClass = hyperbola_view.blurbViewDispatcher(
         self.blogPostSharedToEveryone).__class__
     self.failUnless(isinstance(frag, fragClass))
     self.assertIdentical(frag.fragmentParent, model)
     self.failUnless(frag.docFactory)
     self.assertIdentical(col.sortAttribute(), None)
     self.assertRaises(NotImplementedError, col.toComparableValue, None)
Esempio n. 12
0
    def test_addComment(self):
        """
        Test adding a comment to a blurb of each flavor through
        L{hyperbola.hyperbola_view.addCommentDispatcher}
        """
        for flavor in hyperblurb.ALL_FLAVORS:
            share = self._shareAndGetProxy(self._makeBlurb(flavor))

            parent = hyperbola_view.blurbViewDispatcher(share)
            parent.customizeFor(self.role.externalID)

            frag = hyperbola_view.addCommentDispatcher(parent)
            frag.addComment(u'title', u'body!', ())

            (comment,) = share.view(self.role)
            self.assertEquals(comment.title, 'title')
            self.assertEquals(comment.body, 'body!')
            self.assertEquals(list(comment.tags()), [])
Esempio n. 13
0
    def test_addCommentDialogDispatch(self):
        """
        Test that we can pass a blurb of any flavor to
        L{hyperbola.hyperbola_view.addCommentDialogDispatcher} and then render
        the result
        """
        class RequestWithArgs(AccumulatingFakeRequest):
            def __init__(self, *a, **k):
                AccumulatingFakeRequest.__init__(self, *a, **k)
                self.args = {'title': [''], 'body': [''], 'url': ['']}

        deferreds = list()
        for flavor in hyperblurb.ALL_FLAVORS:
            proxy = self._shareAndGetProxy(self._makeBlurb(flavor))
            deferreds.append(
                self._renderFragment(hyperbola_view.addCommentDialogDispatcher(
                    hyperbola_view.blurbViewDispatcher(proxy)),
                                     reqFactory=RequestWithArgs))
        return defer.gatherResults(deferreds)
Esempio n. 14
0
    def test_addCommentDialogDispatch(self):
        """
        Test that we can pass a blurb of any flavor to
        L{hyperbola.hyperbola_view.addCommentDialogDispatcher} and then render
        the result
        """
        class RequestWithArgs(AccumulatingFakeRequest):
            def __init__(self, *a, **k):
                AccumulatingFakeRequest.__init__(self, *a, **k)
                self.args = {'title': [''], 'body': [''], 'url': ['']}

        deferreds = list()
        for flavor in hyperblurb.ALL_FLAVORS:
            proxy = self._shareAndGetProxy(self._makeBlurb(flavor))
            deferreds.append(self._renderFragment(
                hyperbola_view.addCommentDialogDispatcher(
                    hyperbola_view.blurbViewDispatcher(proxy)),
                reqFactory=RequestWithArgs))
        return defer.gatherResults(deferreds)
Esempio n. 15
0
    def test_blogTags(self):
        """
        Test that the implementation of C{_getAllTags} on the view for a blog
        post returns all tags that have been applied to blurbs, without
        duplicates
        """
        postShare = self._shareAndGetProxy(
            self._makeBlurb(hyperblurb.FLAVOR.BLOG_POST))
        postShare.tag(u'foo')

        otherPostShare = self._shareAndGetProxy(
            self._makeBlurb(hyperblurb.FLAVOR.BLOG_POST))
        otherPostShare.tag(u'foo')
        otherPostShare.tag(u'bar')

        blogShare = self._shareAndGetProxy(
            self._makeBlurb(hyperblurb.FLAVOR.BLOG))
        blogView = hyperbola_view.blurbViewDispatcher(blogShare)

        self.assertEquals(
            list(sorted(blogView._getAllTags())),
            [u'bar', u'foo'])
Esempio n. 16
0
    def test_rssGeneration(self):
        """
        Test that the RSS generator produces the desired output.
        """
        BLOG_TITLE = u'Awesome! A Blog.'
        BLOG_DESC = u'A blog about stuff.'
        POST_TITLE = u'awesome title'
        POST_BODY = u'<div>body</div>'
        blurb = MockBlurb(flavor=hyperblurb.FLAVOR.BLOG,
                          title=BLOG_TITLE,
                          body=BLOG_DESC,
                          author=self.BLOG_AUTHOR,
                          children=[
                              MockBlurb(flavor=hyperblurb.FLAVOR.BLOG_POST,
                                        title=POST_TITLE,
                                        body=POST_BODY,
                                        author=self.BLOG_AUTHOR,
                                        children=[])
                          ])

        def checkData(rssData):
            def assertPathEqual(path, data):
                self.assertEqual(evaluateXPath(path, rssData)[0], data)

            assertPathEqual('/rss/channel/title/text()', BLOG_TITLE)
            assertPathEqual('/rss/channel/link/text()', self.BLOG_URL)
            assertPathEqual('/rss/channel/description/text()', BLOG_DESC)

            self.assertEqual(len(evaluateXPath('/rss/channel/item', rssData)),
                             1)
            assertPathEqual('/rss/channel/item[1]/title/text()', POST_TITLE)
            assertPathEqual('/rss/channel/item[1]/description/text()',
                            POST_BODY)

        rssView = hyperbola_view.blurbViewDispatcher(blurb).child_rss(None)
        return renderPage(rssView).addCallback(checkData)