本文整理汇总了Python中questions.tests.question函数的典型用法代码示例。如果您正苦于以下问题:Python question函数的具体用法?Python question怎么用?Python question使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了question函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_search_suggestion_question_age
def test_search_suggestion_question_age(self):
"""Verifies the view doesn't return old questions."""
topic(title='Fix problems', slug='fix-problems', save=True)
p = product(slug=u'firefox', save=True)
q1 = question(title='Fresh Cupcakes', save=True)
q1.products.add(p)
max_age = settings.SEARCH_DEFAULT_MAX_QUESTION_AGE
too_old = datetime.now() - timedelta(seconds=max_age * 2)
q2 = question(title='Stale Cupcakes', created=too_old, updated=too_old,
save=True)
q2.products.add(p)
self.refresh()
url = urlparams(
reverse('questions.aaq_step4', args=['desktop', 'fix-problems']),
search='cupcakes')
response = self.client.get(url, follow=True)
eq_(200, response.status_code)
self.assertContains(response, q1.title)
self.assertNotContains(response, q2.title)
示例2: test_locale_filter
def test_locale_filter(self):
"""Only questions for the current locale should be shown on the
questions front page for AAQ locales."""
eq_(Question.objects.count(), 0)
topic(title="Fix problems", slug="fix-problems", save=True)
p = product(slug=u"firefox", save=True)
q1 = question(title="question cupcakes?", save=True, locale="en-US")
q1.products.add(p)
q2 = question(title="question donuts?", save=True, locale="en-US")
q2.products.add(p)
q3 = question(title="question pies?", save=True, locale="pt-BR")
q3.products.add(p)
q4 = question(title="question pastries?", save=True, locale="de")
q4.products.add(p)
def sub_test(locale, *titles):
url = urlparams(reverse("questions.questions", locale=locale))
response = self.client.get(url, follow=True)
doc = pq(response.content)
eq_msg(len(doc("section[id^=question]")), len(titles), "Wrong number of results for {0}".format(locale))
for substr in titles:
assert substr in doc(".questions section .content h2 a").text()
# en-US and pt-BR are both in AAQ_LOCALES, so should be filtered.
sub_test("en-US", "cupcakes?", "donuts?")
sub_test("pt-BR", "pies?")
# de is not in AAQ_LOCALES, so should show en-US, but not pt-BR
sub_test("de", "cupcakes?", "donuts?", "pastries?")
示例3: test_search_suggestion_questions_locale
def test_search_suggestion_questions_locale(self):
"""Verifies the right languages show up in search suggestions."""
topic(title="Fix problems", slug="fix-problems", save=True)
p = product(slug=u"firefox", save=True)
q1 = question(title="question cupcakes?", save=True, locale="en-US")
q1.products.add(p)
q2 = question(title="question donuts?", save=True, locale="en-US")
q2.products.add(p)
q3 = question(title="question pies?", save=True, locale="pt-BR")
q3.products.add(p)
q4 = question(title="question pastries?", save=True, locale="de")
q4.products.add(p)
self.refresh()
def sub_test(locale, *titles):
url = urlparams(
reverse("questions.aaq_step4", args=["desktop", "fix-problems"], locale=locale), search="question"
)
response = self.client.get(url, follow=True)
doc = pq(response.content)
eq_msg(len(doc(".result.question")), len(titles), "Wrong number of results for {0}".format(locale))
for substr in titles:
assert substr in doc(".result.question h3 a").text()
sub_test("en-US", "cupcakes?", "donuts?")
sub_test("pt-BR", "cupcakes?", "donuts?", "pies?")
sub_test("de", "cupcakes?", "donuts?", "pastries?")
示例4: test_search_suggestion_questions_locale
def test_search_suggestion_questions_locale(self):
"""Verifies the right languages show up in search suggestions."""
topic(title='Fix problems', slug='fix-problems', save=True)
p = product(slug=u'firefox', save=True)
q1 = question(title='question cupcakes?', save=True, locale='en-US')
q1.products.add(p)
q2 = question(title='question donuts?', save=True, locale='en-US')
q2.products.add(p)
q3 = question(title='question pies?', save=True, locale='pt-BR')
q3.products.add(p)
q4 = question(title='question pastries?', save=True, locale='de')
q4.products.add(p)
self.refresh()
def sub_test(locale, *titles):
url = urlparams(reverse('questions.aaq_step4',
args=['desktop', 'fix-problems'],
locale=locale),
search='question')
response = self.client.get(url, follow=True)
doc = pq(response.content)
eq_msg(len(doc('.result.question')), len(titles),
'Wrong number of results for {0}'.format(locale))
for substr in titles:
assert substr in doc('.result.question h3 a').text()
sub_test('en-US', 'cupcakes?', 'donuts?')
sub_test('pt-BR', 'cupcakes?', 'donuts?', 'pies?')
sub_test('de', 'cupcakes?', 'donuts?', 'pastries?')
示例5: test_lock_old_questions
def test_lock_old_questions(self):
last_updated = datetime.now() - timedelta(days=100)
# created just now
q1 = question(save=True)
# created 200 days ago
q2 = question(created=(datetime.now() - timedelta(days=200)),
updated=last_updated,
save=True)
# created 200 days ago, already locked
q3 = question(created=(datetime.now() - timedelta(days=200)),
is_locked=True,
updated=last_updated,
save=True)
auto_lock_old_questions()
# There are three questions.
eq_(len(list(Question.objects.all())), 3)
# q2 and q3 are now locked and updated times are the same
locked_questions = list(Question.uncached.filter(is_locked=True))
eq_(sorted([(q.id, q.updated.date()) for q in locked_questions]),
[(q.id, q.updated.date()) for q in [q2, q3]])
# q1 is still unlocked.
locked_questions = list(Question.uncached.filter(is_locked=False))
eq_(sorted([q.id for q in locked_questions]),
[q1.id])
示例6: test_created
def test_created(self):
"""Basic functionality of created filter."""
created_ds = datetime(2010, 6, 19, 12, 00)
# on 6/19/2010
q1 = question(title=u'q1 audio', created=created_ds, save=True)
q1.tags.add(u'desktop')
ans = answer(question=q1, save=True)
answervote(answer=ans, helpful=True, save=True)
# on 6/21/2010
q2 = question(title=u'q2 audio',
created=(created_ds + timedelta(days=2)),
save=True)
q2.tags.add(u'desktop')
ans = answer(question=q2, save=True)
answervote(answer=ans, helpful=True, save=True)
self.refresh()
qs = {'a': 1, 'w': 2, 'format': 'json',
'sortby': 2, 'created_date': '06/20/2010'}
qs['created'] = constants.INTERVAL_BEFORE
response = self.client.get(reverse('search'), qs)
results = json.loads(response.content)['results']
eq_([q1.get_absolute_url()], [r['url'] for r in results])
qs['created'] = constants.INTERVAL_AFTER
response = self.client.get(reverse('search'), qs)
results = json.loads(response.content)['results']
eq_([q2.get_absolute_url()], [r['url'] for r in results])
示例7: test_created
def test_created(self):
"""Basic functionality of created filter."""
created_ds = datetime(2010, 6, 19, 12, 00)
# on 6/19/2010
q1 = question(title=u"q1 audio", created=created_ds, save=True)
q1.tags.add(u"desktop")
ans = answer(question=q1, save=True)
answervote(answer=ans, helpful=True, save=True)
# on 6/21/2010
q2 = question(title=u"q2 audio", created=(created_ds + timedelta(days=2)), save=True)
q2.tags.add(u"desktop")
ans = answer(question=q2, save=True)
answervote(answer=ans, helpful=True, save=True)
self.refresh()
qs = {"a": 1, "w": 2, "format": "json", "sortby": 2, "created_date": "06/20/2010"}
qs["created"] = constants.INTERVAL_BEFORE
response = self.client.get(reverse("search"), qs)
results = json.loads(response.content)["results"]
eq_([q1.get_absolute_url()], [r["url"] for r in results])
qs["created"] = constants.INTERVAL_AFTER
response = self.client.get(reverse("search"), qs)
results = json.loads(response.content)["results"]
eq_([q2.get_absolute_url()], [r["url"] for r in results])
示例8: test_question_topics
def test_question_topics(self):
"""Search questions for topics."""
t1 = topic(slug='doesnotexist', save=True)
t2 = topic(slug='cookies', save=True)
t3 = topic(slug='sync', save=True)
q = question(save=True)
q.topics.add(t2)
q = question(save=True)
q.topics.add(t2)
q.topics.add(t3)
self.refresh()
topic_vals = (
(t1.slug, 0),
(t2.slug, 2),
(t3.slug, 1),
([t2.slug, t3.slug], 1),
)
qs = {'a': 1, 'w': 2, 'format': 'json'}
for topics, number in topic_vals:
qs.update({'topics': topics})
response = self.client.get(reverse('search'), qs)
eq_(number, json.loads(response.content)['total'])
示例9: test_question_products
def test_question_products(self):
"""Search questions for products."""
p1 = product(slug='b2g', save=True)
p2 = product(slug='mobile', save=True)
p3 = product(slug='desktop', save=True)
q = question(save=True)
q.products.add(p2)
q = question(save=True)
q.products.add(p2)
q.products.add(p3)
self.refresh()
product_vals = (
(p1.slug, 0),
(p2.slug, 2),
(p3.slug, 1),
([p2.slug, p3.slug], 1),
)
qs = {'a': 1, 'w': 2, 'format': 'json'}
for products, number in product_vals:
qs.update({'product': products})
response = self.client.get(reverse('search'), qs)
eq_(number, json.loads(response.content)['total'])
示例10: test_locale_filter
def test_locale_filter(self):
"""Only questions for the current locale should be shown on the
questions front page for AAQ locales."""
eq_(Question.objects.count(), 0)
topic(title='Fix problems', slug='fix-problems', save=True)
p = product(slug=u'firefox', save=True)
q1 = question(title='question cupcakes?', save=True, locale='en-US')
q1.products.add(p)
q2 = question(title='question donuts?', save=True, locale='en-US')
q2.products.add(p)
q3 = question(title='question pies?', save=True, locale='pt-BR')
q3.products.add(p)
q4 = question(title='question pastries?', save=True, locale='de')
q4.products.add(p)
def sub_test(locale, *titles):
url = urlparams(reverse('questions.questions', locale=locale))
response = self.client.get(url, follow=True)
doc = pq(response.content)
eq_msg(len(doc('section[id^=question]')), len(titles),
'Wrong number of results for {0}'.format(locale))
for substr in titles:
assert substr in doc('.questions section .content h2 a').text()
# en-US and pt-BR are both in AAQ_LOCALES, so should be filtered.
sub_test('en-US', 'cupcakes?', 'donuts?')
sub_test('pt-BR', 'pies?')
# de is not in AAQ_LOCALES, so should show en-US, but not pt-BR
sub_test('de', 'cupcakes?', 'donuts?', 'pastries?')
示例11: test_visit_count_from_analytics
def test_visit_count_from_analytics(self, pageviews_by_question):
"""Verify stored visit counts from mocked data."""
q1 = question(save=True)
q2 = question(save=True)
q3 = question(save=True)
pageviews_by_question.return_value = {
q1.id: 42,
q2.id: 27,
q3.id: 1337,
123459: 3,
}
QuestionVisits.reload_from_analytics()
eq_(3, QuestionVisits.objects.count())
eq_(42, QuestionVisits.objects.get(question_id=q1.id).visits)
eq_(27, QuestionVisits.objects.get(question_id=q2.id).visits)
eq_(1337, QuestionVisits.objects.get(question_id=q3.id).visits)
# Change the data and run again to cover the update case.
pageviews_by_question.return_value = {
q1.id: 100,
q2.id: 200,
q3.id: 300,
}
QuestionVisits.reload_from_analytics()
eq_(3, QuestionVisits.uncached.count())
eq_(100, QuestionVisits.uncached.get(question_id=q1.id).visits)
eq_(200, QuestionVisits.uncached.get(question_id=q2.id).visits)
eq_(300, QuestionVisits.uncached.get(question_id=q3.id).visits)
示例12: test_user_num_questions
def test_user_num_questions(self):
"""Answers are counted correctly on a user."""
u = user(save=True)
eq_(user_num_questions(u), 0)
q1 = question(creator=u, save=True)
eq_(user_num_questions(u), 1)
q2 = question(creator=u, save=True)
eq_(user_num_questions(u), 2)
q1.delete()
eq_(user_num_questions(u), 1)
q2.delete()
eq_(user_num_questions(u), 0)
示例13: test_recent_counts_with_filter
def test_recent_counts_with_filter(self):
"""Verify that recent_asked_count and recent_unanswered_count
respect filters passed."""
now = datetime.now()
question(created=now, locale='en-US', save=True)
q = question(created=now, locale='en-US', save=True)
answer(question=q, save=True)
question(created=now, locale='pt-BR', save=True)
question(created=now, locale='pt-BR', save=True)
q = question(created=now, locale='pt-BR', save=True)
answer(question=q, save=True)
# 5 asked recently, 3 are unanswered
eq_(5, Question.recent_asked_count())
eq_(3, Question.recent_unanswered_count())
# check english (2 asked, 1 unanswered)
locale_filter = Q(locale='en-US')
eq_(2, Question.recent_asked_count(locale_filter))
eq_(1, Question.recent_unanswered_count(locale_filter))
# check pt-BR (3 asked, 2 unanswered)
locale_filter = Q(locale='pt-BR')
eq_(3, Question.recent_asked_count(locale_filter))
eq_(2, Question.recent_unanswered_count(locale_filter))
示例14: test_questions
def test_questions(self):
"""Test questions API call."""
# A question with a solution:
a = answer(save=True)
a.question.solution = a
a.question.save()
# A question with an answer:
answer(save=True)
# A question without answers:
question(save=True)
r = self._get_api_result('kpi_questions')
eq_(r['objects'][0]['solved'], 1)
eq_(r['objects'][0]['responded'], 2)
eq_(r['objects'][0]['questions'], 3)
示例15: test_cron_updates_counts
def test_cron_updates_counts(self):
q = question(save=True)
self.refresh()
eq_(q.num_votes_past_week, 0)
# NB: Need to call .values_dict() here and later otherwise we
# get a Question object which has data from the database and
# not the index.
document = (Question.search()
.values_dict('question_num_votes_past_week')
.filter(id=q.id))[0]
eq_(document['question_num_votes_past_week'], 0)
vote = questionvote(question=q, anonymous_id='abc123')
vote.save()
q.num_votes_past_week = 0
q.save()
update_weekly_votes()
self.refresh()
q = Question.objects.get(pk=q.pk)
eq_(1, q.num_votes_past_week)
document = (Question.search()
.values_dict('question_num_votes_past_week')
.filter(id=q.id))[0]
eq_(document['question_num_votes_past_week'], 1)