def test_delete_post_belongs_to_thread_and_forum(self): # Delete post action - post belongs to thread and thread # belongs to forum. f = forum(save=True) t = thread(forum=f, save=True) # Post belongs to a different forum and thread. p = forum_post(save=True) u = p.author # Give the user the permission to delete posts. g = group(save=True) ct = ContentType.objects.get_for_model(f) permission(codename='forums_forum.post_delete_forum', content_type=ct, object_id=p.thread.forum_id, group=g, save=True) permission(codename='forums_forum.post_delete_forum', content_type=ct, object_id=f.id, group=g, save=True) g.user_set.add(u) self.client.login(username=u.username, password='******') # Post isn't in the passed forum: r = get(self.client, 'forums.delete_post', args=[f.slug, p.thread.id, p.id]) eq_(404, r.status_code) # Post isn't in the passed thread: r = get(self.client, 'forums.delete_post', args=[p.thread.forum.slug, t.id, p.id]) eq_(404, r.status_code)
def test_delete_post_belongs_to_thread_and_document(self): """ Delete post action - post belongs to thread and thread belongs to forum. """ r = get(self.client, 'wiki.discuss.delete_post', args=[self.doc_2.slug, self.thread.id, self.post.id]) eq_(404, r.status_code) r = get(self.client, 'wiki.discuss.delete_post', args=[self.doc.slug, self.thread_2.id, self.post.id]) eq_(404, r.status_code)
def test_mods_can_see_spam_details(self): self.question.is_spam = True self.question.save() res = get(self.client, 'questions.details', args=[self.question.id]) eq_(404, res.status_code) u = user(save=True) add_permission(u, FlaggedObject, 'can_moderate') self.client.login(username=u.username, password='******') res = get(self.client, 'questions.details', args=[self.question.id]) eq_(200, res.status_code)
def test_num_replies(self): """Verify the number of replies label.""" t = ThreadFactory() response = get(self.client, 'forums.posts', args=[t.forum.slug, t.id]) eq_(200, response.status_code) assert '0 Replies' in response.content PostFactory(thread=t) PostFactory(thread=t) response = get(self.client, 'forums.posts', args=[t.forum.slug, t.id]) eq_(200, response.status_code) assert '2 Replies' in response.content
def test_num_replies(self): """Verify the number of replies label.""" t = forum_post(save=True).thread response = get(self.client, 'forums.posts', args=[t.forum.slug, t.id]) eq_(200, response.status_code) assert '0 Replies' in response.content forum_post(thread=t, save=True) forum_post(thread=t, save=True) response = get(self.client, 'forums.posts', args=[t.forum.slug, t.id]) eq_(200, response.status_code) assert '2 Replies' in response.content
def test_read_without_permission(self): """Listing posts without the view_in_forum permission should 404.""" rforum = restricted_forum() t = thread(forum=rforum, save=True) response = get(self.client, 'forums.posts', args=[t.forum.slug, t.id]) eq_(404, response.status_code)
def test_canonical_url(self): """Verify the canonical URL is set correctly.""" f = forum(save=True) response = get(self.client, 'forums.threads', args=[f.slug]) eq_('/forums/%s' % f.slug, pq(response.content)('link[rel="canonical"]')[0].attrib['href'])
def test_modal_locale_selected(self): """Locale value is selected for upload modal.""" response = get(self.client, 'gallery.gallery', args=['image'], locale='fr') doc = pq(response.content) eq_('fr', doc('#gallery-upload-image option[selected="selected"]').val())
def test_read_without_permission(self): """Listing posts without the view_in_forum permission should 404.""" rforum = RestrictedForumFactory() t = ThreadFactory(forum=rforum) response = get(self.client, 'forums.posts', args=[t.forum.slug, t.id]) eq_(404, response.status_code)
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_canonical_url(self): """Verify the canonical URL is set correctly.""" f = ForumFactory() response = get(self.client, 'forums.threads', args=[f.slug]) eq_('%s/en-US/forums/%s' % (settings.CANONICAL_URL, f.slug), pq(response.content)('link[rel="canonical"]')[0].attrib['href'])
def test_account_category_anon(self): """Verify the account category page with unauth'd user.""" self.client.logout() response = get(self.client, "questions.marketplace_aaq_category", args=["account"]) eq_(200, response.status_code) doc = pq(response.content) # One extra form field (email) in this case. eq_(5, len(doc("#question-form li")))
def test_payments_category(self): """Verify the payments category page.""" response = get(self.client, 'questions.marketplace_aaq_category', args=['payments']) eq_(200, response.status_code) doc = pq(response.content) assert 'Paypal Help Center' in doc('div.inner-wrap').text()
def test_show_new_thread(self): """'Post new thread' shows if user has permission to post.""" f = forum(save=True) u = user(save=True) self.client.login(username=u.username, password='******') response = get(self.client, 'forums.threads', args=[f.slug]) self.assertContains(response, 'Post a new thread')
def test_show_reply_fields(self): """Reply fields show if user has permission to post.""" t = forum_post(save=True).thread u = user(save=True) self.client.login(username=u.username, password='******') response = get(self.client, 'forums.posts', args=[t.forum.slug, t.pk]) self.assertContains(response, 'thread-reply')
def test_delete_thread_403(self): """Deleting a thread without permissions returns 403.""" t = ThreadFactory() u = UserFactory() self.client.login(username=u.username, password='******') response = get(self.client, 'forums.delete_thread', args=[t.forum.slug, t.id]) eq_(403, response.status_code)
def test_image_draft_shows(self): """The image draft is loaded for this user.""" image(is_draft=True, creator=self.u) response = get(self.client, 'gallery.gallery', args=['image']) eq_(200, response.status_code) doc = pq(response.content) assert doc('.file.preview img').attr('src').endswith('098f6b.jpg') eq_(1, doc('.file.preview img').length)
def test_video_draft_shows(self): """The video draft is loaded for this user.""" video(is_draft=True, creator=self.u) response = get(self.client, 'gallery.gallery', args=['image']) eq_(200, response.status_code) doc = pq(response.content) # Preview for all 3 video formats: flv, ogv, webm eq_(3, doc('#gallery-upload-video .preview input').length)
def test_sticky_thread_405(self): """Marking a thread sticky with a HTTP GET returns 405.""" t = ThreadFactory() u = UserFactory() self.client.login(username=u.username, password='******') response = get(self.client, 'forums.sticky_thread', args=[t.forum.slug, t.id]) eq_(405, response.status_code)
def test_reply_thread_405(self): """Replying to a thread via a GET instead of a POST request.""" t = ThreadFactory() u = UserFactory() self.client.login(username=u.username, password='******') response = get(self.client, 'forums.reply', args=[t.forum.slug, t.id]) eq_(405, response.status_code)
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 test_watch_GET_405(self): """Watch forum with HTTP GET results in 405.""" f = ForumFactory() u = UserFactory() self.client.login(username=u.username, password='******') response = get(self.client, 'forums.watch_forum', args=[f.id]) eq_(405, response.status_code)
def test_read_without_permission(self): """Listing threads without the view_in_forum permission should 404. """ rforum = restricted_forum() response = get(self.client, 'forums.threads', args=[rforum.slug]) eq_(404, response.status_code)
def test_account_category(self): """Verify the account category page.""" response = get(self.client, 'questions.marketplace_aaq_category', args=['account']) eq_(200, response.status_code) doc = pq(response.content) eq_(4, len(doc('#question-form li')))
def test_weird_list_troubleshooting_info(self): """Test the corner case in which 'modifiedPReferences' is in a list in troubleshooting data. This is weird, but caused a bug.""" q = question(save=True) q.add_metadata(troubleshooting='["modifiedPreferences"]') # This case should not raise an error. response = get(self.client, 'questions.details', args=[q.id]) eq_(200, response.status_code)
def test_links_nofollow(self): """Links posted should have rel=nofollow.""" p = forum_post(content='linking http://test.org', save=True) t = p.thread f = t.forum response = get(self.client, 'forums.posts', args=[f.slug, t.pk]) doc = pq(response.content) eq_('nofollow', doc('ol.posts div.content a')[0].attrib['rel'])
def test_edit_locked_thread_403(self): """Editing a locked thread returns 403.""" locked = ThreadFactory(is_locked=True) u = locked.creator PostFactory(thread=locked, author=u) self.client.login(username=u.username, password='******') response = get(self.client, 'forums.edit_thread', args=[locked.forum.slug, locked.id]) eq_(403, response.status_code)
def test_delete_post_belongs_to_thread_and_document(self): """ Delete post action - post belongs to thread and thread belongs to forum. """ r = get( self.client, "wiki.discuss.delete_post", args=[self.doc_2.slug, self.thread.id, self.post.id], ) eq_(404, r.status_code) r = get( self.client, "wiki.discuss.delete_post", args=[self.doc.slug, self.thread_2.id, self.post.id], ) eq_(404, r.status_code)
def test_posts_fr(self): """Posts render for [fr] locale.""" t = forum_post(save=True).thread response = get(self.client, 'forums.posts', args=[t.forum.slug, t.id], locale='fr') eq_(200, response.status_code) eq_('/forums/{f}/{t}'.format(f=t.forum.slug, t=t.id), pq(response.content)('link[rel="canonical"]')[0].attrib['href'])
def test_long_title_truncated_in_crumbs(self): """A very long thread title gets truncated in the breadcrumbs""" t = thread(title='A thread with a very very long title', save=True) forum_post(thread=t, save=True) response = get(self.client, 'forums.posts', args=[t.forum.slug, t.id]) doc = pq(response.content) crumb = doc('#breadcrumbs li:last-child') eq_(crumb.text(), 'A thread with a very very ...')
def test_post_delete_403(self): """Deleting a post without permissions returns 403.""" p = PostFactory() t = p.thread u = UserFactory() self.client.login(username=u.username, password='******') response = get(self.client, 'forums.delete_post', args=[t.forum.slug, t.id, p.id]) eq_(403, response.status_code)
def test_last_post_link_has_post_id(self): """Make sure the last post url links to the last post (#post-<id>). """ p = PostFactory() response = get(self.client, "forums.forums") doc = pq(response.content) last_post_link = doc(".forums .last-post a:not(.username)")[0] href = last_post_link.attrib["href"] eq_(href.split("#")[1], "post-%s" % p.id)
def test_restricted_is_invisible(self): """Forums with restricted view_in permission shouldn't show up.""" restricted_forum = ForumFactory() # Make it restricted. ct = ContentType.objects.get_for_model(restricted_forum) PermissionFactory(codename='forums_forum.view_in_forum', content_type=ct, object_id=restricted_forum.id) response = get(self.client, 'forums.forums') self.assertNotContains(response, restricted_forum.slug)
def test_multi_feed_titling(self): """Ensure that titles are being applied properly to feeds.""" t = thread(save=True) forum = t.forum post(thread=t, save=True) response = get(self.client, 'forums.threads', args=[forum.slug]) doc = pq(response.content) eq_(ThreadsFeed().title(forum), doc('link[type="application/atom+xml"]')[0].attrib['title'])
def test_sticky_thread_405(self): """Marking a thread sticky with a HTTP GET returns 405.""" t = forum_post(save=True).thread u = user(save=True) self.client.login(username=u.username, password='******') response = get(self.client, 'forums.sticky_thread', args=[t.forum.slug, t.id]) eq_(405, response.status_code)
def test_move_thread_405(self): """Moving a thread via a GET instead of a POST request.""" t = ThreadFactory() u = UserFactory() self.client.login(username=u.username, password="******") response = get(self.client, "forums.move_thread", args=[t.forum.slug, t.id]) eq_(405, response.status_code)
def test_edit_thread_template(self): """The edit-thread template should render.""" t = ThreadFactory() creator = t.creator self.client.login(username=creator.username, password="******") res = get(self.client, "forums.edit_thread", args=[t.forum.slug, t.id]) doc = pq(res.content) eq_(len(doc("form.edit-thread")), 1)
def test_display_order(self): """Verify the display_order is respected.""" forum1 = forum(display_order=1, save=True) forum2 = forum(display_order=2, save=True) # forum1 should be listed first r = get(self.client, 'forums.forums') eq_(200, r.status_code) doc = pq(r.content) eq_(forum1.name, doc('ol.forums > li a:first').text()) forum1.display_order = 3 forum1.save() # forum2 should be listed first r = get(self.client, 'forums.forums') eq_(200, r.status_code) doc = pq(r.content) eq_(forum2.name, doc('ol.forums > li a:first').text())
def test_last_post_link_has_post_id(self): """Make sure the last post url links to the last post (#post-<id>). """ p = forum_post(save=True) response = get(self.client, 'forums.forums') doc = pq(response.content) last_post_link = doc('ol.forums div.last-post a:not(.username)')[0] href = last_post_link.attrib['href'] eq_(href.split('#')[1], 'post-%s' % p.id)
def test_posts_fr(self): """Posts render for [fr] locale.""" t = ThreadFactory() response = get(self.client, "forums.posts", args=[t.forum.slug, t.id], locale="fr") eq_(200, response.status_code) eq_( "{c}/fr/forums/{f}/{t}".format(c=settings.CANONICAL_URL, f=t.forum.slug, t=t.id), pq(response.content)('link[rel="canonical"]')[0].attrib["href"], )
def test_edit_thread_403(self): """Editing a thread without permissions returns 403.""" t = ThreadFactory() u = UserFactory() self.client.login(username=u.username, password='******') response = get(self.client, 'forums.edit_thread', args=[t.forum.slug, t.id]) eq_(403, response.status_code)
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 test_delete_thread_403(self): """Deleting a thread without permissions returns 403.""" t = forum_post(save=True).thread u = user(save=True) self.client.login(username=u.username, password='******') response = get(self.client, 'forums.delete_thread', args=[t.forum.slug, t.id]) eq_(403, response.status_code)
def test_move_thread_405(self): """Moving a thread via a GET instead of a POST request.""" t = forum_post(save=True).thread u = user(save=True) self.client.login(username=u.username, password='******') response = get(self.client, 'forums.move_thread', args=[t.forum.slug, t.id]) eq_(405, response.status_code)
def test_sticky_thread_405(self): """Marking a thread sticky with a HTTP GET returns 405.""" t = ThreadFactory() u = UserFactory() self.client.login(username=u.username, password="******") response = get(self.client, "forums.sticky_thread", args=[t.forum.slug, t.id]) eq_(405, response.status_code)
def test_edit_thread_template(self): """The edit-post template should render.""" p = PostFactory() u = p.author self.client.login(username=u.username, password="******") res = get(self.client, "forums.edit_post", args=[p.thread.forum.slug, p.thread.id, p.id],) doc = pq(res.content) eq_(len(doc("form.edit-post")), 1)
def test_last_thread_post_link_has_post_id(self): """Make sure the last post url links to the last post (#post-<id>).""" t = ThreadFactory() last = PostFactory(thread=t) response = get(self.client, "forums.threads", args=[t.forum.slug]) doc = pq(response.content) last_post_link = doc(".threads .last-post a:not(.username)")[0] href = last_post_link.attrib["href"] eq_(href.split("#")[1], "post-%s" % last.id)
def test_delete_thread_403(self): """Deleting a thread without permissions returns 403.""" t = ThreadFactory() u = UserFactory() self.client.login(username=u.username, password="******") response = get(self.client, "forums.delete_thread", args=[t.forum.slug, t.id]) eq_(403, response.status_code)
def test_locked_thread_405(self): """Marking a thread locked via a GET instead of a POST request.""" t = ThreadFactory() u = UserFactory() self.client.login(username=u.username, password='******') response = get(self.client, 'forums.lock_thread', args=[t.forum.slug, t.id]) eq_(405, response.status_code)
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'])
def test_long_title_truncated_in_crumbs(self): """A very long thread title gets truncated in the breadcrumbs""" t = thread(title='A thread with a very very very very long title', save=True) forum_post(thread=t, save=True) response = get(self.client, 'forums.posts', args=[t.forum.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_account_category_anon(self): """Verify the account category page with unauth'd user.""" self.client.logout() response = get(self.client, 'questions.marketplace_aaq_category', args=['account']) eq_(200, response.status_code) doc = pq(response.content) # One extra form field (email) in this case. eq_(5, len(doc('#question-form li')))
def test_display_order(self): """Verify the display_order is respected.""" forum1 = ForumFactory(display_order=1) forum2 = ForumFactory(display_order=2) # forum1 should be listed first r = get(self.client, "forums.forums") eq_(200, r.status_code) doc = pq(r.content) eq_(forum1.name, doc(".forums tr a").first().text()) forum1.display_order = 3 forum1.save() # forum2 should be listed first r = get(self.client, "forums.forums") eq_(200, r.status_code) doc = pq(r.content) eq_(forum2.name, doc(".forums tr a").first().text())
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_delete_no_session(self): """Delete a thread while logged out redirects.""" r = get(self.client, 'wiki.discuss.delete_thread', kwargs={ 'document_slug': 'article-title', 'thread_id': 1 }) assert (settings.LOGIN_URL in r.redirect_chain[0][0]) eq_(302, r.redirect_chain[0][1])
def test_delete_no_session(self): """Delete a thread while logged out redirects.""" r = get(self.client, 'forums.delete_thread', kwargs={ 'forum_slug': 'test-forum', 'thread_id': 1 }) assert (settings.LOGIN_URL in r.redirect_chain[0][0]) eq_(302, r.redirect_chain[0][1])
def test_edit_thread_template(self): """The edit-thread template should render.""" t = forum_post(save=True).thread creator = t.creator self.client.login(username=creator.username, password='******') res = get(self.client, 'forums.edit_thread', args=[t.forum.slug, t.id]) doc = pq(res.content) eq_(len(doc('form.edit-thread')), 1)