Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[bug 708783] Fix calls to karma manager from Answer.

  • Loading branch information...
commit 0c42ad462b57a308469e7958f4ab9a8d368a625c 1 parent 5ebc305
@rlr rlr authored
View
1  apps/karma/tests/test_actions.py
@@ -1,4 +1,5 @@
from datetime import date
+
import mock
from nose import SkipTest
from nose.tools import eq_
View
4 apps/questions/models.py
@@ -369,7 +369,7 @@ def creator_num_answers(self):
if waffle.switch_is_active('karma'):
try:
return KarmaAction.objects.count(
- self.creator, AnswerAction.action_type)
+ user=self.creator, type=AnswerAction.action_type)
except ConnectionError:
pass
return Answer.objects.filter(creator=self.creator).count()
@@ -381,7 +381,7 @@ def creator_num_solutions(self):
if waffle.switch_is_active('karma'):
try:
return KarmaAction.objects.count(
- self.creator, SolutionAction.action_type)
+ user=self.creator, type=SolutionAction.action_type)
except ConnectionError:
pass
return Question.objects.filter(
View
28 apps/questions/tests/test_models.py
@@ -1,12 +1,17 @@
from django.contrib.auth.models import User
+import mock
+from nose import SkipTest
from nose.tools import eq_, raises
-
-import sumo.models
from taggit.models import Tag
+import waffle
from flagit.models import FlaggedObject
+from karma.manager import KarmaManager
+import sumo.models
+from sumo.redis_utils import RedisError, redis_client
from questions.events import QuestionReplyEvent
+from questions.karma_actions import SolutionAction, AnswerAction
from questions.models import (Question, QuestionMetaData, Answer,
_tenths_version, _has_beta)
from questions.tasks import update_answer_pages
@@ -144,6 +149,25 @@ def test_creator_num_solutions(self):
eq_(answer.creator_num_solutions, 1)
+ @mock.patch.object(waffle, 'switch_is_active')
+ def test_creator_nums_redis(self, switch_is_active):
+ """Test creator_num_* pulled from karma data."""
+ try:
+ KarmaManager()
+ redis_client('karma').flushdb()
+ except RedisError:
+ raise SkipTest
+
+ switch_is_active.return_value = True
+ answer = Answer.objects.all()[0]
+
+ AnswerAction(answer.creator).save()
+ AnswerAction(answer.creator).save()
+ SolutionAction(answer.creator).save()
+
+ eq_(answer.creator_num_solutions, 1)
+ eq_(answer.creator_num_answers, 2)
+
class TestQuestionMetadata(TestCaseBase):
"""Tests handling question metadata"""
Please sign in to comment.
Something went wrong with that request. Please try again.