diff --git a/src/olympia/landfill/management/commands/generate_ui_test_addons.py b/src/olympia/landfill/management/commands/generate_ui_test_addons.py index d771728ea1..111b98fe5d 100644 --- a/src/olympia/landfill/management/commands/generate_ui_test_addons.py +++ b/src/olympia/landfill/management/commands/generate_ui_test_addons.py @@ -6,6 +6,36 @@ from django.test.utils import override_settings from olympia.landfill.serializers import GenerateAddonsSerializer +# Featured collections on the homepage. +# Needs to be updated as the homepage is updated +featured_collections = [ + 'dynamic-media-downloaders', +] + +# Featured collections on the homepage. +base_collections = [ + 'bookmark-managers', + 'password-managers', + 'ad-blockers', + 'smarter-shopping', + 'be-more-productive', + 'watching-videos', +] + +# Addons that exist in the carousel. +# Needs to be updated as the homepage is updated +carousel_addons = [ + 'wikipedia-context-menu-search', + 'momentumdash', + 'undo-close-tab-button', + 'grammarly-1', + 'facebook-filter', + 'gesturefy', + 'multi-account-containers', + 'tree-style-tab', + 'lastpass-password-manager', +] + class Command(BaseCommand): """ @@ -30,7 +60,14 @@ class Command(BaseCommand): serializer.create_featured_theme() serializer.create_featured_collections() serializer.create_featured_themes() + for addon in featured_collections: + serializer.create_a_named_collection_and_addon( + addon, author='mozilla') + for addon in base_collections: + serializer.create_a_named_collection_and_addon( + addon, author='mozilla') + for addon in carousel_addons: + serializer.create_named_addon_with_author(addon) serializer.create_installable_addon() - cache.clear() call_command('clear_cache') diff --git a/src/olympia/landfill/serializers.py b/src/olympia/landfill/serializers.py index 05299672f9..4e9c6f8379 100644 --- a/src/olympia/landfill/serializers.py +++ b/src/olympia/landfill/serializers.py @@ -20,6 +20,7 @@ from olympia.constants.base import ( ) from olympia.landfill.collection import generate_collection from olympia.landfill.generators import generate_themes +from olympia.landfill.user import generate_user from olympia.files.tests.test_helpers import get_file from olympia.ratings.models import Rating from olympia.users.models import UserProfile @@ -40,6 +41,37 @@ class GenerateAddonsSerializer(serializers.Serializer): AddonUser.objects.create( user=user_factory(), addon=addon_factory()) + def create_named_addon_with_author(self, name, author=None): + """Create a generic addon and a user. + + The user will be created if a user is not given. + + """ + + if author is None: + author = user_factory() + try: + generate_user(author) + except Exception: # django.db.utils.IntegrityError + # If the user is already made, use that same user, + # if not use created user + addon = addon_factory( + status=STATUS_PUBLIC, + users=[UserProfile.objects.get(username=author)], + name=u'{}'.format(name), + slug='{}'.format(name), + ) + addon.save() + else: + addon = addon_factory( + status=STATUS_PUBLIC, + users=[UserProfile.objects.get(username=author.username)], + name=u'{}'.format(name), + slug='{}'.format(name), + ) + addon.save() + return addon + def create_featured_addon_with_version(self): """Creates a custom addon named 'Ui-Addon'. @@ -199,6 +231,17 @@ class GenerateAddonsSerializer(serializers.Serializer): addon = addon_factory(status=STATUS_PUBLIC, type=ADDON_PERSONA) generate_collection(addon, app=FIREFOX) + def create_a_named_collection_and_addon(self, name, author): + """Creates a collection with a name and author.""" + + generate_collection( + self.create_named_addon_with_author(name, author=author), + app=FIREFOX, + author=UserProfile.objects.get(username=author), + type=amo.COLLECTION_FEATURED, + name=name + ) + def create_installable_addon(self): activate('en-US') @@ -241,3 +284,6 @@ class GenerateAddonsSerializer(serializers.Serializer): # And let's create a new version for that upload. create_version_for_upload( upload.addon, upload, amo.RELEASE_CHANNEL_LISTED) + + # Change status to public + addon.update(status=amo.STATUS_PUBLIC) diff --git a/tests/ui/pages/desktop/search.py b/tests/ui/pages/desktop/search.py index d89beeaf5a..5ae197f7e1 100644 --- a/tests/ui/pages/desktop/search.py +++ b/tests/ui/pages/desktop/search.py @@ -1,4 +1,5 @@ from pypom import Region +from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.common.by import By from base import Base @@ -46,5 +47,8 @@ class SearchResultList(Base): @property def rating(self): """Returns the rating""" - rating = self.find_element(*self._rating_locator).text - return int(rating.split()[1]) + try: + rating = self.find_element(*self._rating_locator).text + return int(rating.split()[1]) + except NoSuchElementException: + return 0 diff --git a/tests/ui/test_home.py b/tests/ui/test_home.py index 1b5495a3d7..4fbf6bfd4f 100644 --- a/tests/ui/test_home.py +++ b/tests/ui/test_home.py @@ -67,4 +67,4 @@ def test_that_clicking_see_all_collections_link_works( page = Home(selenium, base_url).open() collections = page.featured_collections.collections collections_page = page.featured_collections.see_all() - assert len(collections) == len(collections_page.collections) + assert len(collections_page.collections) >= len(collections)