Example #1
0
 def test_differentUserSameID(self):
     """
     Verify that if different facets of the same item are shared to different
     users with the same shareID, each user will receive the correct
     respective facet with only the correct methods exposed.
     """
     t = PrivateThing(store=self.store, publicData=789)
     toBob = sharing.shareItem(t, toName=u'*****@*****.**',
                               interfaces=[IReadOnly])
     toAlice = sharing.shareItem(t, toName=u'*****@*****.**',
                                 shareID=toBob.shareID,
                                 interfaces=[IPrivateThing])
     # Sanity check.
     self.assertEquals(toBob.shareID, toAlice.shareID)
     asBob = sharing.getShare(self.store,
                              sharing.getPrimaryRole(
             self.store, u'*****@*****.**'),
                              toBob.shareID)
     asAlice = sharing.getShare(self.store,
                              sharing.getPrimaryRole(
             self.store, u'*****@*****.**'),
                              toBob.shareID)
     self.assertEquals(asBob.retrieveSomeState(), 789)
     self.assertRaises(AttributeError, lambda : asBob.mutateSomeState)
     self.assertRaises(AttributeError, lambda : asAlice.retrieveSomeState)
     asAlice.mutateSomeState()
     # Make sure they're both seeing the same item.
     self.assertEquals(asBob.retrieveSomeState(), 789+5)
Example #2
0
 def test_shareToAuthorOnly(self):
     """
     Test that creating a blurb with a single entry for the author in the
     C{roleToPerms} dictionary results in a share that can't be accessed by
     anybody else
     """
     shareID = self.blog.post(u'', u'', self.me,
                              {self.me: [ihyperbola.IViewable]})
     self.failUnless(getShare(self.userStore, self.me, shareID))
     self.assertRaises(NoSuchShare,
                       lambda: getShare(self.userStore, self.you, shareID))
Example #3
0
 def test_shareToAuthorOnly(self):
     """
     Test that creating a blurb with a single entry for the author in the
     C{roleToPerms} dictionary results in a share that can't be accessed by
     anybody else
     """
     shareID = self.blog.post(
         u'', u'', self.me, {self.me: [ihyperbola.IViewable]})
     self.failUnless(getShare(self.userStore, self.me, shareID))
     self.assertRaises(
         NoSuchShare,
         lambda: getShare(self.userStore, self.you, shareID))
Example #4
0
 def test_editPermsAuthorOnly(self):
     """
     Test that creating a blurb with the default permissions and then
     editing the perms to only allow the author to view the post results in
     a share that can't be accessed by anybody else
     """
     shareID = self.blog.post(u'', u'', self.me)
     share = getShare(self.userStore, self.me, shareID)
     shareID = itemFromProxy(share).editPermissions(
         {self.me: [ihyperbola.IViewable]})
     share = getShare(self.userStore, self.me, shareID)
     self.assertRaises(NoSuchShare,
                       lambda: getShare(self.userStore, self.you, shareID))
Example #5
0
 def test_editPermsAuthorOnly(self):
     """
     Test that creating a blurb with the default permissions and then
     editing the perms to only allow the author to view the post results in
     a share that can't be accessed by anybody else
     """
     shareID = self.blog.post(u'', u'', self.me)
     share = getShare(self.userStore, self.me, shareID)
     shareID = itemFromProxy(share).editPermissions(
         {self.me: [ihyperbola.IViewable]})
     share = getShare(self.userStore, self.me, shareID)
     self.assertRaises(
         NoSuchShare,
         lambda: getShare(self.userStore, self.you, shareID))
Example #6
0
    def test_listingNestedChildren(self):
        """
        Verify that if a post is made on a blog and comments are made on it,
        they will be returned by listing the children of that blog.
        """
        shareID1 = self.blog.post(u'My First Post', u'Hello, Viewers', self.me)
        post = getShare(self.userStore, self.you, shareID1)
        shareID2 = post.post(u'a comment', u'O RLY?', self.you)
        post2 = getShare(self.userStore, self.me, shareID2)
        shareID3 = post2.post(u'another comment', u'YA RLY!', self.me)

        posts = list(post.view(self.you))
        self.assertEquals(len(posts), 1)
        self.assertEquals(posts[0].shareID, shareID2)
