Skip to content
This repository was archived by the owner on Mar 15, 2018. It is now read-only.

Commit 6cec953

Browse files
committed
fix AttributeError traceback upon saving new review: Spam.add (bug 771706)
1 parent c44f4f0 commit 6cec953

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

apps/reviews/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,18 @@ class Spam(object):
175175
def add(self, review, reason):
176176
reason = 'amo:review:spam:%s' % reason
177177
try:
178-
reasonset = cache.get('amo:review:spam:reasons')
178+
reasonset = cache.get('amo:review:spam:reasons', set())
179179
except KeyError:
180180
reasonset = set()
181181
try:
182-
idset = cache.get(reason)
182+
idset = cache.get(reason, set())
183183
except KeyError:
184184
idset = set()
185185
reasonset.add(reason)
186186
cache.set('amo:review:spam:reasons', reasonset)
187187
idset.add(review.id)
188188
cache.set(reason, idset)
189-
189+
return True
190190

191191
def reasons(self):
192192
return cache.get('amo:review:spam:reasons')

apps/reviews/tests/test_models.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
import amo.tests
77
from reviews import tasks
8-
from reviews.models import Review, GroupedRating, check_spam
8+
from reviews.models import check_spam, Review, GroupedRating, Spam
99

1010

1111
class TestReviewModel(amo.tests.TestCase):
12-
fixtures = ['base/apps', 'reviews/test_models.json']
12+
fixtures = ['base/apps', 'reviews/test_models']
1313

1414
def test_translations(self):
1515
translation.activate('en-US')
@@ -34,7 +34,7 @@ def test_translations(self):
3434

3535

3636
class TestGroupedRating(amo.tests.TestCase):
37-
fixtures = ['base/apps', 'reviews/dev-reply.json']
37+
fixtures = ['base/apps', 'reviews/dev-reply']
3838

3939
def test_get_none(self):
4040
eq_(GroupedRating.get(3), None)
@@ -51,8 +51,12 @@ def test_cron(self):
5151

5252

5353
class TestSpamTest(amo.tests.TestCase):
54-
# TODO: couldn't find tests covering spam, check coverage?
54+
fixtures = ['reviews/test_models']
5555

5656
def test_create_not_there(self):
57-
assert not Review.objects.count()
57+
Review.objects.all().delete()
58+
eq_(Review.objects.count(), 0)
5859
check_spam(1)
60+
61+
def test_add(self):
62+
assert Spam().add(Review.objects.all()[0], 'ball so hard')

0 commit comments

Comments
 (0)