Addon.objects.valid_q returns a Q object for finding valid add-ons

This commit is contained in:
Jeff Balogh 2010-07-27 16:43:22 -07:00
Родитель 9d8422aca9
Коммит 02f92c9f4a
12 изменённых файлов: 154 добавлений и 34 удалений

Просмотреть файл

@ -37,16 +37,15 @@ class AddonManager(amo.models.ManagerBase):
def public(self):
"""Get public add-ons only"""
return self.filter(inactive=False, status=amo.STATUS_PUBLIC)
return self.filter(self.valid_q([amo.STATUS_PUBLIC]))
def unreviewed(self):
"""Get only unreviewed add-ons"""
return self.filter(inactive=False,
status__in=amo.UNREVIEWED_STATUSES)
return self.filter(self.valid_q(amo.UNREVIEWED_STATUSES))
def valid(self):
"""Get valid, enabled add-ons only"""
return self.filter(status__in=amo.VALID_STATUSES, inactive=False)
return self.filter(self.valid_q(amo.VALID_STATUSES))
def featured(self, app):
"""
@ -68,9 +67,26 @@ class AddonManager(amo.models.ManagerBase):
if len(status) == 0:
status = [amo.STATUS_PUBLIC]
hasver = Q(type=amo.ADDON_PERSONA) | Q(_current_version__isnull=False)
return self.filter(hasver, appsupport__app=app.id,
inactive=False, status__in=status)
return self.filter(self.valid_q(status), appsupport__app=app.id)
def valid_q(self, status=[], prefix=''):
"""
Return a Q object that selects a valid Addon with the given statuses.
An add-on is valid if it's not inactive and has a current version.
``prefix`` can be used if you're not working with Addon directly and
need to hop across a join, e.g. ``prefix='addon__'`` in
CollectionAddon.
"""
if not status:
status = [amo.STATUS_PUBLIC]
def q(*args, **kw):
if prefix:
kw = dict((prefix + k, v) for k, v in kw.items())
return Q(*args, **kw)
return q(q(type=amo.ADDON_PERSONA) | q(_current_version__isnull=False),
inactive=False, status__in=status)
class Addon(amo.models.ModelBase):

Просмотреть файл

@ -5,6 +5,7 @@ from pyquery import PyQuery
import test_utils
import amo
import amo.test_utils
from amo.urlresolvers import reverse
from addons.buttons import install_button
@ -429,8 +430,8 @@ class TestButtonHtml(ButtonTest):
eq_(doc('.contrib .os').text(), '')
class TestViews(test_utils.TestCase):
fixtures = ['addons/eula+contrib-addon']
class TestViews(amo.test_utils.ExtraSetup, test_utils.TestCase):
fixtures = ['addons/eula+contrib-addon', 'base/apps']
def test_eula_with_contrib_roadblock(self):
url = reverse('addons.eula', args=[11730, 53612])

Просмотреть файл

@ -99,7 +99,7 @@ class TestPromobox(test_utils.TestCase):
eq_(response.status_code, 200)
class TestContributeInstalled(test_utils.TestCase):
class TestContributeInstalled(amo.test_utils.ExtraSetup, test_utils.TestCase):
fixtures = ['base/fixtures']
def test_no_header_block(self):
@ -119,7 +119,7 @@ class TestContributeInstalled(test_utils.TestCase):
eq_(title[:37], 'Thank you for installing Gmail S/MIME')
class TestContribute(test_utils.TestCase):
class TestContribute(amo.test_utils.ExtraSetup, test_utils.TestCase):
fixtures = ['base/fixtures']
def test_invalid_is_404(self):
@ -237,8 +237,8 @@ class TestContribute(test_utils.TestCase):
assert r['Location'].startswith(settings.PAYPAL_CGI_URL)
class TestDeveloperPages(test_utils.TestCase):
fixtures = ['base/fixtures', 'addons/eula+contrib-addon']
class TestDeveloperPages(amo.test_utils.ExtraSetup, test_utils.TestCase):
fixtures = ['base/fixtures', 'addons/eula+contrib-addon', 'base/apps']
def test_meet_the_dev_title(self):
r = self.client.get(reverse('addons.meet', args=[592]))
@ -268,7 +268,7 @@ class TestDeveloperPages(test_utils.TestCase):
assert pq(r.content)('#contribute-button')
class TestDetailPage(test_utils.TestCase):
class TestDetailPage(amo.test_utils.ExtraSetup, test_utils.TestCase):
fixtures = ['base/fixtures', 'base/addon_59.json', 'addons/listed',
'addons/persona']
@ -540,8 +540,8 @@ class TestDetailPage(test_utils.TestCase):
for th in headings)
class TestTagsBox(test_utils.TestCase):
fixtures = ['base/addontag']
class TestTagsBox(amo.test_utils.ExtraSetup, test_utils.TestCase):
fixtures = ['base/addontag', 'base/apps']
def test_tag_box(self):
"""Verify that we don't show duplicate tags."""
@ -590,8 +590,8 @@ def test_unicode_redirect():
eq_(response.status_code, 301)
class TestEula(test_utils.TestCase):
fixtures = ['addons/eula+contrib-addon']
class TestEula(amo.test_utils.ExtraSetup, test_utils.TestCase):
fixtures = ['addons/eula+contrib-addon', 'base/apps']
def test_current_version(self):
addon = Addon.objects.get(id=11730)
@ -612,8 +612,8 @@ class TestEula(test_utils.TestCase):
self.assertRedirects(r, reverse('addons.detail', args=[11730]))
class TestPrivacyPolicy(test_utils.TestCase):
fixtures = ['addons/eula+contrib-addon']
class TestPrivacyPolicy(amo.test_utils.ExtraSetup, test_utils.TestCase):
fixtures = ['addons/eula+contrib-addon', 'base/apps']
def test_redirect_no_eula(self):
Addon.objects.filter(id=11730).update(privacy_policy=None)

