def test_autowatch_reply(self, get_current): get_current.return_value.domain = 'testserver' u = UserFactory() t1 = ThreadFactory(is_locked=False) t2 = ThreadFactory(is_locked=False) 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)
def test_autowatch_reply(self, get_current): get_current.return_value.domain = "testserver" u = UserFactory() t1 = ThreadFactory(is_locked=False) t2 = ThreadFactory(is_locked=False) 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)
def test_threads_sort(self): """Ensure that threads are being sorted properly by date/time.""" d = DocumentFactory() t = ThreadFactory(document=d) t.new_post(creator=t.creator, content='foo') time.sleep(1) t2 = ThreadFactory(document=d) t2.new_post(creator=t2.creator, content='foo') given_ = ThreadsFeed().items(d)[0].id eq_(t2.id, given_)
def setUp(self): super(KBBelongsTestCase, self).setUp() u = UserFactory() self.doc = DocumentFactory(title='spam') self.doc_2 = DocumentFactory(title='eggs') self.thread = ThreadFactory(creator=u, document=self.doc, is_locked=False) self.thread_2 = ThreadFactory(creator=u, document=self.doc_2, is_locked=False) 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='******')
def test_watch_other_thread_then_reply(self): """Watching a different thread than the one we're replying to shouldn't notify.""" u_b = UserFactory(username='******') _t = ThreadFactory() self._toggle_watch_thread_as(u_b.username, _t, turn_on=True) u = UserFactory() t2 = ThreadFactory() 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_edit_locked_thread_403(self): """Editing a locked thread returns 403.""" t = ThreadFactory(document=self.doc, creator=self.u, is_locked=True) response = get(self.client, 'wiki.discuss.edit_thread', args=[self.doc.slug, t.id]) eq_(403, response.status_code)
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 = UserFactory(username="******") u_b = UserFactory(username="******") d = DocumentFactory(title="an article title") _t = ThreadFactory(title="Sticky Thread", document=d, is_sticky=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 % { "user": u.profile.name, "document_slug": d.slug, "thread_id": t.id, "post_id": p.id, }, ) self._toggle_watch_thread_as(u_b.username, _t, turn_on=False)
def test_watch_both_then_new_post(self, get_current): """Watching both and replying to a thread should send ONE email.""" get_current.return_value.domain = 'testserver' u = UserFactory() d = DocumentFactory(title='an article title') f = self._toggle_watch_kbforum_as(u.username, d, turn_on=True) t = ThreadFactory(title='Sticky Thread', document=d) self._toggle_watch_thread_as(u.username, t, turn_on=True) u2 = UserFactory(username='******') self.client.login(username=u2.username, password='******') post(self.client, 'wiki.discuss.reply', {'content': 'a post'}, args=[f.slug, t.id]) 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 % { 'user': u2.profile.name, 'document_slug': d.slug, 'thread_id': t.id, 'post_id': p.id, }) self._toggle_watch_kbforum_as(u.username, d, turn_on=False) self._toggle_watch_thread_as(u.username, t, turn_on=False)
def test_watch_both_then_new_post(self, get_current): """Watching both and replying to a thread should send ONE email.""" get_current.return_value.domain = "testserver" u = UserFactory() d = DocumentFactory(title="an article title") f = self._toggle_watch_kbforum_as(u.username, d, turn_on=True) t = ThreadFactory(title="Sticky Thread", document=d) self._toggle_watch_thread_as(u.username, t, turn_on=True) u2 = UserFactory(username="******") self.client.login(username=u2.username, password="******") post(self.client, "wiki.discuss.reply", {"content": "a post"}, args=[f.slug, t.id]) 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 % { "user": u2.profile.name, "document_slug": d.slug, "thread_id": t.id, "post_id": p.id, }, ) self._toggle_watch_kbforum_as(u.username, d, turn_on=False) self._toggle_watch_thread_as(u.username, t, turn_on=False)
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 = UserFactory() _d = DocumentFactory(title="an article title") d = self._toggle_watch_kbforum_as(u.username, _d, turn_on=True) t = ThreadFactory(title="Sticky Thread", document=d) 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 = UserFactory(username="******") 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 % { "user": u2.profile.name, "document_slug": d.slug, "thread_id": t.id, "post_id": p.id, }, )
def test_locale_discussions_ignores_sticky(self): """Sticky flag is ignored in locale discussions view""" u = UserFactory() d = DocumentFactory() t = ThreadFactory(title="Sticky Thread", is_sticky=True, document=d) t.new_post(creator=u, content="foo") t2 = ThreadFactory(title="A thread with a very very long", is_sticky=False, document=d) 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(".threads .title a:first").text() assert title.startswith("A thread with a very very long")
def setUp(self): super(KBSaveDateTestCase, self).setUp() self.user = UserFactory() self.doc = DocumentFactory() self.thread = ThreadFactory( created=datetime.datetime(2010, 1, 12, 9, 48, 23))
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 = UserFactory() _d = DocumentFactory(title='an article title') d = self._toggle_watch_kbforum_as(u.username, _d, turn_on=True) t = ThreadFactory(title='Sticky Thread', document=d) 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 = UserFactory(username='******') 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 % { 'user': u2.profile.name, 'document_slug': d.slug, 'thread_id': t.id, 'post_id': p.id, })
def test_delete_last_and_only_post_in_thread(self): """Deleting the only post in a thread should delete the thread""" t = ThreadFactory(title="test") 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())
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 = UserFactory(username='******') u_b = UserFactory(username='******') d = DocumentFactory(title='an article title') _t = ThreadFactory(title='Sticky Thread', document=d, is_sticky=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 % { 'user': u.profile.name, 'document_slug': d.slug, 'thread_id': t.id, 'post_id': p.id, }) self._toggle_watch_thread_as(u_b.username, _t, turn_on=False)
def test_posts_sort(self): """Ensure that posts are being sorted properly by date/time.""" t = ThreadFactory() 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_)
def test_links_nofollow(self): """Links posted should have rel=nofollow.""" u = UserFactory() t = ThreadFactory() 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"])
def test_post_absolute_url(self): t = ThreadFactory() 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_long_title_truncated_in_crumbs(self): """A very long thread title gets truncated in the breadcrumbs""" d = DocumentFactory() t = ThreadFactory(title='A thread with a very very very very very' * 5, document=d) 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 setUp(self): super(KBBelongsTestCase, self).setUp() u = UserFactory() self.doc = DocumentFactory(title="spam") self.doc_2 = DocumentFactory(title="eggs") self.thread = ThreadFactory(creator=u, document=self.doc, is_locked=False) self.thread_2 = ThreadFactory(creator=u, document=self.doc_2, is_locked=False) 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="******")
def test_locale_discussions_ignores_sticky(self): """Sticky flag is ignored in locale discussions view""" u = UserFactory() d = DocumentFactory() t = ThreadFactory(title='Sticky Thread', is_sticky=True, document=d) t.new_post(creator=u, content='foo') t2 = ThreadFactory(title='A thread with a very very long', is_sticky=False, document=d) 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_links_nofollow(self): """Links posted should have rel=nofollow.""" u = UserFactory() t = ThreadFactory() 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'])
def test_edit_thread_template(self): """The edit-thread template should render.""" u = UserFactory() self.client.login(username=u.username, password="******") t = ThreadFactory(creator=u, is_locked=False) 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 setUp(self): super(ThreadPermissionsTests, self).setUp() self.doc = DocumentFactory() self.u = UserFactory() self.thread = ThreadFactory(document=self.doc, creator=self.u) self.post = self.thread.new_post(creator=self.thread.creator, content='foo') # Login for testing 403s u2 = UserFactory() self.client.login(username=u2.username, password='******')
def test_fire_on_reply(self, fire): """The event fires when there is a reply.""" t = ThreadFactory() u = UserFactory() 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_empty_reply_errors(self): """Posting an empty reply shows errors.""" u = UserFactory() self.client.login(username=u.username, password="******") d = DocumentFactory() t = ThreadFactory(document=d) 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_last_thread_post_link_has_post_id(self): """Make sure the last post url links to the last post (#post-<id>).""" u = UserFactory() t = ThreadFactory() 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("tr.threads td.last-post a:not(.username)")[0] href = last_post_link.attrib["href"] eq_(href.split("#")[1], "post-%d" % p2.id)
def test_last_thread_post_link_has_post_id(self): """Make sure the last post url links to the last post (#post-<id>).""" u = UserFactory() t = ThreadFactory() 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)
def test_edit_thread_template(self): """The edit-post template should render.""" u = UserFactory() self.client.login(username=u.username, password='******') t = ThreadFactory(creator=u, is_locked=False) p = t.new_post(creator=u, content='foo') res = get(self.client, 'wiki.discuss.edit_post', args=[p.thread.document.slug, p.thread.id, p.id]) doc = pq(res.content) eq_(len(doc('form.edit-post')), 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 = UserFactory() d = DocumentFactory(title='an article title') f = self._toggle_watch_kbforum_as(u.username, d, turn_on=True) t = ThreadFactory(document=d) 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