Example #7
0
    def test_listingNestedChildren(self):
        """
        Verify that if a post is made on a blog and comments are made on it,
        they will be returned by listing the children of that blog.
        """
        shareID1 = self.blog.post(
            u'My First Post', u'Hello, Viewers', self.me)
        post = getShare(self.userStore, self.you, shareID1)
        shareID2 = post.post(u'a comment', u'O RLY?', self.you)
        post2 = getShare(self.userStore, self.me, shareID2)
        shareID3 = post2.post(u'another comment', u'YA RLY!', self.me)

        posts = list(post.view(self.you))
        self.assertEquals(len(posts), 1)
        self.assertEquals(posts[0].shareID, shareID2)
Example #8
0
 def test_tagsNoTags(self):
     """
     Test that L{hyperbola.hyperblurb.Blurb.tags} returns an empty iterable
     when there are no tags
     """
     shareID = self.blog.post(u'', u'', self.me)
     post = getShare(self.userStore, self.me, shareID)
     self.assertEquals(list(post.tags()), [])
Example #9
0
 def test_linkToProxy(self):
     """
     Test that L{xmantissa.websharing.linkTo} generates a URL that I can
     link to.
     """
     self._verifyPath(
         websharing.linkTo(sharing.getShare(self.s, sharing.getEveryoneRole(
                     self.s), u'loginsystem')))
Example #10
0
 def test_tagsNoTags(self):
     """
     Test that L{hyperbola.hyperblurb.Blurb.tags} returns an empty iterable
     when there are no tags
     """
     shareID = self.blog.post(u'', u'', self.me)
     post = getShare(self.userStore, self.me, shareID)
     self.assertEquals(list(post.tags()), [])
Example #11
0
 def test_tagging(self):
     """
     Test that blurb tagging works
     """
     shareID = self.blog.post(u'', u'', self.me)
     post = getShare(self.userStore, self.me, shareID)
     post.tag(u'foo')
     post.tag(u'bar')
     self.assertEquals(list(post.tags()), ['foo', 'bar'])
Example #12
0
 def test_tagging(self):
     """
     Test that blurb tagging works
     """
     shareID = self.blog.post(u'', u'', self.me)
     post = getShare(self.userStore, self.me, shareID)
     post.tag(u'foo')
     post.tag(u'bar')
     self.assertEquals(list(post.tags()), ['foo', 'bar'])
Example #13
0
 def test_linkToProxy(self):
     """
     Test that L{xmantissa.websharing.linkTo} generates a URL that I can
     link to.
     """
     self._verifyPath(
         websharing.linkTo(
             sharing.getShare(self.s, sharing.getEveryoneRole(self.s),
                              u'loginsystem')))
Example #14
0
    def test_viewByTag(self):
        """
        Test that L{hyperbola.hyperblurb.Blurb.viewByTag} only returns
        children with the given tag
        """
        post1 = getShare(self.userStore, self.me,
                         self.blog.post(u'', u'', self.me))
        post2 = getShare(self.userStore, self.me,
                         self.blog.post(u'', u'', self.me))
        post3 = getShare(self.userStore, self.me,
                         self.blog.post(u'', u'', self.me))

        post1.tag(u'foo')
        post1.tag(u'bar')

        post2.tag(u'bar')

        self.assertEquals(
            [p.shareID for p in self.blog.viewByTag(self.me, u'bar')],
            [post2.shareID, post1.shareID])
Example #15
0
    def test_viewByTag(self):
        """
        Test that L{hyperbola.hyperblurb.Blurb.viewByTag} only returns
        children with the given tag
        """
        post1 = getShare(
            self.userStore, self.me, self.blog.post(u'', u'', self.me))
        post2 = getShare(
            self.userStore, self.me, self.blog.post(u'', u'', self.me))
        post3 = getShare(
            self.userStore, self.me, self.blog.post(u'', u'', self.me))

        post1.tag(u'foo')
        post1.tag(u'bar')

        post2.tag(u'bar')

        self.assertEquals(
            [p.shareID for p in self.blog.viewByTag(self.me, u'bar')],
            [post2.shareID, post1.shareID])
