def test_notifications_for_new_post(self):
        ws = self.portal['workspaces']['workspace-1']
        people = self.portal['people']
        self.mailhost.messages = []
        login(self.portal, 'test_user_1')

        post = helpers.create_post(ws, 'new-post', title=u"New Post",
            text=richtextify(u"<p>test</p><p>test</p>123"))

        self.assertEqual(len(self.mailhost.messages), 0)

        helpers.publish_post(post)

        self.assertEqual(len(self.mailhost.messages), 2)

        recipients = [unicode(m['To']) for m in self.mailhost.messages]
        expected_recipients = []
        for uid in ws.getMemberIds():
            name = getattr(people.get(uid, None), 'title', uid)
            email = getattr(people.get(uid, None), 'emailAddress', None)
            if not email:
                continue
            expected_recipients.append('{0} <{1}>'.format(name, email))
        self.assertEqual(recipients, expected_recipients)

        for message in self.mailhost.messages:
            self.assertEqual(unicode(message['Subject']), u"[Plone site] " +
                u"New post: “New Post” by Test User in Workspace 1")

            msg_text = quopri.decodestring(message.get_payload())
            expected_msg_text = u"test\n\ntest\n123"
            self.assertEqual(msg_text, expected_msg_text)
    def test_invalid_recipient(self):
        ws = self.portal['workspaces']['workspace-1']
        ws.addMember('non_existing_member')
        self.mailhost.messages = []
        login(self.portal, 'test_user_1')

        post = helpers.create_post(ws, 'new-post', title=u"New Post")
        helpers.publish_post(post)

        self.assertEqual(len(self.mailhost.messages), 2)
    def test_notifications_disabled(self):
        ws = self.portal['workspaces']['workspace-1']
        self.portal['people']['test_user_1'].recieveNotifications = False
        self.portal['people']['test_user_2'].recieveNotifications = False
        self.mailhost.messages = []
        login(self.portal, 'test_user_1')

        post = helpers.create_post(ws, 'new-post', title=u"New Post")
        helpers.publish_post(post)
        helpers.create_reply(post, 'new-reply', title=u"New Reply")

        self.assertEqual(len(self.mailhost.messages), 0)
    def test_browse_posts(self):
        """A minimal functional test for posts."""
        setRoles(self.portal, TEST_USER_ID, ('Manager',))

        # create, publish and join a workspace:
        ws = helpers.create_workspace(self.portal, 'ws1', title=u"Workspace 1")
        ws.addMember(SITE_MEMBER)

        import transaction
        transaction.commit()

        browser = Browser(self.app)
        browser.handleErrors = False

        # Log in as a user
        browser.addHeader(
            'Authorization',
            'Basic %s:%s' % (SITE_MEMBER, PASSWORD,))

        # go to conversation:
        browser.open("%s/conversation" % ws.absolute_url())

        # create another post:
        browser.getLink(text='Post').click()
        title = browser.getControl(name='form.widgets.title')
        title.value = "The Post"
        text = browser.getControl(name='form.widgets.text')
        text.value = "<p>Blah, blah, test.</p>"
        browser.getControl(name='form.buttons.save').click()

        self.assertIn('the-post', ws)
        post = ws['the-post']

        # publish the post:
        # TODO: we cheat because there is no publishing interface available to
        #       normal users.
        helpers.publish_post(post)

        # the post should be published:
        pw = getToolByName(self.portal, 'portal_workflow')
        self.assertEqual(pw.getInfoFor(post, 'review_state'), 'published')

        # we should be send to the posts view now:
        self.assertTrue("The Post" in browser.contents)
        self.assertTrue("Blah, blah, test." in browser.contents)

        # TODO: edit the post:
        browser.getLink(text='Edit')
示例#5
0
    def test_reply_creation(self):
        setRoles(self.portal, TEST_USER_ID, ('Manager',))

        ws = helpers.create_workspace(self.portal, 'ws1', title=u"Workspace 1")
        p = helpers.create_post(ws, 'p1', title=u"Post 1")
        p = helpers.publish_post(p)
        r = helpers.create_reply(p, 'r1', title=u"Reply 1")

        self.assertTrue('r1' in p)
        self.assertEqual(r, p['r1'])
示例#6
0
    def test_post_publishing(self):
        setRoles(self.portal, TEST_USER_ID, ('Manager',))

        ws = helpers.create_workspace(self.portal, 'ws1', title=u"Workspace 1")
        post = helpers.create_post(ws, 'post-1', title=u"Post 1")
        post = helpers.publish_post(post)

        self.assertEqual(post, ws['post-1'])

        # the post should be published:
        pw = getToolByName(self.portal, 'portal_workflow')
        self.assertEqual(pw.getInfoFor(post, 'review_state'), 'published')
    def test_thread_sort(self):
        setRoles(self.portal, TEST_USER_ID, ('Manager',))

        ws = helpers.create_workspace(self.portal, 'ws1', title=u"Workspace 1")

        t1 = helpers.publish_post(helpers.create_task(
            ws, 't1', title=u"Task 1",
            deadline=datetime.now() + timedelta(1)))
        p1 = helpers.publish_post(helpers.create_post(
            ws, 'p1', title=u"Post 1",
            creation_date=DateTime() - 3))
        t2 = helpers.publish_post(helpers.create_task(
            ws, 't2', title=u"Task 2",
            deadline=datetime.now() - timedelta(4)))
        t3 = helpers.publish_post(helpers.create_task(
            ws, 't3', title=u"Task 3",
            deadline=datetime.now() - timedelta(2)))
        p2 = helpers.publish_post(helpers.create_post(
            ws, 'p2', title=u"Post 2",
            creation_date=DateTime() - 1))
        r1 = helpers.create_reply(
            p2, 'r1', title=u"Reply 1",
            creation_date=DateTime() - 1)
        p3 = helpers.publish_post(helpers.create_post(
            ws, 'p3', title=u"Post 3",
            creation_date=DateTime()))
        r2 = helpers.create_reply(
            p2, 'r2', title=u"Reply 2",
            creation_date=DateTime())
        r3 = helpers.create_reply(
            p2, 'r3', title=u"Reply 3",
            creation_date=DateTime() + 1)

        conversation = ws.unrestrictedTraverse('@@conversation')
        post_brains = conversation.brains

        result = []

        for post_brain in post_brains:
            post = post_brain.getObject()
            result.append(post.id)

            thread = post.unrestrictedTraverse('@@thread')
            for reply_brain in thread.replies:
                result.append(reply_brain.getId)

        expected = [t1, p3, p2, r1, r2, r3, t3, p1, t2]
        expected = [x.id for x in expected]

        self.assertEqual(result, expected)
