예제 #1
0
파일: test_es.py 프로젝트: rootmeb/kitsune
    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
0
    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())
예제 #3
0
파일: test_api.py 프로젝트: 1234-/kitsune
    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
예제 #4
0
    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())
예제 #5
0
파일: test_api.py 프로젝트: ziegeer/kitsune
    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
예제 #6
0
파일: test_es.py 프로젝트: 1234-/kitsune
    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)
예제 #7
0
    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])
예제 #8
0
    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])
예제 #9
0
    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)
예제 #10
0
파일: test_api.py 프로젝트: 1234-/kitsune
    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)
예제 #11
0
파일: test_utils.py 프로젝트: 1234-/kitsune
    def test_num_solutions(self):
        u = UserFactory()
        q1 = QuestionFactory()
        q2 = QuestionFactory()
        a1 = AnswerFactory(creator=u, question=q1)
        a2 = AnswerFactory(creator=u, question=q2)
        eq_(num_solutions(u), 0)

        q1.solution = a1
        q1.save()
        eq_(num_solutions(u), 1)

        q2.solution = a2
        q2.save()
        eq_(num_solutions(u), 2)

        q1.solution = None
        q1.save()
        eq_(num_solutions(u), 1)

        a2.delete()
        eq_(num_solutions(u), 0)
예제 #12
0
    def test_num_solutions(self):
        u = UserFactory()
        q1 = QuestionFactory()
        q2 = QuestionFactory()
        a1 = AnswerFactory(creator=u, question=q1)
        a2 = AnswerFactory(creator=u, question=q2)
        eq_(num_solutions(u), 0)

        q1.solution = a1
        q1.save()
        eq_(num_solutions(u), 1)

        q2.solution = a2
        q2.save()
        eq_(num_solutions(u), 2)

        q1.solution = None
        q1.save()
        eq_(num_solutions(u), 1)

        a2.delete()
        eq_(num_solutions(u), 0)
예제 #13
0
    def test_done(self):
        """Verify the done queryset."""
        # Create a question, there shouldn't be any done yet.
        q = QuestionFactory()
        eq_(0, Question.objects.done().count())

        # Add an answer, there shouldn't be any done yet.
        a = AnswerFactory(question=q)
        eq_(0, Question.objects.done().count())

        # Make it the solution, there should be one done.
        q.solution = a
        q.save()
        eq_(1, Question.objects.done().count())

        # Create a locked questions, there should be two done.
        QuestionFactory(is_locked=True)
        eq_(2, Question.objects.done().count())
예제 #14
0
    def test_done(self):
        """Verify the done queryset."""
        # Create a question, there shouldn't be any done yet.
        q = QuestionFactory()
        eq_(0, Question.objects.done().count())

        # Add an answer, there shouldn't be any done yet.
        a = AnswerFactory(question=q)
        eq_(0, Question.objects.done().count())

        # Make it the solution, there should be one done.
        q.solution = a
        q.save()
        eq_(1, Question.objects.done().count())

        # Create a locked questions, there should be two done.
        QuestionFactory(is_locked=True)
        eq_(2, Question.objects.done().count())
예제 #15
0
    def test_questions_by_product(self):
        """Test product filtering of questions API call."""
        firefox_os = ProductFactory(slug='firefox-os')
        firefox = ProductFactory(slug='firefox')

        # A Firefox OS question with a solution:
        q = QuestionFactory(product=firefox_os)
        a = AnswerFactory(question=q)
        q.solution = a
        q.save()

        # A Firefox OS question with an answer:
        q = QuestionFactory(product=firefox_os)
        AnswerFactory(question=q)

        # A Firefox OS question without answers:
        q = QuestionFactory(product=firefox_os)

        # A Firefox question without answers:
        q = QuestionFactory(product=firefox, locale='pt-BR')

        # Verify no product filtering:
        r = self._get_api_result('api.kpi.questions')
        eq_(r['objects'][0]['solved'], 1)
        eq_(r['objects'][0]['responded_24'], 2)
        eq_(r['objects'][0]['responded_72'], 2)
        eq_(r['objects'][0]['questions'], 4)

        # Verify product=firefox-os
        r = self._get_api_result('api.kpi.questions', product='firefox-os')
        eq_(r['objects'][0]['solved'], 1)
        eq_(r['objects'][0]['responded_24'], 2)
        eq_(r['objects'][0]['responded_72'], 2)
        eq_(r['objects'][0]['questions'], 3)

        # Verify product=firefox
        r = self._get_api_result('api.kpi.questions', product='firefox')
        eq_(r['objects'][0]['questions'], 1)
        assert 'solved' not in r['objects'][0]
        assert 'responded_24' not in r['objects'][0]
        assert 'responded_72' not in r['objects'][0]