Просмотреть файл

@ -0,0 +1,46 @@
[
{
"pk": 1,
"model": "applications.application",
"fields": {
"guid": "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}",
"modified": "2008-11-03 15:34:59",
"created": "2007-03-05 13:09:26"
}
},
{
"pk": 60,
"model": "applications.application",
"fields": {
"guid": "{a23983c0-fd0e-11dc-95ff-0800200c9a66}",
"modified": "2008-10-28 18:25:09",
"created": "2008-10-28 18:25:09"
}
},
{
"pk": 59,
"model": "applications.application",
"fields": {
"guid": "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}",
"modified": "2008-06-17 08:29:01",
"created": "2007-03-05 13:09:26"
}
},
{
"pk": 18,
"model": "applications.application",
"fields": {
"guid": "{3550f703-e582-4d05-9a08-453d09bdfdc6}",
"created": "2006-08-21 23:53:19"
}
},
{
"pk": 1,
"model": "files.platform",
"fields": {
"icontype": "",
"modified": "2008-04-07 08:16:55",
"created": "2007-03-05 13:09:27"
}
}
]

Просмотреть файл

@ -5076,6 +5076,35 @@
"notifyevents": 1
}
},
{
"pk": 592,
"model": "versions.version",
"fields": {
"license": 5,
"created": "2009-12-06 03:06:48",
"releasenotes": null,
"modified": "2009-12-06 06:43:48",
"approvalnotes": "",
"version": "1.32",
"addon": 592
}
},
{
"pk": 592,
"model": "files.file",
"fields": {
"status": 4,
"codereview": 0,
"hash": "sha256:fa8934ccfacc78cd35944ae1a1fd0b398f5644698e2f362358c711726e81737e",
"created": "2009-12-06 06:47:22",
"modified": "2010-01-14 14:15:29",
"filename": "gmail/mime-1.32-fx.xpi",
"platform": 1,
"version": 592,
"size": 110,
"datestatuschanged": "2010-01-14 14:15:28"
}
},
{
"pk": 86740,
"model": "versions.version",

Просмотреть файл

@ -1,17 +1,17 @@
# -*- coding: utf8 -*-
"""Check all our redirects from remora to zamboni."""
from django import test
from nose.tools import eq_
import test_utils
import amo
import amo.test_utils
from addons.models import Category
from applications.models import Application
class TestRedirects(test.TestCase):
class TestRedirects(amo.test_utils.ExtraSetup, test_utils.TestCase):
fixtures = ['reviews/test_models', 'base/global-stats']
fixtures = ['base/apps', 'reviews/test_models', 'base/global-stats']
def test_persona_category(self):
"""`/personas/film and tv` should go to /personas/film-and-tv"""

Просмотреть файл

@ -6,12 +6,13 @@ from django.http import QueryDict
from nose.tools import eq_
import test_utils
import amo.test_utils
from amo.urlresolvers import reverse
from bandwagon.models import Collection, CollectionVote
class TestViews(test_utils.TestCase):
fixtures = ['bandwagon/test_models.json']
class TestViews(amo.test_utils.ExtraSetup, test_utils.TestCase):
fixtures = ['bandwagon/test_models.json', 'base/apps']
def check_response(self, url, code, to=None):
response = self.client.get(url, follow=True)

Просмотреть файл

@ -117,5 +117,30 @@
"user": 1,
"reply_to": null
}
},
{
"pk": 592,
"model": "versions.version",
"fields": {
"license": null,
"created": "2009-12-06 03:06:48",
"modified": "2009-12-06 06:43:48",
"version": "1.32",
"addon": 4
}
},
{
"pk": 592,
"model": "files.file",
"fields": {
"status": 4,
"hash": "sha256:fa8934ccfacc78cd35944ae1a1fd0b398f5644698e2f362358c711726e81737e",
"created": "2009-12-06 06:47:22",
"modified": "2010-01-14 14:15:29",
"filename": "gmail/mime-1.32-fx.xpi",
"platform": 1,
"version": 592,
"datestatuschanged": "2010-01-14 14:15:28"
}
}
]

