当前位置: 首页>>代码示例>>Python>>正文


Python QuestionFactory.save方法代码示例

本文整理汇总了Python中kitsune.questions.tests.QuestionFactory.save方法的典型用法代码示例。如果您正苦于以下问题:Python QuestionFactory.save方法的具体用法?Python QuestionFactory.save怎么用?Python QuestionFactory.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kitsune.questions.tests.QuestionFactory的用法示例。


在下文中一共展示了QuestionFactory.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_data_in_index

# 需要导入模块: from kitsune.questions.tests import QuestionFactory [as 别名]
# 或者: from kitsune.questions.tests.QuestionFactory import save [as 别名]
    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)
开发者ID:1234-,项目名称:kitsune,代码行数:33,代码来源:test_es.py

示例2: test_cron_updates_counts

# 需要导入模块: from kitsune.questions.tests import QuestionFactory [as 别名]
# 或者: from kitsune.questions.tests.QuestionFactory import save [as 别名]
    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)
开发者ID:1234-,项目名称:kitsune,代码行数:29,代码来源:test_votes.py

示例3: test_responded

# 需要导入模块: from kitsune.questions.tests import QuestionFactory [as 别名]
# 或者: from kitsune.questions.tests.QuestionFactory import save [as 别名]
    def test_responded(self):
        """Verify the responded queryset."""
        # Create a question, there shouldn't be any responded yet.
        q = QuestionFactory()
        eq_(0, Question.objects.responded().count())

        # Add an answer, there should be one responded.
        a = AnswerFactory(question=q)
        eq_(1, Question.objects.responded().count())

        # Add an answer by the creator, there should be none responded.
        a = AnswerFactory(creator=q.creator, question=q)
        eq_(0, Question.objects.responded().count())

        # Add another answer, there should be one responded.
        a = AnswerFactory(question=q)
        eq_(1, Question.objects.responded().count())

        # Lock it, there should be none responded.
        q.is_locked = True
        q.save()
        eq_(0, Question.objects.responded().count())

        # Unlock it and mark solved, there should be none responded.
        q.is_locked = False
        q.solution = a
        q.save()
        eq_(0, Question.objects.responded().count())
开发者ID:1234-,项目名称:kitsune,代码行数:30,代码来源:test_managers.py

示例4: test_asker_replies_arent_a_contribution

# 需要导入模块: from kitsune.questions.tests import QuestionFactory [as 别名]
# 或者: from kitsune.questions.tests.QuestionFactory import save [as 别名]
    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)
开发者ID:1234-,项目名称:kitsune,代码行数:31,代码来源:test_api.py

示例5: _make_question

# 需要导入模块: from kitsune.questions.tests import QuestionFactory [as 别名]
# 或者: from kitsune.questions.tests.QuestionFactory import save [as 别名]
    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
开发者ID:1234-,项目名称:kitsune,代码行数:32,代码来源:test_api.py

示例6: test_no_notification_on_update

# 需要导入模块: from kitsune.questions.tests import QuestionFactory [as 别名]
# 或者: from kitsune.questions.tests.QuestionFactory import save [as 别名]
    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)
开发者ID:1234-,项目名称:kitsune,代码行数:11,代码来源:test_models.py

示例7: test_tasks

# 需要导入模块: from kitsune.questions.tests import QuestionFactory [as 别名]
# 或者: from kitsune.questions.tests.QuestionFactory import save [as 别名]
    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)
开发者ID:chupahanks,项目名称:kitsune,代码行数:13,代码来源:test_es.py

示例8: test_question_spam_is_unindexed

# 需要导入模块: from kitsune.questions.tests import QuestionFactory [as 别名]
# 或者: from kitsune.questions.tests.QuestionFactory import save [as 别名]
    def test_question_spam_is_unindexed(self):
        search = QuestionMappingType.search()

        q = QuestionFactory(title=u'I am spam')
        self.refresh()
        eq_(search.query(question_title__match='spam').count(), 1)

        q.is_spam = True
        q.save()
        self.refresh()
        eq_(search.query(question_title__match='spam').count(), 0)
开发者ID:1234-,项目名称:kitsune,代码行数:13,代码来源:test_es.py

示例9: test_filter_is_solved

# 需要导入模块: from kitsune.questions.tests import QuestionFactory [as 别名]
# 或者: from kitsune.questions.tests.QuestionFactory import save [as 别名]
    def test_filter_is_solved(self):
        q1 = QuestionFactory()
        a1 = AnswerFactory(question=q1)
        q1.solution = a1
        q1.save()
        q2 = QuestionFactory()

        qs = self.filter_instance.filter_is_solved(self.queryset, True)
        eq_(list(qs), [q1])

        qs = self.filter_instance.filter_is_solved(self.queryset, False)
        eq_(list(qs), [q2])
开发者ID:Andisutra80,项目名称:kitsune,代码行数:14,代码来源:test_api.py

示例10: test_counts

