Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
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 = 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)
Ejemplo n.º 6
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 = 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)