From 068822db4a11a732656c46a933391ad7cf605040 Mon Sep 17 00:00:00 2001 From: Jeff Balogh Date: Tue, 22 Jun 2010 10:51:29 -0700 Subject: [PATCH] make sure we're returning distinct user add-ons (bug 573774) --- apps/users/models.py | 4 ++-- apps/users/tests/test_models.py | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/users/models.py b/apps/users/models.py index bc923a4226..2270028296 100644 --- a/apps/users/models.py +++ b/apps/users/models.py @@ -79,8 +79,8 @@ class UserProfile(amo.models.ModelBase): @amo.cached_property def addons_listed(self): - """public add-ons this user is listed as author of""" - return self.addons.valid().filter(addonuser__listed=True) + """Public add-ons this user is listed as author of.""" + return self.addons.valid().filter(addonuser__listed=True).distinct() @property def name(self): diff --git a/apps/users/tests/test_models.py b/apps/users/tests/test_models.py index ad323f5684..147308a3d5 100644 --- a/apps/users/tests/test_models.py +++ b/apps/users/tests/test_models.py @@ -7,7 +7,7 @@ from django.core import mail from nose.tools import eq_ -from addons.models import Addon +from addons.models import Addon, AddonUser from reviews.models import Review from users.models import UserProfile, get_hexdigest @@ -108,6 +108,13 @@ class TestUserProfile(test.TestCase): assert new_reply.pk not in review_list, ( 'Developer reply must not show up in review list.') + def test_addons_listed(self): + """Make sure we're returning distinct add-ons.""" + AddonUser.objects.create(addon_id=3615, user_id=2519, listed=True) + u = UserProfile.objects.get(id=2519) + addons = u.addons_listed.values_list('id', flat=True) + eq_(sorted(addons), [3615, 4664]) + class TestPasswords(test.TestCase):