Created
April 30, 2012 07:04
-
-
Save cvan/2556137 to your computer and use it in GitHub Desktop.
better app_factory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/apps/amo/tests/__init__.py b/apps/amo/tests/__init__.py | |
index 893e59f..0e6c299 100644 | |
--- a/apps/amo/tests/__init__.py | |
+++ b/apps/amo/tests/__init__.py | |
@@ -326,8 +326,20 @@ def assert_no_validation_errors(validation): | |
def app_factory(**kw): | |
- kw.update(type=amo.ADDON_WEBAPP) | |
- return amo.tests.addon_factory(**kw) | |
+ popularity = kw.pop('popularity', None) | |
+ a = Addon(type=amo.ADDON_WEBAPP, status=amo.STATUS_PUBLIC) | |
+ junk = ''.join(random.sample(map(chr, range(65, 123)), 10)) | |
+ a.name = name = 'webapp %s' % junk | |
+ a.slug = name.replace(' ', '-').lower() | |
+ a.bayesian_rating = random.uniform(1, 5) | |
+ a.average_daily_users = popularity or random.randint(200, 2000) | |
+ a.weekly_downloads = popularity or random.randint(200, 2000) | |
+ a.created = a.last_updated = datetime(2011, 6, 6, random.randint(0, 23), | |
+ random.randint(0, 59)) | |
+ for key, value in kw.items(): | |
+ setattr(a, key, value) | |
+ a.save() | |
+ return a | |
def addon_factory(version_kw={}, file_kw={}, **kw): | |
@@ -347,8 +359,9 @@ def addon_factory(version_kw={}, file_kw={}, **kw): | |
a.weekly_downloads = popularity or random.randint(200, 2000) | |
a.created = a.last_updated = datetime(2011, 6, 6, random.randint(0, 23), | |
random.randint(0, 59)) | |
- version_factory(file_kw, addon=a, **version_kw) # Save 2. | |
- a.update_version() | |
+ if type_ != amo.ADDON_WEBAPP: | |
+ version_factory(file_kw, addon=a, **version_kw) # Save 2. | |
+ a.update_version() | |
a.status = amo.STATUS_PUBLIC | |
for key, value in kw.items(): | |
setattr(a, key, value) | |
diff --git a/apps/users/models.py b/apps/users/models.py | |
index 33cfc82..beeb5bd 100644 | |
--- a/apps/users/models.py | |
+++ b/apps/users/models.py | |
@@ -166,8 +166,8 @@ class UserProfile(amo.models.OnChangeMixin, amo.models.ModelBase): | |
@amo.cached_property | |
def apps_listed(self): | |
"""Public apps this user is listed as author of.""" | |
- return self.addons.reviewed().filter(type=amo.ADDON_WEBAPP, | |
- addonuser__user=self, addonuser__listed=True) | |
+ return self.addons.filter(type=amo.ADDON_WEBAPP, | |
+ status=amo.STATUS_PUBLIC, addonuser__listed=True) | |
def my_addons(self, n=8): | |
"""Returns n addons (anything not a webapp)""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment