Exemple #1
0
    def test_autowatch_reply(self, get_current):
        get_current.return_value.domain = 'testserver'

        u = user(save=True)
        t1 = thread(is_locked=False, save=True)
        t2 = thread(is_locked=False, save=True)
        assert not NewPostEvent.is_notifying(u, t1)
        assert not NewPostEvent.is_notifying(u, t2)

        self.client.login(username=u.username, password='******')
        s = Setting.objects.create(user=u,
                                   name='kbforums_watch_after_reply',
                                   value='True')
        data = {'content': 'some content'}
        post(self.client,
             'wiki.discuss.reply',
             data,
             args=[t1.document.slug, t1.pk])
        assert NewPostEvent.is_notifying(u, t1)

        s.value = 'False'
        s.save()
        post(self.client,
             'wiki.discuss.reply',
             data,
             args=[t2.document.slug, t2.pk])
        assert not NewPostEvent.is_notifying(u, t2)
Exemple #2
0
 def test_threads_sort(self):
     """Ensure that threads are being sorted properly by date/time."""
     d = document(save=True)
     t = thread(document=d, save=True)
     t.new_post(creator=t.creator, content='foo')
     time.sleep(1)
     t2 = thread(document=d, save=True)
     t2.new_post(creator=t2.creator, content='foo')
     given_ = ThreadsFeed().items(d)[0].id
     eq_(t2.id, given_)
Exemple #3
0
 def test_threads_sort(self):
     """Ensure that threads are being sorted properly by date/time."""
     d = document(save=True)
     t = thread(document=d, save=True)
     t.new_post(creator=t.creator, content='foo')
     time.sleep(1)
     t2 = thread(document=d, save=True)
     t2.new_post(creator=t2.creator, content='foo')
     given_ = ThreadsFeed().items(d)[0].id
     eq_(t2.id, given_)
    def test_watch_other_thread_then_reply(self):
        """Watching a different thread than the one we're replying to shouldn't
        notify."""
        u_b = user(username="******", save=True)
        _t = thread(save=True)
        self._toggle_watch_thread_as(u_b.username, _t, turn_on=True)
        u = user(save=True)
        t2 = thread(save=True)
        self.client.login(username=u.username, password="******")
        post(self.client, "wiki.discuss.reply", {"content": "a post"}, args=[t2.document.slug, t2.id])

        assert not mail.outbox
    def test_watch_other_thread_then_reply(self):
        """Watching a different thread than the one we're replying to shouldn't
        notify."""
        u_b = user(username='******', save=True)
        _t = thread(save=True)
        self._toggle_watch_thread_as(u_b.username, _t, turn_on=True)
        u = user(save=True)
        t2 = thread(save=True)
        self.client.login(username=u.username, password='******')
        post(self.client, 'wiki.discuss.reply', {'content': 'a post'},
             args=[t2.document.slug, t2.id])

        assert not mail.outbox
Exemple #6
0
 def test_edit_locked_thread_403(self):
     """Editing a locked thread returns 403."""
     t = thread(document=self.doc, creator=self.u, is_locked=True,
                save=True)
     response = get(self.client, 'wiki.discuss.edit_thread',
                    args=[self.doc.slug, t.id])
     eq_(403, response.status_code)
Exemple #7
0
    def test_watch_all_then_new_post(self, get_current):
        """Watching document + thread + locale and reply to thread."""
        get_current.return_value.domain = 'testserver'

        u = user(save=True)
        _d = document(title='an article title', save=True)
        d = self._toggle_watch_kbforum_as(u.username, _d, turn_on=True)
        t = thread(title='Sticky Thread', document=d, save=True)
        self._toggle_watch_thread_as(u.username, t, turn_on=True)
        self.client.login(username=u.username, password='******')
        post(self.client, 'wiki.discuss.watch_locale', {'watch': 'yes'})

        # Reply as jsocol to document d.
        u2 = user(username='******', save=True)
        self.client.login(username=u2.username, password='******')
        post(self.client,
             'wiki.discuss.reply', {'content': 'a post'},
             args=[d.slug, t.id])

        # Only ONE email was sent. As expected.
        eq_(1, len(mail.outbox))
        p = Post.objects.all().order_by('-id')[0]
        attrs_eq(mail.outbox[0],
                 to=[u.email],
                 subject='Re: an article title - Sticky Thread')
        starts_with(mail.outbox[0].body, REPLY_EMAIL % (d.slug, t.id, p.id))
