def common_vote(self): """Helper method for question vote tests.""" # Check that there are no votes and vote form renders response = get(self.client, 'questions.answers', args=[self.question.id]) doc = pq(response.content) eq_('0 people', doc('div.have-problem mark')[0].text) eq_(1, len(doc('div.me-too form'))) # Vote post(self.client, 'questions.vote', args=[self.question.id]) # Check that there is 1 vote and vote form doesn't render response = get(self.client, 'questions.answers', args=[self.question.id]) doc = pq(response.content) eq_('1 person', doc('div.have-problem mark')[0].text) eq_(0, len(doc('div.me-too form'))) # Voting again (same user) should not increment vote count post(self.client, 'questions.vote', args=[self.question.id]) response = get(self.client, 'questions.answers', args=[self.question.id]) doc = pq(response.content) eq_('1 person', doc('div.have-problem mark')[0].text)
def common_answer_vote(self): """Helper method for answer vote tests.""" # Check that there are no votes and vote form renders response = get(self.client, 'questions.answers', args=[self.question.id]) doc = pq(response.content) eq_(1, len(doc('form.helpful input[name="helpful"]'))) # Vote ua = 'Mozilla/5.0 (DjangoTestClient)' self.client.post(reverse('questions.answer_vote', args=[self.question.id, self.answer.id]), {'helpful': 'y'}, HTTP_USER_AGENT=ua) # Check that there is 1 vote and vote form doesn't render response = get(self.client, 'questions.answers', args=[self.question.id]) doc = pq(response.content) eq_('1 out of 1 person found this reply helpful', doc('#answer-1 span.helpful')[0].text.strip()) eq_(0, len(doc('form.helpful input[name="helpful"]'))) # Verify user agent vote_meta = VoteMetadata.objects.all()[0] eq_('ua', vote_meta.key) eq_(ua, vote_meta.value) # Voting again (same user) should not increment vote count post(self.client, 'questions.answer_vote', {'helpful': 'y'}, args=[self.question.id, self.answer.id]) doc = pq(response.content) eq_('1 out of 1 person found this reply helpful', doc('#answer-1 span.helpful')[0].text.strip())
def common_answer_vote(self): """Helper method for answer vote tests.""" # Check that there are no votes and vote form renders response = get(self.client, 'questions.answers', args=[self.question.id]) doc = pq(response.content) eq_(1, len(doc('form.helpful input[name="helpful"]'))) # Vote post(self.client, 'questions.answer_vote', {'helpful': 'y'}, args=[self.question.id, self.answer.id]) # Check that there is 1 vote and vote form doesn't render response = get(self.client, 'questions.answers', args=[self.question.id]) doc = pq(response.content) eq_('1 out of 1 person', doc('#answer-1 div.helpful mark')[0].text) eq_(0, len(doc('form.helpful input[name="helpful"]'))) # Voting again (same user) should not increment vote count post(self.client, 'questions.answer_vote', {'helpful': 'y'}, args=[self.question.id, self.answer.id]) doc = pq(response.content) eq_('1 out of 1 person', doc('#answer-1 div.helpful mark')[0].text)
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_top_contributors(self): # There should be no top contributors since there are no solutions. cache_top_contributors() response = get(self.client, 'questions.questions') doc = pq(response.content) eq_(0, len(doc('#top-contributors ol li'))) # Solve a question and verify we now have a top conributor. answer = Answer.objects.all()[0] answer.created = datetime.now() answer.save() answer.question.solution = answer answer.question.save() cache_top_contributors() response = get(self.client, 'questions.questions') doc = pq(response.content) lis = doc('#top-contributors ol li') eq_(1, len(lis)) eq_('pcraciunoiu', lis[0].text) # Make answer 8 days old. There should no be top contributors. answer.created = datetime.now() - timedelta(days=8) answer.save() cache_top_contributors() response = get(self.client, 'questions.questions') doc = pq(response.content) eq_(0, len(doc('#top-contributors ol li')))
def common_vote(self): """Helper method for question vote tests.""" # Check that there are no votes and vote form renders response = get(self.client, 'questions.answers', args=[self.question.id]) doc = pq(response.content) eq_('0 people', doc('div.have-problem mark')[0].text) eq_(1, len(doc('div.me-too form'))) # Vote ua = 'Mozilla/5.0 (DjangoTestClient)' self.client.post(reverse('questions.vote', args=[self.question.id]), {}, HTTP_USER_AGENT=ua) # Check that there is 1 vote and vote form doesn't render response = get(self.client, 'questions.answers', args=[self.question.id]) doc = pq(response.content) eq_('1 person', doc('div.have-problem mark')[0].text) eq_(0, len(doc('div.me-too form'))) # Verify user agent vote_meta = VoteMetadata.objects.all()[0] eq_('ua', vote_meta.key) eq_(ua, vote_meta.value) # Voting again (same user) should not increment vote count post(self.client, 'questions.vote', args=[self.question.id]) response = get(self.client, 'questions.answers', args=[self.question.id]) doc = pq(response.content) eq_('1 person', doc('div.have-problem mark')[0].text)
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_delete_post_belongs_to_thread_and_forum(self): """ Delete post action - post belongs to thread and thread belongs to forum. """ r = get(self.client, 'forums.delete_post', args=[self.forum_2.slug, self.thread.id, self.post.id]) eq_(404, r.status_code) r = get(self.client, 'forums.delete_post', args=[self.forum.slug, self.thread_2.id, self.post.id]) eq_(404, r.status_code)
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_edit_answer_without_permission(self): """Editing an answer without permissions returns a 403. The edit link shouldn't show up on the Answers page.""" response = get(self.client, "questions.answers", args=[self.question.id]) doc = pq(response.content) eq_(0, len(doc("ol.answers li.edit"))) answer = self.question.last_answer response = get(self.client, "questions.edit_answer", args=[self.question.id, answer.id]) eq_(403, response.status_code) content = "New content for answer" response = post(self.client, "questions.edit_answer", {"content": content}, args=[self.question.id, answer.id]) eq_(403, response.status_code)
def test_answer_creator_can_edit(self): """The creator of an answer can edit his/her answer.""" self.client.login(username='******', password='******') # Initially there should be no edit links response = get(self.client, 'questions.answers', args=[self.question.id]) doc = pq(response.content) eq_(0, len(doc('ol.answers a.edit'))) # Add an answer and verify the edit link shows up content = 'lorem ipsum dolor sit amet' response = post(self.client, 'questions.reply', {'content': content}, args=[self.question.id]) doc = pq(response.content) eq_(1, len(doc('ol.answers a.edit'))) new_answer = self.question.answers.order_by('-created')[0] eq_(1, len(doc('#answer-%s a.edit' % new_answer.id))) # Make sure it can be edited content = 'New content for answer' response = post(self.client, 'questions.edit_answer', {'content': content}, args=[self.question.id, new_answer.id]) eq_(200, response.status_code) # Now lock it and make sure it can't be edited self.question.is_locked = True self.question.save() response = post(self.client, 'questions.edit_answer', {'content': content}, args=[self.question.id, new_answer.id]) eq_(403, response.status_code)
def test_watch_solution(self, get_current): """Watch a question for solution.""" self.client.logout() get_current.return_value.domain = "testserver" post(self.client, "questions.watch", {"email": "*****@*****.**", "event_type": "solution"}, args=[self.question.id]) assert QuestionSolvedEvent.is_notifying("*****@*****.**", self.question), "Watch was not created" attrs_eq(mail.outbox[0], to=["*****@*****.**"], subject="Please confirm your email address") assert "questions/confirm/" in mail.outbox[0].body assert "Solution found" in mail.outbox[0].body # Now activate the watch. w = Watch.objects.get() get(self.client, "questions.activate_watch", args=[w.id, w.secret]) assert Watch.objects.get().is_active
def test_answer_creator_can_edit(self): """The creator of an answer can edit his/her answer.""" self.client.login(username="******", password="******") # Initially there should be no edit links response = get(self.client, "questions.answers", args=[self.question.id]) doc = pq(response.content) eq_(0, len(doc("ol.answers li.edit"))) # Add an answer and verify the edit link shows up content = "lorem ipsum dolor sit amet" response = post(self.client, "questions.reply", {"content": content}, args=[self.question.id]) doc = pq(response.content) eq_(1, len(doc("ol.answers li.edit"))) new_answer = self.question.answers.order_by("-created")[0] eq_(1, len(doc("#answer-%s li.edit" % new_answer.id))) # Make sure it can be edited content = "New content for answer" response = post( self.client, "questions.edit_answer", {"content": content}, args=[self.question.id, new_answer.id] ) eq_(200, response.status_code) # Now lock it and make sure it can't be edited self.question.is_locked = True self.question.save() response = post( self.client, "questions.edit_answer", {"content": content}, args=[self.question.id, new_answer.id] ) eq_(403, response.status_code)
def test_delete_question_without_permissions(self): """Deleting a question without permissions is a 403.""" self.client.login(username="******", password="******") response = get(self.client, "questions.delete", args=[self.question.id]) eq_(403, response.status_code) response = post(self.client, "questions.delete", args=[self.question.id]) eq_(403, response.status_code)
def test_watch_GET_405(self): """Watch KB forum with HTTP GET results in 405.""" self.client.login(username='******', password='******') doc = Document.objects.filter()[0] response = get(self.client, 'wiki.discuss.watch_forum', args=[doc.slug]) eq_(405, response.status_code)
def test_contributed_badge(self): # pcraciunoiu should have a contributor badge on question 1 but not 2 self.client.login(username='******', password="******") response = get(self.client, 'questions.questions') doc = pq(response.content) eq_(1, len(doc('li#question-1 span.contributed'))) eq_(0, len(doc('li#question-2 span.contributed')))
def test_long_title_truncated_in_crumbs(self): """A very long thread title gets truncated in the breadcrumbs""" d = Document.objects.get(pk=1) response = get(self.client, 'wiki.discuss.posts', args=[d.slug, 4]) doc = pq(response.content) crumb = doc('#breadcrumbs li:last-child') eq_(crumb.text(), 'A thread with a very very ...')
def test_posts_thread_belongs_to_forum(self): """Posts view - redirect if thread does notbelong to forum.""" r = get(self.client, 'forums.posts', args=[self.forum_2.slug, self.thread.id]) eq_(200, r.status_code) u = r.redirect_chain[0][0] assert u.endswith(self.thread.get_absolute_url())
def test_read_without_permission(self): """Listing threads without the view_in_forum permission should 404.""" restricted_forum = _restricted_forum() response = get(self.client, 'forums.threads', args=[restricted_forum.slug]) 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 = 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_read_without_permission(self): """Listing posts without the view_in_forum permission should 404.""" restricted_forum = _restricted_forum() t = thread(forum=restricted_forum, save=True) 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.""" jsocol = User.objects.get(username='******') t = self.forum.thread_set.filter(creator=jsocol, is_locked=True)[0] response = get(self.client, 'forums.edit_thread', args=[self.forum.slug, t.id]) eq_(403, response.status_code)
def test_long_title_truncated_in_crumbs(self): """A very long thread title gets truncated in the breadcrumbs""" forum = Forum.objects.filter()[0] response = get(self.client, 'forums.posts', args=[forum.slug, 4]) doc = pq(response.content) crumb = doc('ol.breadcrumbs li:last-child') eq_(crumb.text(), 'A thread with a very very ...')
def test_last_post_link_has_post_id(self): """Make sure the last post url links to the last post (#post-<id>).""" 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-25')
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_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_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_last_thread_post_link_has_post_id(self): """Make sure the last post url links to the last post (#post-<id>).""" response = get(self.client, 'wiki.discuss.threads', args=['article-title']) 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-4')
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_restricted_is_invisible(self): """Forums with restricted view_in permission shouldn't show up.""" restricted_forum = forum(save=True) # Make it restricted. ct = ContentType.objects.get_for_model(restricted_forum) permission(codename='forums_forum.view_in_forum', content_type=ct, object_id=restricted_forum.id, save=True) response = get(self.client, 'forums.forums') self.assertNotContains(response, restricted_forum.slug)
def test_edit_answer_without_permission(self): """Editing an answer without permissions returns a 403. The edit link shouldn't show up on the Answers page.""" response = get(self.client, 'questions.answers', args=[self.question.id]) doc = pq(response.content) eq_(0, len(doc('ol.answers li.edit'))) answer = self.question.last_answer response = get(self.client, 'questions.edit_answer', args=[self.question.id, answer.id]) eq_(403, response.status_code) content = 'New content for answer' response = post(self.client, 'questions.edit_answer', {'content': content}, args=[self.question.id, answer.id]) eq_(403, response.status_code)
def test_related_list(self): """Test that related Questions appear in the list.""" raise SkipTest question = Question.objects.get(pk=1) response = get(self.client, 'questions.answers', args=[question.id]) doc = pq(response.content) eq_(1, len(doc('ul.related li')))
def test_last_thread_post_link_has_post_id(self): """Make sure the last post url links to the last post (#post-<id>).""" t = forum_post(save=True).thread last = forum_post(thread=t, save=True) response = get(self.client, 'forums.threads', args=[t.forum.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-%s' % last.id)
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)
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_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_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_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_delete_question_with_permissions(self): """Deleting a question with permissions.""" self.client.login(username='******', password='******') response = get(self.client, 'questions.delete', args=[self.question.id]) eq_(200, response.status_code) response = post(self.client, 'questions.delete', args=[self.question.id]) eq_(0, Question.objects.filter(pk=self.question.id).count())
def test_posts_fr(self): """Posts render for [fr] locale.""" forum = Forum.objects.filter()[0] response = get(self.client, 'forums.posts', args=[forum.slug, 4], locale='fr') eq_(200, response.status_code) eq_('/forums/test-forum/4', pq(response.content)('link[rel="canonical"]')[0].attrib['href'])
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_locked_thread_405(self): """Marking a thread locked 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.lock_thread', args=[t.forum.slug, t.id]) eq_(405, response.status_code)
def test_edit_thread_template(self): """The edit-thread template should render.""" self.client.login(username='******', password='******') u = User.objects.get(username='******') t = Thread.objects.filter(creator=u, is_locked=False)[0] 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_delete_answer_without_permissions(self): """Deleting an answer without permissions sends 403.""" self.client.login(username='******', password='******') answer = self.question.last_answer response = get(self.client, 'questions.delete_answer', args=[self.question.id, answer.id]) eq_(403, response.status_code) response = post(self.client, 'questions.delete_answer', args=[self.question.id, answer.id]) eq_(403, response.status_code)
def test_edit_thread_template(self): """The edit-post template should render.""" p = forum_post(save=True) 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_watch_solution(self, get_current): """Watch a question for solution.""" self.client.logout() get_current.return_value.domain = 'testserver' post(self.client, 'questions.watch', {'email': '*****@*****.**', 'event_type': 'solution'}, args=[self.question.id]) assert QuestionSolvedEvent.is_notifying('*****@*****.**', self.question), ( 'Watch was not created') attrs_eq(mail.outbox[0], to=['*****@*****.**'], subject='Please confirm your email address') assert 'questions/confirm/' in mail.outbox[0].body assert 'Solution found' in mail.outbox[0].body # Now activate the watch. w = Watch.objects.get() get(self.client, 'questions.activate_watch', args=[w.id, w.secret]) assert Watch.objects.get().is_active
def test_delete_answer_with_permissions(self): """Deleting an answer with permissions.""" answer = self.question.last_answer self.client.login(username='******', password='******') response = get(self.client, 'questions.delete_answer', args=[self.question.id, answer.id]) eq_(200, response.status_code) response = post(self.client, 'questions.delete_answer', args=[self.question.id, answer.id]) eq_(0, Answer.objects.filter(pk=self.question.id).count())
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_edit_locked_thread_403(self): """Editing a locked thread returns 403.""" locked = thread(is_locked=True, save=True) u = locked.creator forum_post(thread=locked, author=u, save=True) 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_is_listed(self): """Verify is_listed is respected.""" forum1 = forum(is_listed=True, save=True) forum2 = forum(is_listed=True, save=True) # Both forums should be listed. r = get(self.client, 'forums.forums') eq_(200, r.status_code) doc = pq(r.content) eq_(2, len(doc('ol.forums > li'))) forum1.is_listed = False forum1.save() # Only forum2 should be listed. r = get(self.client, 'forums.forums') eq_(200, r.status_code) doc = pq(r.content) eq_(1, len(doc('ol.forums > li'))) eq_(forum2.name, doc('ol.forums > li a').text())
def test_post_edit_403(self): """Editing a post without permissions returns 403.""" p = forum_post(save=True) t = p.thread u = user(save=True) self.client.login(username=u.username, password='******') response = get(self.client, 'forums.edit_post', args=[t.forum.slug, t.id, p.id]) eq_(403, response.status_code)
def test_edit_thread_template(self): """The edit-post template should render.""" self.client.login(username='******', password='******') u = User.objects.get(username='******') p = Post.objects.filter(creator=u, thread__is_locked=False)[0] 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_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()) eq_('fr', doc('#gallery-upload-video option[selected="selected"]').val())
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_delete_question_without_permissions(self): """Deleting a question without permissions is a 403.""" self.client.login(username='******', password='******') response = get(self.client, 'questions.delete', args=[self.question.id]) eq_(403, response.status_code) response = post(self.client, 'questions.delete', args=[self.question.id]) eq_(403, response.status_code)
def test_empty_troubleshooting_info(self): """Test a troubleshooting value that is valid JSON, but junk. This should trigger the parser to return None, which should not cause a 500. """ q = question(save=True) q.add_metadata(troubleshooting='{"foo": "bar"}') # This case should not raise an error. response = get(self.client, 'questions.answers', args=[q.id]) eq_(200, response.status_code)
def test_only_owner_can_accept_solution(self): """Make sure non-owner can't mark solution.""" response = get(self.client, 'questions.answers', args=[self.question.id]) doc = pq(response.content) eq_(1, len(doc('input[name="solution"]'))) self.client.logout() self.client.login(username='******', password='******') response = get(self.client, 'questions.answers', args=[self.question.id]) doc = pq(response.content) eq_(0, len(doc('input[name="solution"]'))) answer = self.question.answers.all()[0] response = post(self.client, 'questions.solution', args=[self.question.id, answer.id]) eq_(403, response.status_code)