Example #16
0
 def test_editTags(self):
     """
     Test that L{hyperbola.hyperblurb.Blurb.edit} changes the tags of the
     blurb
     """
     postShareID = self.blog.post(u'', u'', self.me)
     sharedPost = getShare(self.userStore, self.me, postShareID)
     sharedPost.tag(u'foo')
     sharedPost.tag(u'bar')
     self.assertEquals(set(sharedPost.tags()), set(('foo', 'bar')))
     sharedPost.edit(u'', u'', self.me, (u'foo', u'baz'))
     self.assertEquals(set(sharedPost.tags()), set(('foo', 'baz')))
Example #17
0
 def test_editTags(self):
     """
     Test that L{hyperbola.hyperblurb.Blurb.edit} changes the tags of the
     blurb
     """
     postShareID = self.blog.post(u'', u'', self.me)
     sharedPost = getShare(self.userStore, self.me, postShareID)
     sharedPost.tag(u'foo')
     sharedPost.tag(u'bar')
     self.assertEquals(set(sharedPost.tags()), set(('foo', 'bar')))
     sharedPost.edit(u'', u'', self.me, (u'foo', u'baz'))
     self.assertEquals(set(sharedPost.tags()), set(('foo', 'baz')))
Example #18
0
 def test_defaultShareIDInteractionNoMatch(self):
     """
     Verify that L{websharing.linkTo} explicitly includes a share ID in the
     URL if the ID of the share it is passed doesn't match the default.
     """
     websharing.addDefaultShareID(self.s, u'share-id', 0)
     shareable = Shareable(store=self.s)
     sharing.shareItem(Shareable(store=self.s), shareID=u'not-the-share-id')
     share = sharing.getShare(self.s, sharing.getEveryoneRole(self.s),
                              u'not-the-share-id')
     url = websharing.linkTo(share)
     self.assertEqual(str(url), '/users/right/not-the-share-id')
Example #19
0
 def test_postPermissions(self):
     """
     Verify that a post made on the blog by its owner cannot be commented on by
     people who are not authorized to comment on it.
     """
     postShareID = self.blog.post(u'My First Post', u'Hello, Viewers', self.me)
     self.assertNotIdentical(postShareID, None)
     sharedPost = getShare(self.userStore, self.you, postShareID)
     commentShareID = sharedPost.post(u'My Comemnt To Your Post',
                                      u'Your Bolg Sucks, man', self.you)
     self.assertNotIdentical(commentShareID, None)
     sharedComment = getShare(self.userStore, self.you, commentShareID)
     self.assertIdentical(sharedComment.parent, itemFromProxy(sharedPost))
     self.assertRaises(AttributeError,
                       lambda: sharedPost.edit(
             u'Ima Haxer', u'Haxed u', self.you, ()))
     newTitle = u'My Comment To Your Post'
     newBody = u'Your Blog Sucks, man'
     sharedComment.edit(newTitle, newBody, self.you, ())
     self.assertEquals(sharedComment.body, newBody)
     self.assertEquals(sharedComment.title, newTitle)
Example #20
0
 def test_defaultShareIDInteractionNoMatch(self):
     """
     Verify that L{websharing.linkTo} explicitly includes a share ID in the
     URL if the ID of the share it is passed doesn't match the default.
     """
     websharing.addDefaultShareID(self.s, u'share-id', 0)
     shareable = Shareable(store=self.s)
     sharing.shareItem(Shareable(store=self.s), shareID=u'not-the-share-id')
     share = sharing.getShare(
         self.s, sharing.getEveryoneRole(self.s), u'not-the-share-id')
     url = websharing.linkTo(share)
     self.assertEqual(str(url), '/users/right/not-the-share-id')
Example #21
0
 def test_postPermissions(self):
     """
     Verify that a post made on the blog by its owner cannot be commented on by
     people who are not authorized to comment on it.
     """
     postShareID = self.blog.post(u'My First Post', u'Hello, Viewers',
                                  self.me)
     self.assertNotIdentical(postShareID, None)
     sharedPost = getShare(self.userStore, self.you, postShareID)
     commentShareID = sharedPost.post(u'My Comemnt To Your Post',
                                      u'Your Bolg Sucks, man', self.you)
     self.assertNotIdentical(commentShareID, None)
     sharedComment = getShare(self.userStore, self.you, commentShareID)
     self.assertIdentical(sharedComment.parent, itemFromProxy(sharedPost))
     self.assertRaises(
         AttributeError,
         lambda: sharedPost.edit(u'Ima Haxer', u'Haxed u', self.you, ()))
     newTitle = u'My Comment To Your Post'
     newBody = u'Your Blog Sucks, man'
     sharedComment.edit(newTitle, newBody, self.you, ())
     self.assertEquals(sharedComment.body, newBody)
     self.assertEquals(sharedComment.title, newTitle)