Exemple #8
0
 def setUp(self):
     super(KBBelongsTestCase, self).setUp()
     u = user(save=True)
     self.doc = document(title='spam', save=True)
     self.doc_2 = document(title='eggs', save=True)
     self.thread = thread(creator=u, document=self.doc, is_locked=False,
                          save=True)
     self.thread_2 = thread(creator=u, document=self.doc_2, is_locked=False,
                            save=True)
     permissions = ('sticky_thread', 'lock_thread', 'delete_thread',
                    'delete_post')
     for permission in permissions:
         add_permission(u, self.thread, permission)
     self.post = self.thread.new_post(creator=self.thread.creator,
                                      content='foo')
     self.client.login(username=u.username, password='******')
Exemple #9
0
    def setUp(self):
        super(KBSaveDateTestCase, self).setUp()

        self.user = user(save=True)
        self.doc = document(save=True)
        self.thread = thread(created=datetime.datetime(2010, 1, 12, 9, 48, 23),
                             save=True)
Exemple #10
0
    def setUp(self):
        super(KBSaveDateTestCase, self).setUp()

        self.user = user(save=True)
        self.doc = document(save=True)
        self.thread = thread(created=datetime.datetime(2010, 1, 12, 9, 48, 23),
                             save=True)
Exemple #11
0
 def test_posts_sort(self):
     """Ensure that posts are being sorted properly by date/time."""
     t = thread(save=True)
     t.new_post(creator=t.creator, content='foo')
     time.sleep(1)
     p2 = t.new_post(creator=t.creator, content='foo')
     given_ = PostsFeed().items(t)[0].id
     eq_(p2.id, given_)
Exemple #12
0
 def test_posts_sort(self):
     """Ensure that posts are being sorted properly by date/time."""
     t = thread(save=True)
     t.new_post(creator=t.creator, content='foo')
     time.sleep(1)
     p2 = t.new_post(creator=t.creator, content='foo')
     given_ = PostsFeed().items(t)[0].id
     eq_(p2.id, given_)
Exemple #13
0
 def test_delete_last_and_only_post_in_thread(self):
     """Deleting the only post in a thread should delete the thread"""
     d = document(save=True)
     t = thread(title="test", document=d, save=True)
     p = t.new_post(creator=t.creator, content="test")
     eq_(1, t.post_set.count())
     p.delete()
     eq_(0, Thread.objects.filter(pk=t.id).count())
Exemple #14
0
 def test_post_absolute_url(self):
     t = thread(save=True)
     p = t.new_post(creator=t.creator, content='foo')
     url_ = reverse('wiki.discuss.posts',
                    locale=p.thread.document.locale,
                    args=[p.thread.document.slug, p.thread.id])
     exp_ = urlparams(url_, hash='post-{0!s}'.format(p.id))
     eq_(exp_, p.get_absolute_url())
Exemple #15
0
 def test_delete_last_and_only_post_in_thread(self):
     """Deleting the only post in a thread should delete the thread"""
     d = document(save=True)
     t = thread(title="test", document=d, save=True)
     p = t.new_post(creator=t.creator, content="test")
     eq_(1, t.post_set.count())
     p.delete()
     eq_(0, Thread.uncached.filter(pk=t.id).count())
 def test_fire_on_reply(self, fire):
     """The event fires when there is a reply."""
     t = thread(save=True)
     u = user(save=True)
     self.client.login(username=u.username, password="******")
     post(self.client, "wiki.discuss.reply", {"content": "a post"}, args=[t.document.slug, t.id])
     # NewPostEvent.fire() is called.
     assert fire.called
