def afterSetUp(self):
        addNyFolder(self.portal, 'myfolder', contributor='admin', submitted=1)
        start_date = (date.today() - timedelta(days=1)).strftime('%d/%m/%Y')
        end_date = (date.today() + timedelta(days=10)).strftime('%d/%m/%Y')
        addNyTalkBackConsultation(self.portal.myfolder,
                                  title="Test consultation",
                                  start_date=start_date,
                                  end_date=end_date,
                                  contributor='admin',
                                  submitted=1)
        consultation = self.portal.myfolder['test-consultation']

        consultation.addSection(
            id='test-section',
            title='Test section',
            body='<p>First paragraph</p><p>Second paragraph</p>')

        consultation.invitations._send_invitation(
            name='The Invitee',
            email='*****@*****.**',
            organization='Thinkle University',
            notes='Knows his shit',
            inviter_userid='contributor',
            inviter_name='Contributor Test',
            message='')
        self.invite_key = consultation.invitations._invites.values()[0].key

        permattr = '_Naaya___Invite_to_TalkBack_Consultation_Permission'
        setattr(consultation, permattr, ['Reviewer'])

        comments = []
        paragraph_000 = consultation['test-section']['000']
        # comment 0
        id0 = addComment(paragraph_000,
                         contributor='contributor',
                         message=u'comment by contributor (0)')
        comments.append(paragraph_000[id0])

        # comment 1
        id1 = addComment(consultation['test-section']['000'],
                         contributor='invite:' + self.invite_key,
                         message=u'invitee comment (1)')
        comments.append(paragraph_000[id1])

        transaction.commit()

        self.comments = comments
        self.consultation = self.portal.myfolder['test-consultation']
        self.diverted_mail = divert_mail()
        self.cons_url = 'http://localhost/portal/myfolder/test-consultation'
    def test_owner_edit_comment(self):
        self.browser_do_login('reviewer', 'reviewer')

        comment_id = addComment(self.section['000'],
            contributor='reviewer', message='original comment')
        transaction.commit()

        self.browser.go('%s/000/%s/edit_html' % (self.section_url, comment_id))
        form = self.browser.get_form('frmEdit')

        form['message:utf8:ustring'] = 'modified comment'
        self.browser.clicked(form, form.find_control('message:utf8:ustring'))
        self.browser.submit()

        self.assertEqual(self.section['000'][comment_id].message, 'modified comment')

        self.browser_do_logout()

        #login with a different user
        self.browser_do_login('contributor', 'contributor')

        self.browser.go('%s/000/%s/edit_html' % (self.section_url, comment_id))
        self.assertRedirectUnauthorizedPage()

        self.browser_do_logout()
    def test_owner_edit_comment(self):
        self.browser_do_login('reviewer', 'reviewer')

        comment_id = addComment(self.section['000'],
                                contributor='reviewer',
                                message='original comment')
        transaction.commit()

        self.browser.go('%s/000/%s/edit_html' % (self.section_url, comment_id))
        form = self.browser.get_form('frmEdit')

        form['message:utf8:ustring'] = 'modified comment'
        self.browser.clicked(form, form.find_control('message:utf8:ustring'))
        self.browser.submit()

        self.assertEqual(self.section['000'][comment_id].message,
                         'modified comment')

        self.browser_do_logout()

        #login with a different user
        self.browser_do_login('contributor', 'contributor')

        self.browser.go('%s/000/%s/edit_html' % (self.section_url, comment_id))
        self.assertRedirectUnauthorizedPage()

        self.browser_do_logout()
    def afterSetUp(self):
        addNyFolder(self.portal, 'myfolder', contributor='admin', submitted=1)
        start_date = (date.today() - timedelta(days=1)).strftime('%d/%m/%Y')
        end_date = (date.today() + timedelta(days=10)).strftime('%d/%m/%Y')
        addNyTalkBackConsultation(self.portal.myfolder, title="Test consultation",
            start_date=start_date, end_date=end_date,
            contributor='admin', submitted=1)
        consultation = self.portal.myfolder['test-consultation']

        consultation.addSection(
            id='test-section', title='Test section',
            body='<p>First paragraph</p><p>Second paragraph</p>')

        consultation.invitations._send_invitation(
            name='The Invitee', email='*****@*****.**',
            organization='Thinkle University', notes='Knows his shit',
            inviter_userid='contributor', inviter_name='Contributor Test', message='')
        self.invite_key = consultation.invitations._invites.values()[0].key

        permattr = '_Naaya___Invite_to_TalkBack_Consultation_Permission'
        setattr(consultation, permattr, ['Reviewer'])

        comments = []
        paragraph_000 = consultation['test-section']['000']
        # comment 0
        id0 = addComment(paragraph_000,
                         contributor='contributor',
                         message=u'comment by contributor (0)')
        comments.append(paragraph_000[id0])

        # comment 1
        id1 = addComment(consultation['test-section']['000'],
                         contributor='invite:' + self.invite_key,
                         message=u'invitee comment (1)')
        comments.append(paragraph_000[id1])

        transaction.commit()

        self.comments = comments
        self.consultation = self.portal.myfolder['test-consultation']
        self.diverted_mail = divert_mail()
        self.cons_url = 'http://localhost/portal/myfolder/test-consultation'