Example #22
0
    def _shareAndGetProxy(self, blurb):
        """
        Share C{blurb} to everyone and return a shared proxy

        @param blurb: a blurb
        @type blurb: L{hyperbola.hyperblurb.Blurb}

        @rtype: L{xmantissa.sharing.SharedProxy}
        """
        share = sharing.shareItem(blurb)
        return sharing.getShare(self.userStore,
                                sharing.getEveryoneRole(self.userStore),
                                share.shareID)
Example #23
0
 def test_defaultShareIDInteractionMatching(self):
     """
     Verify that L{websharing.linkTo} does not explicitly include a share
     ID in the URL if the ID of the share it is passed matches the default.
     """
     websharing.addDefaultShareID(self.s, u'share-id', 0)
     sharing.shareItem(Shareable(store=self.s), shareID=u'share-id')
     share = sharing.getShare(
         self.s, sharing.getEveryoneRole(self.s), u'share-id')
     url = websharing.linkTo(share)
     self.assertEqual(str(url), '/users/right/')
     # and if we call child()
     self.assertEqual(str(url.child('child')), '/users/right/share-id/child')
Example #24
0
 def test_getShareProxyWithAdapter(self):
     """
     When you share an item with an interface that has an adapter for that
     interface, the object that results from getShare should provide the
     interface by exposing the adapter rather than the original item.
     """
     privateThing = PrivateThing(store=self.store)
     shared = sharing.shareItem(privateThing, toName=u'testshare',
                                interfaces=[IExternal])
     proxy = sharing.getShare(self.store,
                              sharing.getPrimaryRole(self.store, u'testshare'),
                              shared.shareID)
     proxy.doExternal()
     self.assertTrue(privateThing.externalized)
Example #25
0
    def setUp(self):
        """
        Set up an environment suitable for testing the share-handling
        functionality of L{hyperbola_view.ShareScrollingElement}.
        """
        self._setUpStore()

        blogShare = self._shareAndGetProxy(self._makeBlurb(FLAVOR.BLOG))
        EVERYBODY = sharing.getEveryoneRole(self.userStore)
        sharing.itemFromProxy(blogShare).permitChildren(
            EVERYBODY, FLAVOR.BLOG_POST, ihyperbola.IViewable)

        # For sanity's sake, let's not have the role of the view and the role
        # implicitly chosen by not calling 'customizeFor' disagree.  (This
        # shouldn't be possible anyway, and in the future getRole should just
        # be looking at its proxy.)
        self.publicBlogShare = sharing.getShare(
            self.userStore, EVERYBODY, blogShare.shareID)
        selfRole = sharing.getSelfRole(self.userStore)
        blogPostShareID = blogShare.post(u'', u'', selfRole)
        self.blogPostSharedToEveryone = sharing.getShare(
            self.userStore, EVERYBODY, blogPostShareID)
        self.blogPostItem = sharing.itemFromProxy(self.blogPostSharedToEveryone)
Example #26
0
    def _shareAndGetProxy(self, blurb):
        """
        Share C{blurb} to everyone and return a shared proxy

        @param blurb: a blurb
        @type blurb: L{hyperbola.hyperblurb.Blurb}

        @rtype: L{xmantissa.sharing.SharedProxy}
        """
        share = sharing.shareItem(blurb)
        return sharing.getShare(
            self.userStore,
            sharing.getEveryoneRole(self.userStore),
            share.shareID)
Example #27
0
 def test_defaultShareIDInteractionMatching(self):
     """
     Verify that L{websharing.linkTo} does not explicitly include a share
     ID in the URL if the ID of the share it is passed matches the default.
     """
     websharing.addDefaultShareID(self.s, u'share-id', 0)
     sharing.shareItem(Shareable(store=self.s), shareID=u'share-id')
     share = sharing.getShare(self.s, sharing.getEveryoneRole(self.s),
                              u'share-id')
     url = websharing.linkTo(share)
     self.assertEqual(str(url), '/users/right/')
     # and if we call child()
     self.assertEqual(str(url.child('child')),
                      '/users/right/share-id/child')
Example #28
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)
Example #29
0
    def test_shareAndAdapt(self):
        """
        Verify that when an item is shared to a particular user with a particular
        interface, retrieving it for that user results in methods on the given
        interface being callable and other methods being restricted.
        """
        t = PrivateThing(store=self.store, publicData=789)

        # Sanity check.
        self.failUnless(IPublicThing(t).isMethodAvailable())

        shared = sharing.shareItem(t, toName=u'testshare', interfaces=[IReadOnly])
        proxy = sharing.getShare(self.store,
                                 sharing.getPrimaryRole(self.store, u'testshare'),
                                 shared.shareID)
        self.assertFalse(IPublicThing(proxy).isMethodAvailable())
        self.assertRaises(AttributeError, IPublicThing(proxy).callMethod)
Example #30
0
 def test_twoInterfacesTwoGroups(self):
     """
     Verify that when an item is shared to two roles that a user is a member of,
     they will have access to both interfaces when it is retrieved with
     getShare.
     """
     self.addSomeThings()
     us = sharing.getPrimaryRole(self.store, u'us', True)
     them = sharing.getPrimaryRole(self.store, u'them', True)
     self.bob.becomeMemberOf(us)
     self.bob.becomeMemberOf(them)
     it = PrivateThing(store=self.store, publicData=1234)
     sharing.shareItem(it, toRole=us, shareID=u'q', interfaces=[IPrivateThing])
     sharing.shareItem(it, toRole=them, shareID=u'q', interfaces=[IReadOnly])
     that = sharing.getShare(self.store, self.bob, u'q')
     self.assertEquals(that.retrieveSomeState(), 1234)
     that.mutateSomeState()
     self.assertEquals(that.retrieveSomeState(), 1239)
Example #31
0
    def test_coalesceInheritedAdapters(self):
        """
        If multiple interfaces that are part of the same inheritance hierarchy are
        specified, only the leaf interfaces should be adapted to, and provided
        for all interfaces it inherits from.
        """

        extraPrivateThing = ExtraPrivateThing(store=self.store)
        role = sharing.getPrimaryRole(self.store, u'testshare')
        extraProxy = sharing.getShare(
            self.store, role, sharing.shareItem(
                extraPrivateThing,
                toRole=role, interfaces=[IExternal,
                                      IExtraExternal]).shareID)

        externalTag, externalObj = extraProxy.doExternal()
        extraExternalTag, extraExternalObj = extraProxy.doExternalExtra()
        self.assertIdentical(externalObj, extraExternalObj)
        self.assertEquals(externalTag, 'external')
        self.assertEquals(extraExternalTag, 'external-extra')
Example #32
0
    def addComment(self, title, body, tags):
        """
        Add a comment blurb to our parent blurb

        @param title: the title of the comment
        @type title: C{unicode}

        @param body: the body of the comment
        @type body: C{unicode}

        @param tags: tags to apply to the comment
        @type tags: iterable of C{unicode}

        @rtype: C{None}
        """
        shareID = self.parent.original.post(title, body, self.parent.getRole())
        role = self.parent.getRole()
        # is role.store correct?
        post = sharing.getShare(role.store, role, shareID)
        for tag in tags:
            post.tag(tag)
Example #33
0
 def test_simpleShare(self):
     """
     Verify that an item which is shared with shareItem can be retrieved and
     manipulated with getShare.  This is an older-style API, on its way to
     deprecation.
     """
     t = PrivateThing(store=self.store, publicData=456)
     shareItemResult = self.assertWarns(
         PendingDeprecationWarning,
         "Use Role.shareItem() instead of sharing.shareItem().",
         __file__,
         lambda : sharing.shareItem(t, toName=u'*****@*****.**'))
     bob = sharing.getPrimaryRole(self.store, u'*****@*****.**')
     gotShare = self.assertWarns(
         PendingDeprecationWarning,
         "Use Role.getShare() instead of sharing.getShare().",
         __file__,
         lambda :
             sharing.getShare(self.store, bob, shareItemResult.shareID))
     gotShare.mutateSomeState()
     self.assertEquals(t.publicData, 456 + 5)