示例#8
0
    def test_reply_permissions(self):
        setRoles(self.portal, TEST_USER_ID, ('Manager',))

        ws = helpers.create_workspace(self.portal, 'ws1', title=u"Workspace 1")
        p = helpers.create_post(ws, 'p1', title=u"Post 1")
        p = helpers.publish_post(p)
        r = helpers.create_reply(p, 'r1', title=u"Reply 1")
        pt = helpers.PermissionTester(r)

        # Anonymous cannot view (permission may be aquired):
        self.assertFalse(pt.has('Anonymous', 'View'))

        # Owners, contributors, editors and admins can add content:
        self.assertTrue(pt.has('Owner', 'Add portal content'))
        self.assertTrue(pt.has('Contributor', 'Add portal content'))
        self.assertTrue(pt.has('Editor', 'Add portal content'))
        self.assertTrue(pt.has('Manager', 'Add portal content'))
        self.assertTrue(pt.has('Site Administrator', 'Add portal content'))
        # others can't:
        self.assertFalse(pt.has('Authenticated', 'Add portal content'))
        self.assertFalse(pt.has('Anonymous', 'Add portal content'))

        # Owners and admins can modify and delete content:
        self.assertTrue(pt.has('Owner', 'Modify portal content'))
        self.assertTrue(pt.has('Manager', 'Modify portal content'))
        self.assertTrue(pt.has('Site Administrator', 'Modify portal content'))
        self.assertTrue(pt.has('Owner', 'Delete objects'))
        self.assertTrue(pt.has('Manager', 'Delete objects'))
        self.assertTrue(pt.has('Site Administrator', 'Delete objects'))
        # others can't:
        self.assertFalse(pt.has('Editor', 'Modify portal content'))
        self.assertFalse(pt.has('Contributor', 'Modify portal content'))
        self.assertFalse(pt.has('Authenticated', 'Modify portal content'))
        self.assertFalse(pt.has('Anonymous', 'Modify portal content'))
        self.assertFalse(pt.has('Editor', 'Delete objects'))
        self.assertFalse(pt.has('Contributor', 'Delete objects'))
        self.assertFalse(pt.has('Authenticated', 'Delete objects'))
        self.assertFalse(pt.has('Anonymous', 'Delete objects'))

        # reply to our reply to have it set to 'active':
        helpers.create_reply(r, 'r2', text=u"Reply 2")

        # Anonymous cannot view (permission may be aquired):
        self.assertFalse(pt.has('Anonymous', 'View'))

        # Owners, contributors, editors and admins can add content:
        self.assertTrue(pt.has('Owner', 'Add portal content'))
        self.assertTrue(pt.has('Contributor', 'Add portal content'))
        self.assertTrue(pt.has('Editor', 'Add portal content'))
        self.assertTrue(pt.has('Manager', 'Add portal content'))
        self.assertTrue(pt.has('Site Administrator', 'Add portal content'))
        # others can't:
        self.assertFalse(pt.has('Authenticated', 'Add portal content'))
        self.assertFalse(pt.has('Anonymous', 'Add portal content'))

        # Owners and admins can modify content:
        self.assertTrue(pt.has('Owner', 'Modify portal content'))
        self.assertTrue(pt.has('Manager', 'Modify portal content'))
        self.assertTrue(pt.has('Site Administrator', 'Modify portal content'))
        # others can't:
        self.assertFalse(pt.has('Editor', 'Modify portal content'))
        self.assertFalse(pt.has('Contributor', 'Modify portal content'))
        self.assertFalse(pt.has('Authenticated', 'Modify portal content'))
        self.assertFalse(pt.has('Anonymous', 'Modify portal content'))

        # administrators can delete:
        self.assertTrue(pt.has('Manager', 'Delete objects'))
        self.assertTrue(pt.has('Site Administrator', 'Delete objects'))
        # others can't:
        self.assertFalse(pt.has('Owner', 'Delete objects'))
        self.assertFalse(pt.has('Editor', 'Delete objects'))
        self.assertFalse(pt.has('Contributor', 'Delete objects'))
        self.assertFalse(pt.has('Authenticated', 'Delete objects'))
        self.assertFalse(pt.has('Anonymous', 'Delete objects'))
    def test_task_publishing(self):
        self.task = helpers.publish_post(self.task)

        # the task should be published:
        pw = getToolByName(self.portal, 'portal_workflow')
        self.assertEqual(pw.getInfoFor(self.task, 'review_state'), 'published')