Exemple #17
0
 def test_post_absolute_url(self):
     t = thread(save=True)
     p = t.new_post(creator=t.creator, content='foo')
     url_ = reverse('wiki.discuss.posts',
                    locale=p.thread.document.locale,
                    args=[p.thread.document.slug, p.thread.id])
     exp_ = urlparams(url_, hash='post-%s' % p.id)
     eq_(exp_, p.get_absolute_url())
 def test_fire_on_reply(self, fire):
     """The event fires when there is a reply."""
     t = thread(save=True)
     u = user(save=True)
     self.client.login(username=u.username, password='******')
     post(self.client, 'wiki.discuss.reply', {'content': 'a post'},
          args=[t.document.slug, t.id])
     # NewPostEvent.fire() is called.
     assert fire.called
 def test_locale_discussions_ignores_sticky(self):
     """Sticky flag is ignored in locale discussions view"""
     u = user(save=True)
     d = document(save=True)
     t = thread(title='Sticky Thread', is_sticky=True, document=d,
                save=True)
     t.new_post(creator=u, content='foo')
     t2 = thread(title='A thread with a very very long',
                 is_sticky=False, document=d, save=True)
     t2.new_post(creator=u, content='bar')
     time.sleep(1)
     t2.new_post(creator=u, content='last')
     self.client.login(username=u.username, password='******')
     response = post(self.client, 'wiki.locale_discussions')
     eq_(200, response.status_code)
     doc = pq(response.content)
     title = doc('ol.threads li div.title a:first').text()
     assert title.startswith('A thread with a very very long')
 def test_long_title_truncated_in_crumbs(self):
     """A very long thread title gets truncated in the breadcrumbs"""
     d = document(save=True)
     t = thread(title='A thread with a very very very very very' * 5, document=d,
                save=True)
     response = get(self.client, 'wiki.discuss.posts', args=[d.slug, t.id])
     doc = pq(response.content)
     crumb = doc('#breadcrumbs li:last-child')
     eq_(crumb.text(), 'A thread with a very very very very ...')
 def test_links_nofollow(self):
     """Links posted should have rel=nofollow."""
     u = user(save=True)
     t = thread(save=True)
     t.new_post(creator=u, content='linking http://test.org')
     response = get(self.client, 'wiki.discuss.posts',
                    args=[t.document.slug, t.pk])
     doc = pq(response.content)
     eq_('nofollow', doc('ol.posts div.content a')[0].attrib['rel'])
Exemple #22
0
 def test_long_title_truncated_in_crumbs(self):
     """A very long thread title gets truncated in the breadcrumbs"""
     d = document(save=True)
     t = thread(title='A thread with a very very very very very' * 5,
                document=d,
                save=True)
     response = get(self.client, 'wiki.discuss.posts', args=[d.slug, t.id])
     doc = pq(response.content)
     crumb = doc('#breadcrumbs li:last-child')
     eq_(crumb.text(), 'A thread with a very very very very ...')
Exemple #23
0
 def test_edit_locked_thread_403(self):
     """Editing a locked thread returns 403."""
     t = thread(document=self.doc,
                creator=self.u,
                is_locked=True,
                save=True)
     response = get(self.client,
                    'wiki.discuss.edit_thread',
                    args=[self.doc.slug, t.id])
     eq_(403, response.status_code)
    def test_autowatch_reply(self, get_current):
        get_current.return_value.domain = "testserver"

        u = user(save=True)
        t1 = thread(is_locked=False, save=True)
        t2 = thread(is_locked=False, save=True)
        assert not NewPostEvent.is_notifying(u, t1)
        assert not NewPostEvent.is_notifying(u, t2)

        self.client.login(username=u.username, password="******")
        s = Setting.objects.create(user=u, name="kbforums_watch_after_reply", value="True")
        data = {"content": "some content"}
        post(self.client, "wiki.discuss.reply", data, args=[t1.document.slug, t1.pk])
        assert NewPostEvent.is_notifying(u, t1)

        s.value = "False"
        s.save()
        post(self.client, "wiki.discuss.reply", data, args=[t2.document.slug, t2.pk])
        assert not NewPostEvent.is_notifying(u, t2)
