本文整理汇总了Python中kitsune.questions.tests.QuestionFactory类的典型用法代码示例。如果您正苦于以下问题:Python QuestionFactory类的具体用法?Python QuestionFactory怎么用?Python QuestionFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QuestionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_data_in_index
def test_data_in_index(self):
"""Verify the data we are indexing."""
p = ProductFactory()
q = QuestionFactory(locale='pt-BR', product=p)
a = AnswerFactory(question=q)
self.refresh()
eq_(AnswerMetricsMappingType.search().count(), 1)
data = AnswerMetricsMappingType.search()[0]
eq_(data['locale'], q.locale)
eq_(data['product'], [p.slug])
eq_(data['creator_id'], a.creator_id)
eq_(data['is_solution'], False)
eq_(data['by_asker'], False)
# Mark as solution and verify
q.solution = a
q.save()
self.refresh()
data = AnswerMetricsMappingType.search()[0]
eq_(data['is_solution'], True)
# Make the answer creator to be the question creator and verify.
a.creator = q.creator
a.save()
self.refresh()
data = AnswerMetricsMappingType.search()[0]
eq_(data['by_asker'], True)
示例2: test_cron_updates_counts
def test_cron_updates_counts(self):
q = QuestionFactory()
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 = (QuestionMappingType.search()
.filter(id=q.id))[0]
eq_(document['question_num_votes_past_week'], 0)
QuestionVoteFactory(question=q, anonymous_id='abc123')
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 = (QuestionMappingType.search()
.filter(id=q.id))[0]
eq_(document['question_num_votes_past_week'], 1)
示例3: test_asker_replies_arent_a_contribution
def test_asker_replies_arent_a_contribution(self):
"""Verify that replies posted by the question creator aren't counted.
If a user has 10 replies to their own question, they aren't counted as
a contributor.
"""
# A user with 10 answers to own question.
q = QuestionFactory()
u = q.creator
AnswerFactory.create_batch(10, creator=u, question=q)
# Create metric kinds and update metrics for tomorrow (today's
# activity shows up tomorrow).
self._make_contributor_metric_kinds()
update_contributor_metrics(day=date.today() + timedelta(days=1))
r = self._get_api_result('api.kpi.contributors')
eq_(r['objects'][0]['support_forum'], 0)
# Change the question creator, now we should have 1 contributor.
q.creator = UserFactory()
q.save()
cache.clear() # We need to clear the cache for new results.
Metric.objects.all().delete()
update_contributor_metrics(day=date.today() + timedelta(days=1))
r = self._get_api_result('api.kpi.contributors')
eq_(r['objects'][0]['support_forum'], 1)
示例4: test_take_twice_forced
def test_take_twice_forced(self):
u1 = UserFactory()
u2 = UserFactory()
q = QuestionFactory()
q.take(u1)
q.take(u2, force=True)
eq_(q.taken_by, u2)
示例5: test_created
def test_created(self):
"""Basic functionality of created filter."""
created_ds = datetime(2010, 6, 19, 12, 00)
# on 6/19/2010
q1 = QuestionFactory(title=u"q1 audio", created=created_ds)
q1.tags.add(u"desktop")
ans = AnswerFactory(question=q1)
AnswerVoteFactory(answer=ans, helpful=True)
# on 6/21/2010
q2 = QuestionFactory(title=u"q2 audio", created=(created_ds + timedelta(days=2)), tags=[u"desktop"])
ans = AnswerFactory(question=q2)
AnswerVoteFactory(answer=ans, helpful=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.advanced"), 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.advanced"), qs)
results = json.loads(response.content)["results"]
eq_([q2.get_absolute_url()], [r["url"] for r in results])
示例6: _make_question
def _make_question(self, solved=True, **kwargs):
defaults = {
'title': 'Login to website comments disabled ' + str(time.time()),
'content': """
readersupportednews.org, sends me emails with a list of
articles to read.
The links to the articles work as normal, except that I
cannot login from the linked article - as required - to
send my comments.
I see a javascript activity statement at the bottom left
corner of my screen while the left button is depressed
on the Login button. it is gone when I release the left
button, but no results.
I have the latest (7) version of java enabled, on an XP
box.
Why this inability to login to this website commentary?
""",
}
defaults.update(kwargs)
q = QuestionFactory(**defaults)
if solved:
a = AnswerFactory(question=q)
q.solution = a
# Trigger a reindex for the question.
q.save()
return q
示例7: test_is_taken
def test_is_taken(self):
q = QuestionFactory()
u = UserFactory()
q.take(u)
url = reverse('question-detail', args=[q.id])
res = self.client.get(url)
eq_(res.status_code, 200)
eq_(res.data['taken_by']['username'], u.username)
示例8: test_weird_list_troubleshooting_info
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 = QuestionFactory()
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)
示例9: test_no_notification_on_update
def test_no_notification_on_update(self):
"""Saving an existing question does not watch it."""
q = QuestionFactory()
QuestionReplyEvent.stop_notifying(q.creator, q)
assert not QuestionReplyEvent.is_notifying(q.creator, q)
q.save()
assert not QuestionReplyEvent.is_notifying(q.creator, q)
示例10: test_question_no_answers_deleted
def test_question_no_answers_deleted(self):
search = QuestionMappingType.search()
q = QuestionFactory(title=u'Does this work?')
self.refresh()
eq_(search.query(question_title__match='work').count(), 1)
q.delete()
self.refresh()
eq_(search.query(question_title__match='work').count(), 0)
示例11: test_empty_troubleshooting_info
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 = QuestionFactory()
q.add_metadata(troubleshooting='{"foo": "bar"}')
# This case should not raise an error.
response = get(self.client, 'questions.details', args=[q.id])
eq_(200, response.status_code)
示例12: test_tasks
def test_tasks(self, index_fun):
"""Tests to make sure tasks are added and run"""
q = QuestionFactory()
# Don't call self.refresh here since that calls generate_tasks().
eq_(index_fun.call_count, 0)
q.save()
generate_tasks()
eq_(index_fun.call_count, 1)
示例13: test_filter_is_taken_expired
def test_filter_is_taken_expired(self):
q = QuestionFactory()
# "take" the question, but with an expired timer.
q.taken_by = UserFactory()
q.taken_until = datetime.now() - timedelta(seconds=60)
url = reverse('question-list') + '?is_taken=1'
res = self.client.get(url)
eq_(res.status_code, 200)
eq_(res.data['count'], 0)
示例14: test_delete_question_removes_flag
def test_delete_question_removes_flag(self):
"""Deleting a question also removes the flags on that question."""
q = QuestionFactory(title='Test Question', content='Lorem Ipsum Dolor')
u = UserFactory()
FlaggedObject.objects.create(
status=0, content_object=q, reason='language', creator_id=u.id)
eq_(1, FlaggedObject.objects.count())
q.delete()
eq_(0, FlaggedObject.objects.count())
示例15: test_filter_taken_by_username
def test_filter_taken_by_username(self):
q1 = QuestionFactory()
q2 = QuestionFactory()
q2.take(q1.creator)
url = reverse('question-list') + '?taken_by=' + q1.creator.username
res = self.client.get(url)
eq_(res.status_code, 200)
eq_(res.data['count'], 1)
eq_(res.data['results'][0]['id'], q2.id)