# 需要导入模块: from kitsune.questions.tests import QuestionFactory [as 别名]
# 或者: from kitsune.questions.tests.QuestionFactory import save [as 别名]
    def test_counts(self):
        u = UserFactory()
        p = u.profile
        q = QuestionFactory(creator=u)
        AnswerFactory(creator=u)
        q.solution = AnswerFactory(question=q, creator=u)
        q.save()

        serializer = api.ProfileSerializer(instance=p)
        eq_(serializer.data['question_count'], 1)
        eq_(serializer.data['answer_count'], 2)
        eq_(serializer.data['solution_count'], 1)
开发者ID:1234-,项目名称:kitsune,代码行数:14,代码来源:test_api.py

示例11: TestVoteQuestions

# 需要导入模块: from kitsune.questions.tests import QuestionFactory [as 别名]
# 或者: from kitsune.questions.tests.QuestionFactory import save [as 别名]
class TestVoteQuestions(TestCaseBase):
    def setUp(self):
        u = UserFactory()
        self.client.login(username=u.username, password='testpass')
        self.question = QuestionFactory()

    def test_cannot_vote_on_spam_question(self):
        self.question.is_spam = True
        self.question.save()

        res = self.client.post(
            reverse('questions.vote', args=[self.question.id]))
        eq_(res.status_code, 404)
开发者ID:Andisutra80,项目名称:kitsune,代码行数:15,代码来源:test_views.py

示例12: test_is_taken

# 需要导入模块: from kitsune.questions.tests import QuestionFactory [as 别名]
# 或者: from kitsune.questions.tests.QuestionFactory import save [as 别名]
    def test_is_taken(self):
        q = QuestionFactory()
        u = UserFactory()
        eq_(q.is_taken, False)

        q.taken_by = u
        q.taken_until = datetime.now() + timedelta(seconds=600)
        q.save()
        eq_(q.is_taken, True)

        q.taken_by = None
        q.taken_until = None
        q.save()
        eq_(q.is_taken, False)
开发者ID:1234-,项目名称:kitsune,代码行数:16,代码来源:test_models.py

示例13: test_only_show_wiki_and_questions

# 需要导入模块: from kitsune.questions.tests import QuestionFactory [as 别名]
# 或者: from kitsune.questions.tests.QuestionFactory import save [as 别名]
    def test_only_show_wiki_and_questions(self):
        """Tests that the simple search doesn't show forums

        This verifies that we're only showing documents of the type
        that should be shown and that the filters on model are working
        correctly.

        Bug #767394

        """
        p = ProductFactory(slug=u'desktop')
        ques = QuestionFactory(title=u'audio', product=p)
        ans = AnswerFactory(question=ques, content=u'volume')
        AnswerVoteFactory(answer=ans, helpful=True)

        doc = DocumentFactory(title=u'audio', locale=u'en-US', category=10)
        doc.products.add(p)
        RevisionFactory(document=doc, is_approved=True)

        thread1 = ThreadFactory(title=u'audio')
        PostFactory(thread=thread1)

        self.refresh()

        response = self.client.get(reverse('search'), {
            'q': 'audio', 'format': 'json'})

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content['total'], 2)

        # Archive the article and question. They should no longer appear
        # in simple search results.
        ques.is_archived = True
        ques.save()
        doc.is_archived = True
        doc.save()

        self.refresh()

        response = self.client.get(reverse('search'), {
            'q': 'audio', 'format': 'json'})

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content['total'], 0)
开发者ID:Andisutra80,项目名称:kitsune,代码行数:50,代码来源:test_search_simple.py

示例14: test_filter_solved_by

# 需要导入模块: from kitsune.questions.tests import QuestionFactory [as 别名]
# 或者: from kitsune.questions.tests.QuestionFactory import save [as 别名]
    def test_filter_solved_by(self):
        q1 = QuestionFactory()
        a1 = AnswerFactory(question=q1)
        q1.solution = a1
        q1.save()
        q2 = QuestionFactory()
        AnswerFactory(question=q2, creator=a1.creator)
        q3 = QuestionFactory()
        a3 = AnswerFactory(question=q3)
        q3.solution = a3
        q3.save()

        qs = self.filter_instance.filter_solved_by(self.queryset, a1.creator.username)
        eq_(list(qs), [q1])

        qs = self.filter_instance.filter_solved_by(self.queryset, a3.creator.username)
        eq_(list(qs), [q3])
开发者ID:Andisutra80,项目名称:kitsune,代码行数:19,代码来源:test_api.py

示例15: TestQuestionDetails

# 需要导入模块: from kitsune.questions.tests import QuestionFactory [as 别名]
# 或者: from kitsune.questions.tests.QuestionFactory import save [as 别名]
class TestQuestionDetails(TestCaseBase):
    def setUp(self):
        self.question = QuestionFactory()

    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 = UserFactory()
        add_permission(u, FlaggedObject, 'can_moderate')
        self.client.login(username=u.username, password='testpass')

        res = get(self.client, 'questions.details', args=[self.question.id])
        eq_(200, res.status_code)
开发者ID:Andisutra80,项目名称:kitsune,代码行数:19,代码来源:test_views.py


注:本文中的kitsune.questions.tests.QuestionFactory.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。