def generate_addons(num, owner, app_name, addon_type=ADDON_EXTENSION): """Generate `num` addons for the given `owner` and `app_name`.""" # Disconnect this signal given that we issue a reindex at the end. 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_type): # 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, type=addon_type) 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)
def create_featured_addon_with_version(self): """Creates a custom addon named 'Ui-Addon'. This addon will be a featured addon and will have a featured collecton attatched to it. It will belong to the user uitest. It has 1 preview, 5 reviews, and 2 authors. The second author is named 'ui-tester2'. It has a version number. """ default_icons = [x[0] for x in icons() if x[0].startswith('icon/')] addon = addon_factory( status=STATUS_APPROVED, type=ADDON_EXTENSION, average_daily_users=5000, users=[self.user], average_rating=5, description=u'My Addon description', file_kw={ 'hash': 'fakehash', 'platform': amo.PLATFORM_ALL.id, 'size': 42, }, guid=generate_addon_guid(), icon_type=random.choice(default_icons), name=u'Ui-Addon', public_stats=True, slug='ui-test-2', summary=u'My Addon summary', tags=[ 'some_tag', 'another_tag', 'ui-testing', 'selenium', 'python' ], total_ratings=500, weekly_downloads=9999999, developer_comments='This is a testing addon.', ) Preview.objects.create(addon=addon, position=1) Rating.objects.create(addon=addon, rating=5, user=user_factory()) Rating.objects.create(addon=addon, rating=5, user=user_factory()) Rating.objects.create(addon=addon, rating=5, user=user_factory()) Rating.objects.create(addon=addon, rating=5, user=user_factory()) Rating.objects.create(addon=addon, rating=5, user=user_factory()) Rating.objects.create(addon=addon, rating=5, user=user_factory()) Rating.objects.create(addon=addon, rating=5, user=user_factory()) Rating.objects.create(addon=addon, rating=5, user=user_factory()) AddonUser.objects.create(user=user_factory(username='******'), addon=addon, listed=True) addon.save() generate_collection(addon, app=FIREFOX) print('Created addon {0} for testing successfully'.format(addon.name))
def create_featured_android_addon(self): """Creates a custom addon named 'Ui-Addon-Android'. This addon will be a featured addon and will have a featured collecton attatched to it. It will belong to the user uitest. It has 1 preview, 2 reviews, and 1 authors. It is an Android addon. """ default_icons = [x[0] for x in icons() if x[0].startswith('icon/')] addon = addon_factory( status=amo.STATUS_APPROVED, type=ADDON_EXTENSION, average_daily_users=5656, users=[self.user], average_rating=5, description=u'My Addon description about ANDROID', file_kw={'is_webextension': True}, guid=generate_addon_guid(), icon_type=random.choice(default_icons), name=u'Ui-Addon-Android', public_stats=True, slug='ui-test-addon-android', summary=u'My Addon summary for Android', tags=[ 'some_tag', 'another_tag', 'ui-testing', 'selenium', 'python', 'android' ], total_ratings=500, weekly_downloads=9999999, developer_comments='This is a testing addon for Android.', version_kw={ 'recommendation_approved': True, 'nomination': days_ago(6) }) Preview.objects.create(addon=addon, position=1) Rating.objects.create(addon=addon, rating=5, user=user_factory()) Rating.objects.create(addon=addon, rating=5, user=user_factory()) AddonUser.objects.create(user=user_factory(username='******'), addon=addon, listed=True) addon.save() DiscoveryItem.objects.create(recommendable=True, addon=addon) generate_collection(addon, app=FIREFOX) print('Created addon {0} for testing successfully'.format(addon.name))
def create_featured_addon_with_version_for_install(self): """Creates a custom addon named 'Ui-Addon'. This addon will be a featured addon and will have a featured collecton attatched to it. It will belong to the user uitest. It has 1 preview, 5 reviews, and 2 authors. The second author is named 'ui-tester2'. It has a version number. """ default_icons = [x[0] for x in icons() if x[0].startswith('icon/')] try: addon = Addon.objects.get(guid='@webextension-guid') except Addon.DoesNotExist: addon = addon_factory( file_kw=False, average_daily_users=5000, users=[self.user], average_rating=5, description=u'My Addon description', guid='@webextension-guid', icon_type=random.choice(default_icons), name=u'Ui-Addon-Install', public_stats=True, slug='ui-test-install', summary=u'My Addon summary', tags=[ 'some_tag', 'another_tag', 'ui-testing', 'selenium', 'python' ], weekly_downloads=9999999, developer_comments='This is a testing addon.', version_kw={ 'recommendation_approved': True, 'nomination': days_ago(6) }, ) addon.save() generate_collection(addon, app=FIREFOX) DiscoveryItem.objects.create(recommendable=True, addon=addon) print('Created addon {0} for testing successfully'.format( addon.name)) return addon
def generate_addons(num, owner, app_name, addon_type=ADDON_EXTENSION): """Generate `num` addons for the given `owner` and `app_name`.""" # Disconnect this signal given that we issue a reindex at the end. 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_type): # 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, type=addon_type) 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)