Example #1
0
    def test_advanced_search_questions_num_votes(self):
        """Tests advanced search for questions num_votes filter"""
        q = question(title=u"tags tags tags", save=True)

        # Add two question votes
        questionvote(question=q, save=True)
        questionvote(question=q, save=True)

        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"),
            {"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"),
            {"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)
Example #2
0
    def test_advanced_search_questions_num_votes(self):
        """Tests advanced search for questions num_votes filter"""
        q = question(title=u'tags tags tags', save=True)

        # Add two question votes
        questionvote(question=q, save=True)
        questionvote(question=q, save=True)

        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'), {
            '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'), {
            '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)
Example #3
0
    def test_advanced_search_questions_num_votes(self):
        """Tests advanced search for questions num_votes filter"""
        q = question(title=u'tags tags tags', save=True)

        # Add two question votes
        questionvote(question=q, save=True)
        questionvote(question=q, save=True)

        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'), {
            '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'), {
            '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)
Example #4
0
    def test_vote_updates_count(self):
        q = question(save=True)
        eq_(0, q.num_votes_past_week)

        questionvote(question=q, anonymous_id='abc123', save=True)

        q = Question.uncached.get(id=q.id)
        eq_(1, q.num_votes_past_week)
Example #5
0
    def test_vote_updates_count(self):
        q = question(save=True)
        eq_(0, q.num_votes_past_week)

        questionvote(question=q, anonymous_id='abc123', save=True)

        q = Question.uncached.get(id=q.id)
        eq_(1, q.num_votes_past_week)
Example #6
0
    def test_num_votes_none(self):
        """Tests num_voted filtering where num_votes is ''"""
        q = question(save=True)
        questionvote(question=q, save=True)

        self.refresh()

        qs = {"q": "", "w": 2, "a": 1, "num_voted": 2, "num_votes": ""}
        response = self.client.get(reverse("search"), qs)
        eq_(200, response.status_code)
Example #7
0
    def test_num_votes_none(self):
        """Tests num_voted filtering where num_votes is ''"""
        q = question(save=True)
        questionvote(question=q, save=True)

        self.refresh()

        qs = {'q': '', 'w': 2, 'a': 1, 'num_voted': 2, 'num_votes': ''}
        response = self.client.get(reverse('search'), qs)
        eq_(200, response.status_code)
Example #8
0
 def test_helpful_double_vote(self):
     q = question(save=True)
     u = profile().user
     questionvote(question=q, creator=u, save=True)
     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)
Example #9
0
 def test_helpful_double_vote(self):
     q = question(save=True)
     u = profile().user
     questionvote(question=q, creator=u, save=True)
     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)
Example #10
0
    def test_num_votes_none(self):
        """Tests num_voted filtering where num_votes is ''"""
        q = question(save=True)
        questionvote(question=q, save=True)

        self.refresh()

        qs = {'q': '', 'w': 2, 'a': 1, 'num_voted': 2, 'num_votes': ''}
        response = self.client.get(reverse('search'), qs)
        eq_(200, response.status_code)
Example #11
0
    def test_cron_updates_counts(self):
        q = question(save=True)
        eq_(0, q.num_votes_past_week)

        questionvote(question=q, anonymous_id='abc123', save=True)

        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)
Example #12
0
    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 = question(title=u'model makers will inherit the earth', save=True)
        self.refresh()
        eq_(search.filter(question_num_votes__gt=0).count(), 0)

        # Add a QuestionVote--it should show up now.
        questionvote(question=q, save=True)
        self.refresh()
        eq_(search.filter(question_num_votes__gt=0).count(), 1)
Example #13
0
    def test_cron_updates_counts(self):
        q = question(save=True)
        eq_(0, q.num_votes_past_week)

        questionvote(question=q, anonymous_id='abc123', save=True)

        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)
Example #14
0
    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 = question(title=u'model makers will inherit the earth', save=True)
        self.refresh()
        eq_(search.filter(question_num_votes__gt=0).count(), 0)

        # Add a QuestionVote--it should show up now.
        questionvote(question=q, save=True)
        self.refresh()
        eq_(search.filter(question_num_votes__gt=0).count(), 1)
Example #15
0
    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 = (QuestionMappingType.search().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 = (QuestionMappingType.search().filter(id=q.id))[0]

        eq_(document['question_num_votes_past_week'], 1)
Example #16
0
    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 = (QuestionMappingType.search()
                    .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 = (QuestionMappingType.search()
                    .filter(id=q.id))[0]

        eq_(document['question_num_votes_past_week'], 1)
Example #17
0
    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 = question(save=True)
        questionvote(question=q1, save=True)
        q1.num_votes_past_week = 1
        q1.save()

        q2 = question(save=True)

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

        questionvote(question=q2, save=True)
        questionvote(question=q2, save=True)
        qs = Question.uncached.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.uncached.all().order_by('-num_votes_past_week')
        eq_(q2.pk, qs[0].pk)
Example #18
0
    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 = question(save=True)
        questionvote(question=q1, save=True)
        q1.num_votes_past_week = 1
        q1.save()

        q2 = question(save=True)

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

        questionvote(question=q2, save=True)
        questionvote(question=q2, save=True)
        qs = Question.uncached.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.uncached.all().order_by("-num_votes_past_week")
        eq_(q2.pk, qs[0].pk)
Example #19
0
 def test_with_votes(self):
     questionvote(question=self.question, save=True)
     questionvote(question=self.question, save=True)
     questionvote(save=True)
     serializer = api.QuestionSerializer(instance=self.question)
     eq_(serializer.data['num_votes'], 2)
Example #20
0
 def test_add_metadata_over_1000_chars(self):
     qv = questionvote(save=True)
     qv.add_metadata('test1', 'a' * 1001)
     metadata = VoteMetadata.objects.all()[0]
     eq_('a' * 1000, metadata.value)
Example #21
0
 def test_add_metadata_over_1000_chars(self):
     qv = questionvote(save=True)
     qv.add_metadata('test1', 'a'*1001)
     metadata = VoteMetadata.objects.all()[0]
     eq_('a'*1000, metadata.value)
Example #22
0
 def test_with_votes(self):
     questionvote(question=self.question, save=True)
     questionvote(question=self.question, save=True)
     questionvote(save=True)
     serializer = api.QuestionSerializer(instance=self.question)
     eq_(serializer.data['num_votes'], 2)