本文整理汇总了Python中sumo.tests.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: common_answer_vote
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)
示例2: test_top_contributors
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')))
示例3: common_answer_vote
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())
示例4: common_vote
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)
示例5: test_delete_post_belongs_to_thread_and_forum
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='testpass')
# 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)
示例6: common_vote
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)
示例7: test_delete_post_belongs_to_thread_and_forum
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)
示例8: test_delete_post_belongs_to_thread_and_document
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)
示例9: test_num_replies
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
示例10: test_edit_answer_without_permission
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)
示例11: test_delete_question_without_permissions
def test_delete_question_without_permissions(self):
"""Deleting a question without permissions is a 403."""
self.client.login(username="tagger", password="testpass")
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)
示例12: test_long_title_truncated_in_crumbs
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 ...')
示例13: test_last_post_link_has_post_id
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')
示例14: test_edit_locked_thread_403
def test_edit_locked_thread_403(self):
"""Editing a locked thread returns 403."""
jsocol = User.objects.get(username='jsocol')
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)
示例15: test_answer_creator_can_edit
def test_answer_creator_can_edit(self):
"""The creator of an answer can edit his/her answer."""
self.client.login(username="rrosario", password="testpass")
# 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)