Просмотреть файл

@ -8,7 +8,7 @@ from reviews.models import Review, GroupedRating
class TestReviewModel(test_utils.TestCase):
fixtures = ['reviews/test_models.json']
fixtures = ['base/apps', 'reviews/test_models.json']
def test_translations(self):
translation.activate('en-US')

Просмотреть файл

@ -33,7 +33,7 @@ def test_parse_bad_type():
class PersonaSearchTest(SphinxTestCase):
fixtures = ['addons/persona']
fixtures = ['base/apps', 'addons/persona']
def get_response(self, **kwargs):
return self.client.get(reverse('search.search') +

Просмотреть файл

@ -7,13 +7,14 @@ from django.core import mail
from nose.tools import eq_
import amo.test_utils
from addons.models import Addon, AddonUser
from reviews.models import Review
from users.models import UserProfile, get_hexdigest, BlacklistedNickname
class TestUserProfile(test.TestCase):
fixtures = ['base/fixtures', 'users/test_backends']
class TestUserProfile(amo.test_utils.ExtraSetup, test.TestCase):
fixtures = ['base/fixtures', 'users/test_backends', 'base/apps']
def test_anonymize(self):
u = User.objects.get(id='4043307').get_profile()

Просмотреть файл

@ -4,6 +4,7 @@ import mock
import test_utils
import amo
import amo.test_utils
from amo.urlresolvers import reverse
from addons.models import Addon
from versions import views
@ -134,8 +135,8 @@ class TestLicense(test_utils.TestCase):
assert lic.text
class TestViews(test_utils.TestCase):
fixtures = ['addons/eula+contrib-addon']
class TestViews(amo.test_utils.ExtraSetup, test_utils.TestCase):
fixtures = ['addons/eula+contrib-addon', 'base/apps']
def setUp(self):
self.old_perpage = views.PER_PAGE
@ -172,8 +173,8 @@ class TestViews(test_utils.TestCase):
eq_(doc('.version').attr('id'), 'version-%s' % version)
class TestFeeds(test_utils.TestCase):
fixtures = ['addons/versions']
class TestFeeds(amo.test_utils.ExtraSetup, test_utils.TestCase):
fixtures = ['base/apps', 'addons/versions']
def test_feed_elements_present(self):
"""specific elements are present and reasonably well formed"""