Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
diff --git a/src/olympia/landfill/generators.py b/src/olympia/landfill/generators.py
index 9f268a3056..76c355b1b8 100644
--- a/src/olympia/landfill/generators.py
+++ b/src/olympia/landfill/generators.py
@@ -5,6 +5,7 @@ from itertools import cycle, islice
from django.db.models.signals import post_save
+from olympia import amo
from olympia.amo.utils import slugify
from olympia.addons.forms import icons
from olympia.addons.models import Addon, Persona, update_search_index
@@ -40,7 +41,7 @@ def _yield_name_and_cat(num, app=None, type=None):
yield (addon_name, cat)
-def create_addon(name, icon_type, application, **extra_kwargs):
+def create_addon(name, icon_type, application, release_channel, **extra_kwargs):
"""Create an addon with the given `name` and his version."""
kwargs = {
'status': STATUS_PUBLIC,
@@ -56,9 +57,8 @@ def create_addon(name, icon_type, application, **extra_kwargs):
kwargs.update(extra_kwargs)
addon = Addon.objects.create(type=ADDON_EXTENSION, **kwargs)
- generate_version(addon=addon, app=application)
+ generate_version(addon=addon, app=application, channel=release_channel)
addon.update_version()
- addon.status = STATUS_PUBLIC
addon.save()
return addon
@@ -69,24 +69,52 @@ def generate_addons(num, owner, app_name):
post_save.disconnect(update_search_index, sender=Addon,
dispatch_uid='addons.search.index')
- featured_categories = collections.defaultdict(int)
user = generate_user(owner)
app = APPS[app_name]
default_icons = [x[0] for x in icons() if x[0].startswith('icon/')]
- for name, category in _yield_name_and_cat(
- num, app=app, type=ADDON_EXTENSION):
- # Use one of the default icons at random.
- icon_type = random.choice(default_icons)
- addon = create_addon(name=name, icon_type=icon_type,
- application=app)
- generate_addon_user_and_category(addon, user, category)
- generate_addon_preview(addon)
- generate_translations(addon)
- # Only feature 5 addons per category at max.
- if featured_categories[category] < 5:
- generate_collection(addon, app)
- featured_categories[category] += 1
- generate_ratings(addon, 5)
+
+ states = [
+ (amo.RELEASE_CHANNEL_LISTED, amo.STATUS_NULL),
+ (amo.RELEASE_CHANNEL_LISTED, amo.STATUS_NOMINATED),
+ (amo.RELEASE_CHANNEL_LISTED, amo.STATUS_PUBLIC),
+ (amo.RELEASE_CHANNEL_LISTED, amo.STATUS_DISABLED),
+ (amo.RELEASE_CHANNEL_LISTED, amo.STATUS_DELETED),
+ (amo.RELEASE_CHANNEL_LISTED, amo.STATUS_REJECTED),
+ (amo.RELEASE_CHANNEL_LISTED, amo.STATUS_PENDING),
+ (amo.RELEASE_CHANNEL_UNLISTED, amo.STATUS_NULL),
+ ]
+
+ # for release_channel, addon_status in states:
+ # name, category = list(_yield_name_and_cat(1, app=app, type=ADDON_EXTENSION))[0]
+
+ # # Use one of the default icons at random.
+ # icon_type = random.choice(default_icons)
+
+ # addon = create_addon(name=name, icon_type=icon_type,
+ # application=app, release_channel=release_channel,
+ # status=addon_status)
+ # print(addon.status)
+ # generate_addon_user_and_category(addon, user, category)
+ # generate_addon_preview(addon)
+ # generate_translations(addon)
+
+ # # And one add-on that has versions in both channels
+
+ icon_type = random.choice(default_icons)
+
+ name, category = list(_yield_name_and_cat(1, app=app, type=ADDON_EXTENSION))[0]
+ addon = create_addon(name=name, icon_type=icon_type,
+ application=app, release_channel=amo.RELEASE_CHANNEL_LISTED)
+
+ generate_addon_user_and_category(addon, user, category)
+ generate_addon_preview(addon)
+ generate_translations(addon)
+
+ print('xxxxxxxxxxxxxxx', name)
+ generate_version(
+ addon=addon, app=app,
+ channel=amo.RELEASE_CHANNEL_UNLISTED)
+
def create_theme(name, **extra_kwargs):
diff --git a/src/olympia/landfill/version.py b/src/olympia/landfill/version.py
index e8acaf76e9..33345a0424 100644
--- a/src/olympia/landfill/version.py
+++ b/src/olympia/landfill/version.py
@@ -7,7 +7,7 @@ from olympia.files.models import File
from olympia.versions.models import ApplicationsVersions, Version
-def generate_version(addon, app=None):
+def generate_version(addon, app=None, channel=None):
"""
Generate a version for the given `addon` and the optional
`app`. The `app` is only useful for add-ons (not themes),
@@ -19,6 +19,8 @@ def generate_version(addon, app=None):
max_app_version = '50.0'
version = '%.1f' % random.uniform(0, 2)
v = Version.objects.create(addon=addon, version=version)
+ if channel is not None:
+ v.channel = channel
v.created = v.last_updated = datetime.now()
v.save()
if app is not None: # Not for themes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment