def createBlog(self, title, description): """ Create a top-level BLOG-flavored Blurb with the given title and description, shared for edit with the owner of this store and for viewing with everyone, and return it. @param title: the blog title @type title: C{unicode} @param description: the blog description @type description: C{unicode} """ store = self.store now = Time() blog = Blurb(store=self.store, dateCreated=now, dateLastEdited=now, title=title, body=description, flavor=FLAVOR.BLOG, author=sharing.getSelfRole(self.store)) authorsRole = sharing.getPrimaryRole(store, title + u' blog', True) sharing.getSelfRole(store).becomeMemberOf(authorsRole) sharing.shareItem(blog, authorsRole, shareID=u'blog') everyoneRole = sharing.getEveryoneRole(store) sharing.shareItem(blog, everyoneRole, shareID=u'blog', interfaces=[IViewable]) # this should be configurable blog.permitChildren(everyoneRole, FLAVOR.BLOG_POST, IViewable)
def test_switchTo(self): """ L{ShellServer.switchTo} takes a L{ITerminalServerFactory} and uses it to create a new L{ITerminalProtocol} which it connects to a L{_ReturnToMenuWrapper}. L{buildTerminalProtocol} is passed an L{IViewer}. """ terminal = FakeTerminal() store = Store() # Put a login method into the store so it can have a role. See #2665. LoginMethod( store=store, internal=True, protocol=u'*', verified=True, localpart=u'alice', domain=u'example.com', # Not really an account, but simpler... account=store) server = ShellServer(store) server.makeConnection(terminal) factory = MockTerminalServerFactory() server.switchTo(factory) self.assertIdentical(factory.shellViewer.roleIn(store), getSelfRole(store)) self.assertTrue(isinstance(server._protocol, MockTerminalProtocol)) self.assertTrue( isinstance(server._protocol.terminal, _ReturnToMenuWrapper)) self.assertIdentical(server._protocol.terminal._shell, server) self.assertIdentical(server._protocol.terminal._terminal, terminal)
def test_roleInMyStore(self): """ L{_AuthenticatedWebViewer} should always return the 'self' role for users looking at their own stores. """ role = getSelfRole(self.adminStore) self.assertIdentical(self.pageFactory.roleIn(self.adminStore), role)
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)
def test_getSelfRole(self): """ The self-role of a store should be determined by its L{LoginMethod}s. """ self.assertEquals(list(self.store.query(sharing.Role)), []) me = sharing.getSelfRole(self.store) self.assertEquals(me.externalID, u'*****@*****.**') self.assertEquals(me.store, self.store) self.assertEquals(list(me.allRoles()), [me, sharing.getAuthenticatedRole(self.store), sharing.getEveryoneRole(self.store)])
def blogs(self, req, tag): """ Render all blogs """ p = inevow.IQ(self.docFactory).patternGenerator('blog') webapp = ixmantissa.IWebTranslator(self.hyperbola.store) blogs = list() primaryRole = sharing.getSelfRole(self.hyperbola.store) for blog in self.hyperbola.getTopLevelFor(primaryRole): blogs.append(p.fillSlots( 'title', blog.title).fillSlots( 'link', websharing.linkTo(blog)).fillSlots( 'post-url', self._getPostURL(blog))) return tag[blogs]
def setUp(self): """ Create a post enough state to have a view for commenting on it. """ self.store = emptyMantissaSiteStore() self.flavor = hyperblurb.FLAVOR.BLOG_POST self.author = sharing.getSelfRole(self.store) self.post = hyperblurb.Blurb( store=self.store, author=self.author, flavor=self.flavor) self.postShare = self.author.shareItem(self.post) self.sharedPost = self.author.getShare(self.postShare.shareID) self.postView = hyperbola_view.BlurbViewer(self.sharedPost) self.fragment = hyperbola_view.AddBlogPostDialogFragment( self.postView)
def test_myFirstBlog(self): """ Verify that when the user creates a blog via the default public interface, createBlog, it is editable by the author (e.g. the owner of the store) and viewable by the public. """ self.publicPresence = hyperbola_model.HyperbolaPublicPresence( store=self.store) self.publicPresence.createBlog(u"A wonderful blog", u"Here it is") myBlogs = list(self.publicPresence.getTopLevelFor(getSelfRole(self.store))) yourBlogs = list(self.publicPresence.getTopLevelFor(getEveryoneRole( self.store))) self.failUnless(len(myBlogs) == 1) self.failUnless(len(yourBlogs) == 1) self.failUnless(ihyperbola.IEditable.providedBy(myBlogs[0])) self.failIf(ihyperbola.IEditable.providedBy(yourBlogs[0])) self.failUnless(ihyperbola.IViewable.providedBy(myBlogs[0])) self.failUnless(ihyperbola.IViewable.providedBy(yourBlogs[0])) self.failUnless(ihyperbola.ICommentable.providedBy(myBlogs[0])) self.failIf(ihyperbola.ICommentable.providedBy(yourBlogs[0]))
def test_myFirstBlog(self): """ Verify that when the user creates a blog via the default public interface, createBlog, it is editable by the author (e.g. the owner of the store) and viewable by the public. """ self.publicPresence = hyperbola_model.HyperbolaPublicPresence( store=self.store) self.publicPresence.createBlog(u"A wonderful blog", u"Here it is") myBlogs = list( self.publicPresence.getTopLevelFor(getSelfRole(self.store))) yourBlogs = list( self.publicPresence.getTopLevelFor(getEveryoneRole(self.store))) self.failUnless(len(myBlogs) == 1) self.failUnless(len(yourBlogs) == 1) self.failUnless(ihyperbola.IEditable.providedBy(myBlogs[0])) self.failIf(ihyperbola.IEditable.providedBy(yourBlogs[0])) self.failUnless(ihyperbola.IViewable.providedBy(myBlogs[0])) self.failUnless(ihyperbola.IViewable.providedBy(yourBlogs[0])) self.failUnless(ihyperbola.ICommentable.providedBy(myBlogs[0])) self.failIf(ihyperbola.ICommentable.providedBy(yourBlogs[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)
def populate(siteStore): """ Make a user with a blog and some blog posts. """ Mantissa().installSite(siteStore, '/') userAccount = Create().addAccount( siteStore, u'testuser', u'localhost', u'asdf') userAccount.addLoginMethod( u'testuser', u'localhost', internal=True) userStore = userAccount.avatars.open() hpp = HyperbolaPublicPresence(store=userStore) installOn(hpp, userStore) hpp.createBlog(u'Title', u'Description') selfRole = getSelfRole(userStore) (blog,) = hpp.getTopLevelFor(selfRole) blog.post(u'Title', u'A pretty innocuous body', selfRole) blog.post(u'An HTML POST!', u'<div><h1>OMG A TITLE</h1><blockquote>A decent<p />post.<p />Several lines<p/>though.</blockquote></div>', selfRole) for i in xrange(60): blog.post(u'A post...', u'This is number %s' % (i+1,), selfRole) return blog
def test_switchTo(self): """ L{ShellServer.switchTo} takes a L{ITerminalServerFactory} and uses it to create a new L{ITerminalProtocol} which it connects to a L{_ReturnToMenuWrapper}. L{buildTerminalProtocol} is passed an L{IViewer}. """ terminal = FakeTerminal() store = Store() # Put a login method into the store so it can have a role. See #2665. LoginMethod( store=store, internal=True, protocol=u'*', verified=True, localpart=u'alice', domain=u'example.com', # Not really an account, but simpler... account=store) server = ShellServer(store) server.makeConnection(terminal) factory = MockTerminalServerFactory() server.switchTo(factory) self.assertIdentical(factory.shellViewer.roleIn(store), getSelfRole(store)) self.assertTrue(isinstance(server._protocol, MockTerminalProtocol)) self.assertTrue(isinstance(server._protocol.terminal, _ReturnToMenuWrapper)) self.assertIdentical(server._protocol.terminal._shell, server) self.assertIdentical(server._protocol.terminal._terminal, terminal)
def populate(siteStore): """ Make a user with a blog and some blog posts. """ Mantissa().installSite(siteStore, '/') userAccount = Create().addAccount(siteStore, u'testuser', u'localhost', u'asdf') userAccount.addLoginMethod(u'testuser', u'localhost', internal=True) userStore = userAccount.avatars.open() hpp = HyperbolaPublicPresence(store=userStore) installOn(hpp, userStore) hpp.createBlog(u'Title', u'Description') selfRole = getSelfRole(userStore) (blog, ) = hpp.getTopLevelFor(selfRole) blog.post(u'Title', u'A pretty innocuous body', selfRole) blog.post( u'An HTML POST!', u'<div><h1>OMG A TITLE</h1><blockquote>A decent<p />post.<p />Several lines<p/>though.</blockquote></div>', selfRole) for i in xrange(60): blog.post(u'A post...', u'This is number %s' % (i + 1, ), selfRole) return blog