Update test addon creation to work better with new amo frontend. (#7334)
These changes help compatibility with the new amo frontend for integration testing. * Create 2 new collections under the username 'Mozilla'. * Change the status of the installable addon to Public. * Allow for custom named extensions and collections. * Added 3 lists to ease updates of the tests as the new homepage changes.
This commit is contained in:
Родитель
440c96a32d
Коммит
cb1550301e
|
@ -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')
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"""
|
||||
try:
|
||||
rating = self.find_element(*self._rating_locator).text
|
||||
return int(rating.split()[1])
|
||||
except NoSuchElementException:
|
||||
return 0
|
||||
|
|
|
@ -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)
|
||||
|
|
Загрузка…
Ссылка в новой задаче