Beispiel #5
0
    def test_html_summary(self):
        # some simple html
        addComment(self.tb['sec']['000'], contributor='contributor',
                   message="teh <em>html</em> comment & stuff")
        # a broken piece of html
        addComment(self.tb['sec']['000'], contributor='contributor',
                   message="so <p><b>hello<i>world</b>!</i>")

        doc = self.tb.comments_atom()
        dom = minidom.parseString(doc)
        entry1 = dom.getElementsByTagName('entry')[1]
        summary1 = entry1.getElementsByTagName('summary')[0]
        assert (summary1.toxml() ==
                '<summary type="html">teh &lt;em&gt;html&lt;/em&gt; '
                'comment &amp; stuff</summary>')

        entry2 = dom.getElementsByTagName('entry')[0]
        summary2 = entry2.getElementsByTagName('summary')[0]
        print summary2.toxml()
        assert (summary2.toxml() ==
                '<summary type="html">so &lt;p&gt;&lt;b&gt;hello&lt;i&gt;'
                'world&lt;/b&gt;!&lt;/i&gt;</summary>')
Beispiel #6
0
    def test_http_content_type(self):
        comment_id = addComment(self.tb['sec']['000'],
                                contributor='contributor',
                                message="hello world")
        transaction.commit()

        url = '/portal/myfolder/test-consultation/comments_atom'
        response = Request.blank(url).get_response(self.wsgi_request)
        assert response.status == '200 OK', repr(response)
        assert (response.headers['Content-Type'] ==
                'application/atom+xml; charset=utf-8')

        assert "hello world" in response.body
    def test_edit_comment(self):
        comment_id = addComment(self.section['000'],
            contributor='contributor', message='original comment')
        transaction.commit()

        self.browser_do_login('admin', '')

        self.browser.go('%s/000/%s/edit_html' % (self.section_url, comment_id))
        form = self.browser.get_form('frmEdit')
        self.assertEqual(form['message:utf8:ustring'].strip(),
                         'original comment')
        form['message:utf8:ustring'] = 'modified comment'
        self.browser.clicked(form, form.find_control('message:utf8:ustring'))
        self.browser.submit()

        self.assertEqual(self.section['000'][comment_id].message, 'modified comment')

        self.browser_do_logout()
    def test_threaded_comments(self):
        comment1_id = addComment(self.section['000'],
                                 contributor='contributor',
                                 message='original comment')
        transaction.commit()

        self.browser_do_login('contributor', 'contributor')

        self.browser.go('%s/000?reply_to=%s' % (self.section_url, comment1_id))
        form = self.browser.get_form('frmAdd')
        self.assertEqual(form['reply_to'], comment1_id)
        self.assertEqual(
            form['message:utf8:ustring'],
            '<p></p><blockquote>original comment</blockquote><p></p>')
        form['message:utf8:ustring'] = (
            '<p>\n&nbsp;\n</p>\n'
            '<blockquote>original comment</blockquote>\n'
            '<p>\n&nbsp;\n</p>')
        self.browser.clicked(form, form.find_control('message:utf8:ustring'))
        self.browser.submit()

        comment2_id = (set(self.section['000'].objectIds()) -
                       set([comment1_id])).pop()
        comment2 = self.section['000'][comment2_id]
        self.assertEqual(comment2.reply_to, comment1_id)
        self.assertEqual(comment2.message,
                         '<blockquote>original comment</blockquote>')

        # make sure we can't add a reply to a non-existent comment
        self.browser.go('%s/000?reply_to=%s' % (self.section_url, comment1_id))
        self.section['000'].manage_delObjects([comment1_id])
        transaction.commit()
        form = self.browser.get_form('frmAdd')
        self.browser.clicked(form, form.find_control('message:utf8:ustring'))
        self.browser.submit()

        self.assertEqual(
            len(self.section['000'].objectIds()), 1,
            'Should not have created comment with bogus '
            '`reply_to` value')

        self.browser_do_logout()
    def test_edit_comment(self):
        comment_id = addComment(self.section['000'],
                                contributor='contributor',
                                message='original comment')
        transaction.commit()

        self.browser_do_login('admin', '')

        self.browser.go('%s/000/%s/edit_html' % (self.section_url, comment_id))
        form = self.browser.get_form('frmEdit')
        self.assertEqual(form['message:utf8:ustring'].strip(),
                         'original comment')
        form['message:utf8:ustring'] = 'modified comment'
        self.browser.clicked(form, form.find_control('message:utf8:ustring'))
        self.browser.submit()

        self.assertEqual(self.section['000'][comment_id].message,
                         'modified comment')

        self.browser_do_logout()