예제 #16
0
파일: test_api.py 프로젝트: 1234-/kitsune
    def test_questions_by_product(self):
        """Test product filtering of questions API call."""
        firefox_os = ProductFactory(slug='firefox-os')
        firefox = ProductFactory(slug='firefox')

        # A Firefox OS question with a solution:
        q = QuestionFactory(product=firefox_os)
        a = AnswerFactory(question=q)
        q.solution = a
        q.save()

        # A Firefox OS question with an answer:
        q = QuestionFactory(product=firefox_os)
        AnswerFactory(question=q)

        # A Firefox OS question without answers:
        q = QuestionFactory(product=firefox_os)

        # A Firefox question without answers:
        q = QuestionFactory(product=firefox, locale='pt-BR')

        # Verify no product filtering:
        r = self._get_api_result('api.kpi.questions')
        eq_(r['objects'][0]['solved'], 1)
        eq_(r['objects'][0]['responded_24'], 2)
        eq_(r['objects'][0]['responded_72'], 2)
        eq_(r['objects'][0]['questions'], 4)

        # Verify product=firefox-os
        r = self._get_api_result('api.kpi.questions', product='firefox-os')
        eq_(r['objects'][0]['solved'], 1)
        eq_(r['objects'][0]['responded_24'], 2)
        eq_(r['objects'][0]['responded_72'], 2)
        eq_(r['objects'][0]['questions'], 3)

        # Verify product=firefox
        r = self._get_api_result('api.kpi.questions', product='firefox')
        eq_(r['objects'][0]['questions'], 1)
        assert 'solved' not in r['objects'][0]
        assert 'responded_24' not in r['objects'][0]
        assert 'responded_72' not in r['objects'][0]
예제 #17
0
파일: test_api.py 프로젝트: zu83/kitsune
    def test_questions_by_product(self):
        """Test product filtering of questions API call."""
        firefox_os = ProductFactory(slug="firefox-os")
        firefox = ProductFactory(slug="firefox")

        # A Firefox OS question with a solution:
        q = QuestionFactory(product=firefox_os)
        a = AnswerFactory(question=q)
        q.solution = a
        q.save()

        # A Firefox OS question with an answer:
        q = QuestionFactory(product=firefox_os)
        AnswerFactory(question=q)

        # A Firefox OS question without answers:
        q = QuestionFactory(product=firefox_os)

        # A Firefox question without answers:
        q = QuestionFactory(product=firefox, locale="pt-BR")

        # Verify no product filtering:
        r = self._get_api_result("api.kpi.questions")
        eq_(r["objects"][0]["solved"], 1)
        eq_(r["objects"][0]["responded_24"], 2)
        eq_(r["objects"][0]["responded_72"], 2)
        eq_(r["objects"][0]["questions"], 4)

        # Verify product=firefox-os
        r = self._get_api_result("api.kpi.questions", product="firefox-os")
        eq_(r["objects"][0]["solved"], 1)
        eq_(r["objects"][0]["responded_24"], 2)
        eq_(r["objects"][0]["responded_72"], 2)
        eq_(r["objects"][0]["questions"], 3)

        # Verify product=firefox
        r = self._get_api_result("api.kpi.questions", product="firefox")
        eq_(r["objects"][0]["questions"], 1)
        assert "solved" not in r["objects"][0]
        assert "responded_24" not in r["objects"][0]
        assert "responded_72" not in r["objects"][0]
예제 #18
0
파일: test_api.py 프로젝트: 1234-/kitsune
    def test_questions_by_locale(self):
        """Test locale filtering of questions API call."""
        # An en-US question with a solution:
        q = QuestionFactory(locale='en-US')
        a = AnswerFactory(question=q)
        q.solution = a
        q.save()
        # An en-US question with an answer:
        q = QuestionFactory(locale='en-US')
        AnswerFactory(question=q)
        # An en-US question without answers:
        QuestionFactory(locale='en-US')

        # A pt-BR question without answers:
        QuestionFactory(locale='pt-BR')

        # Verify no locale filtering:
        r = self._get_api_result('api.kpi.questions')
        eq_(r['objects'][0]['solved'], 1)
        eq_(r['objects'][0]['responded_24'], 2)
        eq_(r['objects'][0]['responded_72'], 2)
        eq_(r['objects'][0]['questions'], 4)

        # Verify locale=en-US
        r = self._get_api_result('api.kpi.questions', locale='en-US')
        eq_(r['objects'][0]['solved'], 1)
        eq_(r['objects'][0]['responded_24'], 2)
        eq_(r['objects'][0]['responded_72'], 2)
        eq_(r['objects'][0]['questions'], 3)

        # Verify locale=pt-BR
        r = self._get_api_result('api.kpi.questions', locale='pt-BR')
        eq_(r['objects'][0]['questions'], 1)
        assert 'solved' not in r['objects'][0]
        assert 'responded_24' not in r['objects'][0]
        assert 'responded_72' not in r['objects'][0]
예제 #19
0
파일: test_api.py 프로젝트: zu83/kitsune
    def test_questions_by_locale(self):
        """Test locale filtering of questions API call."""
        # An en-US question with a solution:
        q = QuestionFactory(locale="en-US")
        a = AnswerFactory(question=q)
        q.solution = a
        q.save()
        # An en-US question with an answer:
        q = QuestionFactory(locale="en-US")
        AnswerFactory(question=q)
        # An en-US question without answers:
        QuestionFactory(locale="en-US")

        # A pt-BR question without answers:
        QuestionFactory(locale="pt-BR")

        # Verify no locale filtering:
        r = self._get_api_result("api.kpi.questions")
        eq_(r["objects"][0]["solved"], 1)
        eq_(r["objects"][0]["responded_24"], 2)
        eq_(r["objects"][0]["responded_72"], 2)
        eq_(r["objects"][0]["questions"], 4)

        # Verify locale=en-US
        r = self._get_api_result("api.kpi.questions", locale="en-US")
        eq_(r["objects"][0]["solved"], 1)
        eq_(r["objects"][0]["responded_24"], 2)
        eq_(r["objects"][0]["responded_72"], 2)
        eq_(r["objects"][0]["questions"], 3)

        # Verify locale=pt-BR
        r = self._get_api_result("api.kpi.questions", locale="pt-BR")
        eq_(r["objects"][0]["questions"], 1)
        assert "solved" not in r["objects"][0]
        assert "responded_24" not in r["objects"][0]
        assert "responded_72" not in r["objects"][0]
예제 #20
0
    def test_questions_by_locale(self):
        """Test locale filtering of questions API call."""
        # An en-US question with a solution:
        q = QuestionFactory(locale='en-US')
        a = AnswerFactory(question=q)
        q.solution = a
        q.save()
        # An en-US question with an answer:
        q = QuestionFactory(locale='en-US')
        AnswerFactory(question=q)
        # An en-US question without answers:
        QuestionFactory(locale='en-US')

        # A pt-BR question without answers:
        QuestionFactory(locale='pt-BR')

        # Verify no locale filtering:
        r = self._get_api_result('api.kpi.questions')
        eq_(r['objects'][0]['solved'], 1)
        eq_(r['objects'][0]['responded_24'], 2)
        eq_(r['objects'][0]['responded_72'], 2)
        eq_(r['objects'][0]['questions'], 4)

        # Verify locale=en-US
        r = self._get_api_result('api.kpi.questions', locale='en-US')
        eq_(r['objects'][0]['solved'], 1)
        eq_(r['objects'][0]['responded_24'], 2)
        eq_(r['objects'][0]['responded_72'], 2)
        eq_(r['objects'][0]['questions'], 3)

        # Verify locale=pt-BR
        r = self._get_api_result('api.kpi.questions', locale='pt-BR')
        eq_(r['objects'][0]['questions'], 1)
        assert 'solved' not in r['objects'][0]
        assert 'responded_24' not in r['objects'][0]
        assert 'responded_72' not in r['objects'][0]