def test_basic(self): user_with_themes = user_factory() user_with_extensions = user_factory() user_with_both = user_factory() user_factory(is_public=True) # marked as public, but no addons. extension = addon_factory(users=(user_with_extensions, user_with_both)) theme = addon_factory(type=amo.ADDON_STATICTHEME, users=(user_with_themes, user_with_both)) sitemap = AccountSitemap() items = list(sitemap.items()) assert items == [ ( theme.last_updated, reverse('users.profile', args=[user_with_both.id]), 1, 1, ), ( theme.last_updated, reverse('users.profile', args=[user_with_themes.id]), 1, 1, ), ( extension.last_updated, reverse('users.profile', args=[user_with_extensions.id]), 1, 1, ), ]
def test_accounts_sitemap(): user_with_themes = user_factory() user_with_extensions = user_factory() user_with_both = user_factory() user_factory() # no addons extension = addon_factory(users=(user_with_extensions, user_with_both)) theme = addon_factory(type=amo.ADDON_STATICTHEME, users=(user_with_themes, user_with_both)) sitemap = AccountSitemap() items = list(sitemap.items()) assert items == [ (theme.last_updated, user_with_both.id, 1, 1), (theme.last_updated, user_with_themes.id, 1, 1), (extension.last_updated, user_with_extensions.id, 1, 1), ] for item in sitemap.items(): assert sitemap.location(item) == reverse('users.profile', args=[item.id]) # add some extra extensions and themes to test pagination extra_extension_a = addon_factory(users=(user_with_extensions, user_with_both)) extra_extension_b = addon_factory(users=(user_with_extensions, user_with_both)) extra_theme_a = addon_factory(type=amo.ADDON_STATICTHEME, users=(user_with_themes, user_with_both)) extra_theme_b = addon_factory(type=amo.ADDON_STATICTHEME, users=(user_with_themes, user_with_both)) extra_theme_c = addon_factory(type=amo.ADDON_STATICTHEME, users=(user_with_themes, user_with_both)) with mock.patch('olympia.amo.sitemap.EXTENSIONS_BY_AUTHORS_PAGE_SIZE', 2), mock.patch( 'olympia.amo.sitemap.THEMES_BY_AUTHORS_PAGE_SIZE', 3): sitemap = AccountSitemap() paginated_items = list(sitemap.items()) assert paginated_items == [ (extra_theme_c.last_updated, user_with_both.id, 1, 1), (extra_theme_c.last_updated, user_with_both.id, 2, 1), (extra_theme_c.last_updated, user_with_both.id, 1, 2), (extra_theme_c.last_updated, user_with_themes.id, 1, 1), (extra_theme_c.last_updated, user_with_themes.id, 1, 2), (extra_extension_b.last_updated, user_with_extensions.id, 1, 1), (extra_extension_b.last_updated, user_with_extensions.id, 2, 1), ] # repeat, but after changing some of the addons so they wouldn't be visible with mock.patch('olympia.amo.sitemap.EXTENSIONS_BY_AUTHORS_PAGE_SIZE', 2), mock.patch( 'olympia.amo.sitemap.THEMES_BY_AUTHORS_PAGE_SIZE', 3): extra_theme_a.update(status=amo.STATUS_NOMINATED) sitemap = AccountSitemap() assert list(sitemap.items()) == [ # now only one page of themes for both users (extra_theme_c.last_updated, user_with_both.id, 1, 1), (extra_theme_c.last_updated, user_with_both.id, 2, 1), (extra_theme_c.last_updated, user_with_themes.id, 1, 1), (extra_extension_b.last_updated, user_with_extensions.id, 1, 1), (extra_extension_b.last_updated, user_with_extensions.id, 2, 1), ] user_with_both.addonuser_set.filter(addon=extra_extension_a).update( listed=False) assert list(sitemap.items()) == [ (extra_theme_c.last_updated, user_with_both.id, 1, 1), (extra_theme_c.last_updated, user_with_themes.id, 1, 1), (extra_extension_b.last_updated, user_with_extensions.id, 1, 1), # user_with_extensions still has 2 pages of extensions though (extra_extension_b.last_updated, user_with_extensions.id, 2, 1), ] extra_theme_c.delete() assert list(sitemap.items()) == [ # the date used for lastmod has changed (extra_theme_b.last_updated, user_with_both.id, 1, 1), (extra_theme_b.last_updated, user_with_themes.id, 1, 1), (extra_extension_b.last_updated, user_with_extensions.id, 1, 1), # user_with_extensions still has 2 pages of extensions though (extra_extension_b.last_updated, user_with_extensions.id, 2, 1), ] # and check that deleting roles works too user_with_both.addonuser_set.filter(addon=extra_theme_b).update( role=amo.AUTHOR_ROLE_DELETED) assert list(sitemap.items()) == [ # the date used for lastmod has changed, and the order too (extra_theme_b.last_updated, user_with_themes.id, 1, 1), (extra_extension_b.last_updated, user_with_both.id, 1, 1), (extra_extension_b.last_updated, user_with_extensions.id, 1, 1), (extra_extension_b.last_updated, user_with_extensions.id, 2, 1), ]
def test_android(self): # users with just themes on Android won't be included user_with_themes = user_factory() user_with_extensions = user_factory() user_with_both = user_factory() user_factory(is_public=True) # marked as public, but no addons. extension = addon_factory( users=(user_with_extensions, user_with_both), version_kw={'application': amo.ANDROID.id}, ) self.make_addon_promoted(extension, RECOMMENDED, approve_version=True) extra_extension_a = addon_factory( users=(user_with_extensions, user_with_both), version_kw={'application': amo.ANDROID.id}, ) self.make_addon_promoted(extra_extension_a, RECOMMENDED, approve_version=True) extra_extension_b = addon_factory( users=(user_with_extensions, user_with_both), version_kw={'application': amo.ANDROID.id}, ) # and some addons that should be ignored addon_factory( type=amo.ADDON_STATICTHEME, users=(user_with_themes, user_with_both), version_kw={'application': amo.ANDROID.id}, ) addon_factory( type=amo.ADDON_STATICTHEME, users=(user_with_themes, user_with_both), version_kw={'application': amo.ANDROID.id}, ) firefox_addon = addon_factory( type=amo.ADDON_EXTENSION, users=(user_with_extensions, user_with_both), version_kw={'application': amo.FIREFOX.id}, ) self.make_addon_promoted(firefox_addon, RECOMMENDED, approve_version=True) # there would be 3 addons but one of them isn't promoted with override_url_prefix(app_name='android'): assert list(AccountSitemap().items()) == [ ( extra_extension_a.last_updated, reverse('users.profile', args=[user_with_both.id]), 1, 1, ), ( extra_extension_a.last_updated, reverse('users.profile', args=[user_with_extensions.id]), 1, 1, ), ] self.make_addon_promoted(extra_extension_b, RECOMMENDED, approve_version=True) with override_url_prefix(app_name='android'): assert list(AccountSitemap().items()) == [ ( extra_extension_b.last_updated, reverse('users.profile', args=[user_with_both.id]), 1, 1, ), ( extra_extension_b.last_updated, reverse('users.profile', args=[user_with_both.id]), 2, 1, ), ( extra_extension_b.last_updated, reverse('users.profile', args=[user_with_extensions.id]), 1, 1, ), ( extra_extension_b.last_updated, reverse('users.profile', args=[user_with_extensions.id]), 2, 1, ), ] # delete user_with_both from extra_extension_b user_with_both.addonuser_set.filter(addon=extra_extension_b).update( role=amo.AUTHOR_ROLE_DELETED) with override_url_prefix(app_name='android'): assert list(AccountSitemap().items()) == [ ( extra_extension_b.last_updated, reverse('users.profile', args=[user_with_extensions.id]), 1, 1, ), ( extra_extension_b.last_updated, reverse('users.profile', args=[user_with_extensions.id]), 2, 1, ), ( extra_extension_a.last_updated, reverse('users.profile', args=[user_with_both.id]), 1, 1, ), ]
def test_pagination(self): user_with_themes = user_factory() user_with_extensions = user_factory() user_with_both = user_factory() user_factory(is_public=True) # marked as public, but no addons. addon_factory(users=(user_with_extensions, user_with_both)) addon_factory(type=amo.ADDON_STATICTHEME, users=(user_with_themes, user_with_both)) extra_extension_a = addon_factory(users=(user_with_extensions, user_with_both)) extra_extension_b = addon_factory(users=(user_with_extensions, user_with_both)) extra_theme_a = addon_factory(type=amo.ADDON_STATICTHEME, users=(user_with_themes, user_with_both)) extra_theme_b = addon_factory(type=amo.ADDON_STATICTHEME, users=(user_with_themes, user_with_both)) extra_theme_c = addon_factory(type=amo.ADDON_STATICTHEME, users=(user_with_themes, user_with_both)) sitemap = AccountSitemap() paginated_items = list(sitemap.items()) assert paginated_items == [ ( extra_theme_c.last_updated, reverse('users.profile', args=[user_with_both.id]), 1, 1, ), ( extra_theme_c.last_updated, reverse('users.profile', args=[user_with_both.id]), 2, 1, ), ( extra_theme_c.last_updated, reverse('users.profile', args=[user_with_both.id]), 1, 2, ), ( extra_theme_c.last_updated, reverse('users.profile', args=[user_with_themes.id]), 1, 1, ), ( extra_theme_c.last_updated, reverse('users.profile', args=[user_with_themes.id]), 1, 2, ), ( extra_extension_b.last_updated, reverse('users.profile', args=[user_with_extensions.id]), 1, 1, ), ( extra_extension_b.last_updated, reverse('users.profile', args=[user_with_extensions.id]), 2, 1, ), ] # repeat, but after changing some of the addons so they wouldn't be visible extra_theme_a.update(status=amo.STATUS_NOMINATED) assert list(AccountSitemap().items()) == [ # now only one page of themes for both users ( extra_theme_c.last_updated, reverse('users.profile', args=[user_with_both.id]), 1, 1, ), ( extra_theme_c.last_updated, reverse('users.profile', args=[user_with_both.id]), 2, 1, ), ( extra_theme_c.last_updated, reverse('users.profile', args=[user_with_themes.id]), 1, 1, ), ( extra_extension_b.last_updated, reverse('users.profile', args=[user_with_extensions.id]), 1, 1, ), ( extra_extension_b.last_updated, reverse('users.profile', args=[user_with_extensions.id]), 2, 1, ), ] user_with_both.addonuser_set.filter(addon=extra_extension_a).update( listed=False) assert list(AccountSitemap().items()) == [ ( extra_theme_c.last_updated, reverse('users.profile', args=[user_with_both.id]), 1, 1, ), ( extra_theme_c.last_updated, reverse('users.profile', args=[user_with_themes.id]), 1, 1, ), ( extra_extension_b.last_updated, reverse('users.profile', args=[user_with_extensions.id]), 1, 1, ), # user_with_extensions still has 2 pages of extensions though ( extra_extension_b.last_updated, reverse('users.profile', args=[user_with_extensions.id]), 2, 1, ), ] extra_theme_c.delete() assert list(AccountSitemap().items()) == [ # the date used for lastmod has changed ( extra_theme_b.last_updated, reverse('users.profile', args=[user_with_both.id]), 1, 1, ), ( extra_theme_b.last_updated, reverse('users.profile', args=[user_with_themes.id]), 1, 1, ), ( extra_extension_b.last_updated, reverse('users.profile', args=[user_with_extensions.id]), 1, 1, ), # user_with_extensions still has 2 pages of extensions though ( extra_extension_b.last_updated, reverse('users.profile', args=[user_with_extensions.id]), 2, 1, ), ] # and check that deleting roles works too user_with_both.addonuser_set.filter(addon=extra_theme_b).update( role=amo.AUTHOR_ROLE_DELETED) assert list(AccountSitemap().items()) == [ # the date used for lastmod has changed, and the order too ( extra_theme_b.last_updated, reverse('users.profile', args=[user_with_themes.id]), 1, 1, ), ( extra_extension_b.last_updated, reverse('users.profile', args=[user_with_both.id]), 1, 1, ), ( extra_extension_b.last_updated, reverse('users.profile', args=[user_with_extensions.id]), 1, 1, ), ( extra_extension_b.last_updated, reverse('users.profile', args=[user_with_extensions.id]), 2, 1, ), ]