Beispiel #10
0
    def test_invited_comments_admin(self):
        comment_id = addComment(self.consultation['test-section']['000'],
                                contributor='invite:' + self.invite_key,
                                message=u'invitee comment')
        transaction.commit()

        self.browser_do_login('contributor', 'contributor')

        edit_url = '%s/test-section/000/%s/edit_html' % (self.cons_url, comment_id)
        self.browser.go('%s/test-section/000' % self.cons_url)
        self.assertTrue(edit_url in self.browser.get_html())

        self.browser.go(edit_url)
        self.assertRedirectUnauthorizedPage(False)

        form = self.browser.get_form('frmEdit')
        form['message:utf8:ustring'] = 'edited'
        self.browser.clicked(form, form.find_control('message:utf8:ustring'))
        self.browser.submit()
        self.assertRedirectUnauthorizedPage(False)

        self.browser_do_logout()
    def test_threaded_comments(self):
        comment1_id = addComment(self.section['000'],
            contributor='contributor', message='original comment')
        transaction.commit()

        self.browser_do_login('contributor', 'contributor')

        self.browser.go('%s/000?reply_to=%s' % (self.section_url, comment1_id))
        form = self.browser.get_form('frmAdd')
        self.assertEqual(form['reply_to'], comment1_id)
        self.assertEqual(form['message:utf8:ustring'],
                         '<p></p><blockquote>original comment</blockquote><p></p>')
        form['message:utf8:ustring'] = ('<p>\n&nbsp;\n</p>\n'
                                        '<blockquote>original comment</blockquote>\n'
                                        '<p>\n&nbsp;\n</p>')
        self.browser.clicked(form, form.find_control('message:utf8:ustring'))
        self.browser.submit()

        comment2_id = ( set(self.section['000'].objectIds()) -
                        set([comment1_id])
                      ).pop()
        comment2 = self.section['000'][comment2_id]
        self.assertEqual(comment2.reply_to, comment1_id)
        self.assertEqual(comment2.message, '<blockquote>original comment</blockquote>')

        # make sure we can't add a reply to a non-existent comment
        self.browser.go('%s/000?reply_to=%s' % (self.section_url, comment1_id))
        self.section['000'].manage_delObjects([comment1_id])
        transaction.commit()
        form = self.browser.get_form('frmAdd')
        self.browser.clicked(form, form.find_control('message:utf8:ustring'))
        self.browser.submit()

        self.assertEqual(len(self.section['000'].objectIds()), 1,
                         'Should not have created comment with bogus '
                         '`reply_to` value')

        self.browser_do_logout()
Beispiel #12
0
    def test_one_entry(self):
        comment_id = addComment(self.tb['sec']['000'],
                                contributor='contributor',
                                message="hello world")

        doc = self.tb.comments_atom()
        dom = minidom.parseString(doc)

        assert len(dom.getElementsByTagName('entry')) == 1
        entry = dom.getElementsByTagName('entry')[0]

        assert (entry.getElementsByTagName('title')[0].firstChild.data ==
                "Comment by Contributor Test (contributor)")

        assert len(entry.getElementsByTagName('author')) == 1
        author = entry.getElementsByTagName('author')[0]
        assert (author.getElementsByTagName('name')[0].firstChild.data ==
                "Contributor Test (contributor)")

        assert (entry.getElementsByTagName('id')[0].firstChild.data ==
                self.tb_url + '/sec/000/' + comment_id)

        assert (entry.getElementsByTagName('summary')[0].firstChild.data ==
                "hello world")
Beispiel #13
0
 def add_comment(msg, delta=timedelta()):
     para = self.tb['sec']['000']
     cid = addComment(para, contributor='contributor', message=msg)
     comment = para[cid]
     comment.comment_date = dt2DT(DT2dt(comment.comment_date) + delta)
     return comment