コード例 #1
0
    def test_questions_num_votes(self):
        """Tests advanced search for questions num_votes filter"""
        q = QuestionFactory(title=u'tags tags tags')

        # Add two question votes
        QuestionVoteFactory(question=q)
        QuestionVoteFactory(question=q)

        self.refresh()

        # Advanced search for questions with num_votes > 5. The above
        # question should be not in this set.
        response = self.client.get(reverse('search.advanced'), {
            'q': '', 'tags': 'desktop', 'w': '2', 'a': '1',
            'num_voted': 2, 'num_votes': 5,
            'format': 'json'
        })

        eq_(200, response.status_code)

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

        # Advanced search for questions with num_votes < 1. The above
        # question should be not in this set.
        response = self.client.get(reverse('search.advanced'), {
            'q': '', 'tags': 'desktop', 'w': '2', 'a': '1',
            'num_voted': 1, 'num_votes': 1,
            'format': 'json'
        })

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content['total'], 0)
コード例 #2
0
ファイル: test_search_advanced.py プロジェクト: zu83/kitsune
    def test_questions_num_votes(self):
        """Tests advanced search for questions num_votes filter"""
        q = QuestionFactory(title="tags tags tags")

        # Add two question votes
        QuestionVoteFactory(question=q)
        QuestionVoteFactory(question=q)

        self.refresh()

        # Advanced search for questions with num_votes > 5. The above
        # question should be not in this set.
        response = self.client.get(
            reverse("search.advanced"),
            {
                "q": "",
                "tags": "desktop",
                "w": "2",
                "a": "1",
                "num_voted": 2,
                "num_votes": 5,
                "format": "json",
            },
        )

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content["total"], 0)

        # Advanced search for questions with num_votes < 1. The above
        # question should be not in this set.
        response = self.client.get(
            reverse("search.advanced"),
            {
                "q": "",
                "tags": "desktop",
                "w": "2",
                "a": "1",
                "num_voted": 1,
                "num_votes": 1,
                "format": "json",
            },
        )

        eq_(200, response.status_code)

        content = json.loads(response.content)
        eq_(content["total"], 0)
コード例 #3
0
ファイル: test_votes.py プロジェクト: yoyo2011/kitsune
    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)
コード例 #4
0
ファイル: test_votes.py プロジェクト: yoyo2011/kitsune
    def test_vote_updates_count(self):
        q = QuestionFactory()
        eq_(0, q.num_votes_past_week)

        QuestionVoteFactory(question=q, anonymous_id='abc123')

        q = Question.objects.get(id=q.id)
        eq_(1, q.num_votes_past_week)
コード例 #5
0
ファイル: test_search_advanced.py プロジェクト: zu83/kitsune
    def test_num_votes_none(self):
        """Tests num_voted filtering where num_votes is ''"""
        q = QuestionFactory()
        QuestionVoteFactory(question=q)

        self.refresh()

        qs = {"q": "", "w": 2, "a": 1, "num_voted": 2, "num_votes": ""}
        response = self.client.get(reverse("search.advanced"), qs)
        eq_(200, response.status_code)
コード例 #6
0
    def test_num_votes_none(self):
        """Tests num_voted filtering where num_votes is ''"""
        q = QuestionFactory()
        QuestionVoteFactory(question=q)

        self.refresh()

        qs = {'q': '', 'w': 2, 'a': 1, 'num_voted': 2, 'num_votes': ''}
        response = self.client.get(reverse('search.advanced'), qs)
        eq_(200, response.status_code)
コード例 #7
0
ファイル: test_api.py プロジェクト: pirateyporat/kitsune
 def test_helpful_double_vote(self):
     q = QuestionFactory()
     u = UserFactory()
     QuestionVoteFactory(question=q, creator=u)
     self.client.force_authenticate(user=u)
     res = self.client.post(reverse('question-helpful', args=[q.id]))
     eq_(res.status_code, 409)
     # It's 1, not 0, because one was created above. The failure cause is
     # if the number of votes is 2, one from above and one from the api call.
     eq_(Question.objects.get(id=q.id).num_votes, 1)
コード例 #8
0
ファイル: test_es.py プロジェクト: rootmeb/kitsune
    def test_question_questionvote(self):
        search = QuestionMappingType.search()

        # Create a question and verify it doesn't show up in a
        # query for num_votes__gt=0.
        q = QuestionFactory(title='model makers will inherit the earth')
        self.refresh()
        eq_(search.filter(question_num_votes__gt=0).count(), 0)

        # Add a QuestionVote--it should show up now.
        QuestionVoteFactory(question=q)
        self.refresh()
        eq_(search.filter(question_num_votes__gt=0).count(), 1)
コード例 #9
0
ファイル: test_votes.py プロジェクト: yoyo2011/kitsune
    def test_cron_updates_counts(self):
        q = QuestionFactory()
        eq_(0, q.num_votes_past_week)

        QuestionVoteFactory(question=q, anonymous_id='abc123')

        q.num_votes_past_week = 0
        q.save()

        update_weekly_votes()

        q = Question.objects.get(pk=q.pk)
        eq_(1, q.num_votes_past_week)
コード例 #10
0
ファイル: test_tasks.py プロジェクト: ziegeer/kitsune
    def test_update_question_vote_chunk(self):
        # Reset the num_votes_past_week counts, I suspect the data gets
        # loaded before I disconnect the signal and they get zeroed out.
        q1 = QuestionFactory()
        QuestionVoteFactory(question=q1)
        q1.num_votes_past_week = 1
        q1.save()

        q2 = QuestionFactory()

        # Actually test the task.
        qs = Question.objects.all().order_by('-num_votes_past_week')
        eq_(q1.pk, qs[0].pk)

        QuestionVoteFactory(question=q2)
        QuestionVoteFactory(question=q2)
        qs = Question.objects.all().order_by('-num_votes_past_week')
        eq_(q1.pk, qs[0].pk)

        update_question_vote_chunk([q.pk for q in qs])
        qs = Question.objects.all().order_by('-num_votes_past_week')
        eq_(q2.pk, qs[0].pk)
コード例 #11
0
    def test_vote_delete(self):
        vote = QuestionVoteFactory(question=self.question)
        vote.delete()

        self.assertEqual(self.get_doc().question_num_votes, 0)
コード例 #12
0
    def test_vote_save(self):
        QuestionVoteFactory(question=self.question)

        self.assertEqual(self.get_doc().question_num_votes, 1)
コード例 #13
0
ファイル: test_models.py プロジェクト: 1234-/kitsune
 def test_add_metadata_over_1000_chars(self):
     qv = QuestionVoteFactory()
     qv.add_metadata('test1', 'a'*1001)
     metadata = VoteMetadata.objects.all()[0]
     eq_('a'*1000, metadata.value)
コード例 #14
0
ファイル: test_models.py プロジェクト: rootmeb/kitsune
 def test_add_metadata_over_1000_chars(self):
     qv = QuestionVoteFactory()
     qv.add_metadata("test1", "a" * 1001)
     metadata = VoteMetadata.objects.all()[0]
     eq_("a" * 1000, metadata.value)
コード例 #15
0
ファイル: test_api.py プロジェクト: pirateyporat/kitsune
 def test_with_votes(self):
     QuestionVoteFactory(question=self.question)
     QuestionVoteFactory(question=self.question)
     QuestionVoteFactory()
     serializer = api.QuestionSerializer(instance=self.question)
     eq_(serializer.data['num_votes'], 2)