Exemple #25
0
 def test_links_nofollow(self):
     """Links posted should have rel=nofollow."""
     u = user(save=True)
     t = thread(save=True)
     t.new_post(creator=u, content='linking http://test.org')
     response = get(self.client,
                    'wiki.discuss.posts',
                    args=[t.document.slug, t.pk])
     doc = pq(response.content)
     eq_('nofollow', doc('ol.posts div.content a')[0].attrib['rel'])
Exemple #26
0
 def setUp(self):
     super(ThreadPermissionsTests, self).setUp()
     self.doc = document(save=True)
     self.u = user(save=True)
     self.thread = thread(document=self.doc, creator=self.u, save=True)
     self.post = self.thread.new_post(creator=self.thread.creator,
                                      content='foo')
     # Login for testing 403s
     u2 = user(save=True)
     self.client.login(username=u2.username, password='******')
Exemple #27
0
 def setUp(self):
     super(ThreadPermissionsTests, self).setUp()
     self.doc = document(save=True)
     self.u = user(save=True)
     self.thread = thread(document=self.doc, creator=self.u, save=True)
     self.post = self.thread.new_post(creator=self.thread.creator,
                                      content='foo')
     # Login for testing 403s
     u2 = user(save=True)
     self.client.login(username=u2.username, password='******')
    def test_edit_thread_template(self):
        """The edit-thread template should render."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        t = thread(creator=u, is_locked=False, save=True)
        res = get(self.client, 'wiki.discuss.edit_thread',
                  args=[t.document.slug, t.id])

        doc = pq(res.content)
        eq_(len(doc('form.edit-thread')), 1)
 def test_last_thread_post_link_has_post_id(self):
     """Make sure the last post url links to the last post (#post-<id>)."""
     u = user(save=True)
     t = thread(save=True)
     t.new_post(creator=u, content='foo')
     p2 = t.new_post(creator=u, content='bar')
     response = get(self.client, 'wiki.discuss.threads',
                    args=[t.document.slug])
     doc = pq(response.content)
     last_post_link = doc('ol.threads div.last-post a:not(.username)')[0]
     href = last_post_link.attrib['href']
     eq_(href.split('#')[1], 'post-%d' % p2.id)
Exemple #30
0
    def test_edit_thread_template(self):
        """The edit-thread template should render."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        t = thread(creator=u, is_locked=False, save=True)
        res = get(self.client,
                  'wiki.discuss.edit_thread',
                  args=[t.document.slug, t.id])

        doc = pq(res.content)
        eq_(len(doc('form.edit-thread')), 1)
    def test_watch_forum_then_new_post_as_self(self, get_current):
        """Watching a forum and replying as myself should not send email."""
        get_current.return_value.domain = "testserver"

        u = user(save=True)
        d = document(title="an article title", save=True)
        f = self._toggle_watch_kbforum_as(u.username, d, turn_on=True)
        t = thread(document=d, save=True)
        self.client.login(username=u.username, password="******")
        post(self.client, "wiki.discuss.reply", {"content": "a post"}, args=[f.slug, t.id])
        # Assert no email is sent.
        assert not mail.outbox
Exemple #32
0
 def test_last_thread_post_link_has_post_id(self):
     """Make sure the last post url links to the last post (#post-<id>)."""
     u = user(save=True)
     t = thread(save=True)
     t.new_post(creator=u, content='foo')
     p2 = t.new_post(creator=u, content='bar')
     response = get(self.client,
                    'wiki.discuss.threads',
                    args=[t.document.slug])
     doc = pq(response.content)
     last_post_link = doc('ol.threads div.last-post a:not(.username)')[0]
     href = last_post_link.attrib['href']
     eq_(href.split('#')[1], 'post-%d' % p2.id)
Exemple #33
0
 def test_locale_discussions_ignores_sticky(self):
     """Sticky flag is ignored in locale discussions view"""
     u = user(save=True)
     d = document(save=True)
     t = thread(title='Sticky Thread',
                is_sticky=True,
                document=d,
                save=True)
     t.new_post(creator=u, content='foo')
     t2 = thread(title='A thread with a very very long',
                 is_sticky=False,
                 document=d,
                 save=True)
     t2.new_post(creator=u, content='bar')
     time.sleep(1)
     t2.new_post(creator=u, content='last')
     self.client.login(username=u.username, password='******')
     response = post(self.client, 'wiki.locale_discussions')
     eq_(200, response.status_code)
     doc = pq(response.content)
     title = doc('ol.threads li div.title a:first').text()
     assert title.startswith('A thread with a very very long')
    def test_empty_reply_errors(self):
        """Posting an empty reply shows errors."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        d = document(save=True)
        t = thread(document=d, save=True)
        response = post(self.client, 'wiki.discuss.reply', {'content': ''},
                        args=[d.slug, t.id])

        doc = pq(response.content)
        error_msg = doc('ul.errorlist li a')[0]
        eq_(error_msg.text, 'Please provide a message.')
    def test_watch_forum_then_new_post_as_self(self, get_current):
        """Watching a forum and replying as myself should not send email."""
        get_current.return_value.domain = 'testserver'

        u = user(save=True)
        d = document(title='an article title', save=True)
        f = self._toggle_watch_kbforum_as(u.username, d, turn_on=True)
        t = thread(document=d, save=True)
        self.client.login(username=u.username, password='******')
        post(self.client, 'wiki.discuss.reply', {'content': 'a post'},
             args=[f.slug, t.id])
        # Assert no email is sent.
        assert not mail.outbox
    def test_watch_thread(self):
        """Watch and unwatch a thread."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        t = thread(save=True)
        response = post(self.client, 'wiki.discuss.watch_thread',
                        {'watch': 'yes'}, args=[t.document.slug, t.id])
        self.assertContains(response, 'Stop')

        response = post(self.client, 'wiki.discuss.watch_thread',
                        {'watch': 'no'}, args=[t.document.slug, t.id])
        self.assertNotContains(response, 'Stop')
Exemple #37
0
    def test_edit_thread(self):
        """Changing thread title works."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        d = document(save=True)
        t = thread(title='Sticky Thread', document=d, creator=u, save=True)
        post(self.client, 'wiki.discuss.edit_thread', {'title': 'A new title'},
             args=[d.slug, t.id])
        edited_t = d.thread_set.get(pk=t.id)

        eq_('Sticky Thread', t.title)
        eq_('A new title', edited_t.title)
Exemple #38
0
 def test_flag_kbforum_post(self):
     u = user(save=True)
     t = thread(save=True)
     p = t.new_post(creator=u, content='foo')
     f = FlaggedObject(content_object=p, reason='spam', creator_id=u.id)
     f.save()
     # Make sure flagit queue page works
     u2 = user(save=True)
     add_permission(u2, FlaggedObject, 'can_moderate')
     self.client.login(username=u2.username, password='******')
     response = get(self.client, 'flagit.queue')
     eq_(200, response.status_code)
     doc = pq(response.content)
     eq_(1, len(doc('#flagged-queue li')))
    def test_edit_post(self):
        """Changing post content works."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        d = document(save=True)
        t = thread(document=d, save=True)
        p = t.new_post(creator=u, content='foo')
        post(self.client, 'wiki.discuss.edit_post',
             {'content': 'Some new content'},
             args=[d.slug, t.id, p.id])
        edited_p = t.post_set.get(pk=p.id)

        eq_('Some new content', edited_p.content)
 def test_flag_kbforum_post(self):
     u = user(save=True)
     t = thread(save=True)
     p = t.new_post(creator=u, content='foo')
     f = FlaggedObject(content_object=p, reason='spam', creator_id=u.id)
     f.save()
     # Make sure flagit queue page works
     u2 = user(save=True)
     add_permission(u2, FlaggedObject, 'can_moderate')
     self.client.login(username=u2.username, password='******')
     response = get(self.client, 'flagit.queue')
     eq_(200, response.status_code)
     doc = pq(response.content)
     eq_(1, len(doc('#flagged-queue li')))
Exemple #41
0
    def test_empty_reply_errors(self):
        """Posting an empty reply shows errors."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        d = document(save=True)
        t = thread(document=d, save=True)
        response = post(self.client,
                        'wiki.discuss.reply', {'content': ''},
                        args=[d.slug, t.id])

        doc = pq(response.content)
        error_msg = doc('ul.errorlist li a')[0]
        eq_(error_msg.text, 'Please provide a message.')
Exemple #42
0
    def test_last_post_updated(self):
        """Adding/Deleting the last post in a thread should
        update the last_post field
        """
        t = thread(save=True)
        u = user(save=True)

        # add a new post, then check that last_post is updated
        new_post = t.new_post(creator=u, content="test")
        eq_(t.last_post.id, new_post.id)

        # delete the new post, then check that last_post is updated
        new_post.delete()
        self.assertIsNone(t.last_post.id)
Exemple #43
0
    def test_last_post_updated(self):
        """Adding/Deleting the last post in a thread should
        update the last_post field
        """
        t = thread(save=True)
        u = user(save=True)

        # add a new post, then check that last_post is updated
        new_post = t.new_post(creator=u, content="test")
        eq_(t.last_post.id, new_post.id)

        # delete the new post, then check that last_post is updated
        new_post.delete()
        self.assertIsNone(t.last_post.id)
Exemple #44
0
    def test_edit_thread(self):
        """Changing thread title works."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        d = document(save=True)
        t = thread(title='Sticky Thread', document=d, creator=u, save=True)
        post(self.client,
             'wiki.discuss.edit_thread', {'title': 'A new title'},
             args=[d.slug, t.id])
        edited_t = d.thread_set.get(pk=t.id)

        eq_('Sticky Thread', t.title)
        eq_('A new title', edited_t.title)
    def test_autowatch_reply(self, get_current):
        get_current.return_value.domain = 'testserver'

        u = user(save=True)
        t1 = thread(is_locked=False, save=True)
        t2 = thread(is_locked=False, save=True)
        assert not NewPostEvent.is_notifying(u, t1)
        assert not NewPostEvent.is_notifying(u, t2)

        self.client.login(username=u.username, password='******')
        s = Setting.objects.create(user=u,
                                   name='kbforums_watch_after_reply',
                                   value='True')
        data = {'content': 'some content'}
        post(self.client, 'wiki.discuss.reply', data,
             args=[t1.document.slug, t1.pk])
        assert NewPostEvent.is_notifying(u, t1)

        s.value = 'False'
        s.save()
        post(self.client, 'wiki.discuss.reply', data,
             args=[t2.document.slug, t2.pk])
        assert not NewPostEvent.is_notifying(u, t2)
Exemple #46
0
    def test_edit_post(self):
        """Changing post content works."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        d = document(save=True)
        t = thread(document=d, save=True)
        p = t.new_post(creator=u, content='foo')
        post(self.client,
             'wiki.discuss.edit_post', {'content': 'Some new content'},
             args=[d.slug, t.id, p.id])
        edited_p = t.post_set.get(pk=p.id)

        eq_('Some new content', edited_p.content)
Exemple #47
0
    def test_watch_thread(self):
        """Watch then unwatch a thread."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        t = thread(save=True)
        post(self.client, 'wiki.discuss.watch_thread', {'watch': 'yes'},
             args=[t.document.slug, t.id])
        assert NewPostEvent.is_notifying(u, t)
        # NewThreadEvent is not notifying.
        assert not NewThreadEvent.is_notifying(u, t.document)

        post(self.client, 'wiki.discuss.watch_thread', {'watch': 'no'},
             args=[t.document.slug, t.id])
        assert not NewPostEvent.is_notifying(u, t)
    def test_edit_thread_errors(self):
        """Editing thread with too short of a title shows errors."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        d = document(save=True)
        t = thread(document=d, creator=u, save=True)
        response = post(self.client, 'wiki.discuss.edit_thread',
                        {'title': 'wha?'}, args=[d.slug, t.id])

        doc = pq(response.content)
        errors = doc('ul.errorlist li a')
        eq_(errors[0].text,
            'Your title is too short (4 characters). ' +
            'It must be at least 5 characters.')
    def test_watch_forum_then_new_post(self, get_current):
        """Watching a forum and replying to a thread should send email."""
        get_current.return_value.domain = "testserver"

        u = user(save=True)
        d = document(title="an article title", save=True)
        f = self._toggle_watch_kbforum_as(u.username, d, turn_on=True)
        t = thread(title="Sticky Thread", document=d, save=True)
        u2 = user(username="******", save=True)
        self.client.login(username=u2.username, password="******")
        post(self.client, "wiki.discuss.reply", {"content": "a post"}, args=[f.slug, t.id])

        p = Post.objects.all().order_by("-id")[0]
        attrs_eq(mail.outbox[0], to=[u.email], subject="Re: an article title - Sticky Thread")
        starts_with(mail.outbox[0].body, REPLY_EMAIL % (d.slug, t.id, p.id))
Exemple #50
0
    def test_watch_thread(self):
        """Watch and unwatch a thread."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        t = thread(save=True)
        response = post(self.client,
                        'wiki.discuss.watch_thread', {'watch': 'yes'},
                        args=[t.document.slug, t.id])
        self.assertContains(response, 'Stop')

        response = post(self.client,
                        'wiki.discuss.watch_thread', {'watch': 'no'},
                        args=[t.document.slug, t.id])
        self.assertNotContains(response, 'Stop')
    def test_preview_reply(self):
        """Preview a reply."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        d = document(save=True)
        t = thread(document=d, save=True)
        num_posts = t.post_set.count()
        content = 'Full of awesome.'
        response = post(self.client, 'wiki.discuss.reply',
                        {'content': content, 'preview': 'any string'},
                        args=[d.slug, t.id])
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_(content, doc('#post-preview div.content').text())
        eq_(num_posts, t.post_set.count())
Exemple #52
0
    def test_edit_thread_errors(self):
        """Editing thread with too short of a title shows errors."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        d = document(save=True)
        t = thread(document=d, creator=u, save=True)
        response = post(self.client,
                        'wiki.discuss.edit_thread', {'title': 'wha?'},
                        args=[d.slug, t.id])

        doc = pq(response.content)
        errors = doc('ul.errorlist li a')
        eq_(
            errors[0].text, 'Your title is too short (4 characters). ' +
            'It must be at least 5 characters.')
    def test_edit_post_errors(self):
        """Changing post content works."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        t = thread(creator=u, is_locked=False, save=True)
        p = t.new_post(creator=u, content='foo')
        response = post(self.client, 'wiki.discuss.edit_post',
                        {'content': 'wha?'},
                        args=[t.document.slug, t.id, p.id])

        doc = pq(response.content)
        errors = doc('ul.errorlist li a')
        eq_(errors[0].text,
            'Your message is too short (4 characters). ' +
            'It must be at least 5 characters.')
Exemple #54
0
    def test_edit_post_errors(self):
        """Changing post content works."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        t = thread(creator=u, is_locked=False, save=True)
        p = t.new_post(creator=u, content='foo')
        response = post(self.client,
                        'wiki.discuss.edit_post', {'content': 'wha?'},
                        args=[t.document.slug, t.id, p.id])

        doc = pq(response.content)
        errors = doc('ul.errorlist li a')
        eq_(
            errors[0].text, 'Your message is too short (4 characters). ' +
            'It must be at least 5 characters.')
Exemple #55
0
    def test_edit_thread_moderator(self):
        """Editing post as a moderator works."""
        u = user(save=True)
        add_permission(u, Thread, 'change_thread')
        t = thread(title='Sticky Thread', save=True)
        d = t.document
        self.client.login(username=u.username, password='******')

        eq_('Sticky Thread', t.title)

        r = post(self.client, 'wiki.discuss.edit_thread',
                 {'title': 'new title'}, args=[d.slug, t.id])
        eq_(200, r.status_code)

        edited_t = Thread.objects.get(pk=t.id)
        eq_('new title', edited_t.title)
Exemple #56
0
    def test_edit_thread_moderator(self):
        """Editing post as a moderator works."""
        u = user(save=True)
        add_permission(u, Thread, 'change_thread')
        t = thread(title='Sticky Thread', save=True)
        d = t.document
        self.client.login(username=u.username, password='******')

        eq_('Sticky Thread', t.title)

        r = post(self.client,
                 'wiki.discuss.edit_thread', {'title': 'new title'},
                 args=[d.slug, t.id])
        eq_(200, r.status_code)

        edited_t = Thread.uncached.get(pk=t.id)
        eq_('new title', edited_t.title)
Exemple #57
0
    def test_watch_thread(self):
        """Watch then unwatch a thread."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        t = thread(save=True)
        post(self.client,
             'wiki.discuss.watch_thread', {'watch': 'yes'},
             args=[t.document.slug, t.id])
        assert NewPostEvent.is_notifying(u, t)
        # NewThreadEvent is not notifying.
        assert not NewThreadEvent.is_notifying(u, t.document)

        post(self.client,
             'wiki.discuss.watch_thread', {'watch': 'no'},
             args=[t.document.slug, t.id])
        assert not NewPostEvent.is_notifying(u, t)
    def test_watch_forum_then_new_post(self, get_current):
        """Watching a forum and replying to a thread should send email."""
        get_current.return_value.domain = 'testserver'

        u = user(save=True)
        d = document(title='an article title', save=True)
        f = self._toggle_watch_kbforum_as(u.username, d, turn_on=True)
        t = thread(title='Sticky Thread', document=d, save=True)
        u2 = user(username='******', save=True)
        self.client.login(username=u2.username, password='******')
        post(self.client, 'wiki.discuss.reply', {'content': 'a post'},
             args=[f.slug, t.id])

        p = Post.objects.all().order_by('-id')[0]
        attrs_eq(mail.outbox[0], to=[u.email],
                 subject='Re: an article title - Sticky Thread')
        starts_with(mail.outbox[0].body, REPLY_EMAIL % (d.slug, t.id, p.id))
    def test_watch_thread_then_reply(self, get_current):
        """The event fires and sends emails when watching a thread."""
        get_current.return_value.domain = 'testserver'
        u = user(username='******', save=True)
        u_b = user(username='******', save=True)
        d = document(title='an article title', save=True)
        _t = thread(title='Sticky Thread', document=d, is_sticky=True,
                    save=True)
        t = self._toggle_watch_thread_as(u_b.username, _t, turn_on=True)
        self.client.login(username=u.username, password='******')
        post(self.client, 'wiki.discuss.reply', {'content': 'a post'},
             args=[t.document.slug, t.id])

        p = Post.objects.all().order_by('-id')[0]
        attrs_eq(mail.outbox[0], to=[u_b.email],
                 subject='Re: an article title - Sticky Thread')
        starts_with(mail.outbox[0].body, REPLY_EMAIL % (d.slug, t.id, p.id))

        self._toggle_watch_thread_as(u_b.username, _t, turn_on=False)