コード例 #1
0
    def test_notifications_for_new_reply(self):
        ws = self.portal['workspaces']['workspace-1']
        people = self.portal['people']
        post = ws['post-2']
        self.mailhost.messages = []
        login(self.portal, 'test_user_1')
        helpers.create_reply(post, 'new-reply',
            text=richtextify(u"<p>test</p><p>test</p>123"))

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

        recipients = [unicode(m['To']) for m in self.mailhost.messages]
        expected_recipients = []
        for uid in ['test_user_1', 'test_user_2']:
            name = getattr(people.get(uid, None), 'title', uid)
            email = getattr(people.get(uid, None), 'emailAddress', None)
            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"Test User replied to “Post 2” 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)
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
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'])
コード例 #5
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'))