def test_basic(self): sitemap = AddonSitemap() items = list(sitemap.items()) assert items == self.expected for item in sitemap.items(): assert sitemap.location(item) == item.url assert '/en-US/firefox/' in sitemap.location(item) assert sitemap.lastmod(item) == item.last_updated
def test_basic(self): sitemap = AddonSitemap() items = list(sitemap.items()) assert items == self.expected for item in sitemap.items(): assert sitemap.location(item) == reverse( 'addons.' + item.urlname, args=[item.slug] ) assert '/en-US/firefox/' in sitemap.location(item) assert sitemap.lastmod(item) == item.last_updated
def test_addon_sitemap(): it = AddonSitemap.item_tuple addon_a = addon_factory(slug='addon-a') addon_b = addon_factory(slug='addon-b') addon_b.update(last_updated=datetime(2020, 1, 1, 1, 1, 1)) addon_c = addon_factory(slug='addon-c') addon_factory(status=amo.STATUS_NOMINATED) # shouldn't show up expected = [ it(addon_c.last_updated, addon_c.slug, 'detail', 1), it(addon_a.last_updated, addon_a.slug, 'detail', 1), it(addon_b.last_updated, addon_b.slug, 'detail', 1), it(addon_c.last_updated, addon_c.slug, 'versions', 1), it(addon_a.last_updated, addon_a.slug, 'versions', 1), it(addon_b.last_updated, addon_b.slug, 'versions', 1), it(addon_c.last_updated, addon_c.slug, 'ratings.list', 1), it(addon_a.last_updated, addon_a.slug, 'ratings.list', 1), it(addon_b.last_updated, addon_b.slug, 'ratings.list', 1), ] sitemap = AddonSitemap() items = list(sitemap.items()) assert items == expected for item in sitemap.items(): assert sitemap.location(item) == reverse( 'addons.' + item.urlname, args=[item.slug] ) assert '/en-US/firefox/' in sitemap.location(item) assert sitemap.lastmod(item) == item.last_updated # add some ratings to test the rating page pagination rating_factory(addon_c) rating_factory(addon_c) rating_factory(addon_c) rating_factory(addon_a) rating_factory(addon_a) # only 2 for addon_a patched_drf_setting = dict(settings.REST_FRAMEWORK) patched_drf_setting['PAGE_SIZE'] = 2 sitemap = AddonSitemap() with override_settings(REST_FRAMEWORK=patched_drf_setting): items_with_ratings = list(sitemap.items()) # only one extra url, for a second ratings page, because PAGE_SIZE = 2 extra_rating = it(addon_c.last_updated, addon_c.slug, 'ratings.list', 2) assert extra_rating in items_with_ratings assert set(items_with_ratings) - set(expected) == {extra_rating} item = items_with_ratings[-3] assert sitemap.location(item).endswith('/reviews/?page=2') assert sitemap.lastmod(item) == item.last_updated
def test_addon_sitemap(): addon_a = addon_factory() addon_b = addon_factory() addon_c = addon_factory() addon_b.update(last_updated=datetime.datetime(2020, 1, 1, 1, 1, 1)) addon_factory(status=amo.STATUS_NOMINATED) # shouldn't show up sitemap = AddonSitemap() assert list(sitemap.items()) == [ (addon_c.last_updated, addon_c.slug), (addon_a.last_updated, addon_a.slug), (addon_b.last_updated, addon_b.slug), ] for item in sitemap.items(): assert sitemap.location(item) == reverse('addons.detail', args=[item.slug]) assert '/en-US/firefox/' in sitemap.location(item) assert sitemap.lastmod(item) == item.last_updated
def test_rating_pagination(self): # add some ratings to test the rating page pagination rating_factory(self.addon_c) rating_factory(self.addon_c) rating_factory(self.addon_c) rating_factory(self.addon_a) rating_factory(self.addon_a) # only 2 for addon_a patched_drf_setting = dict(settings.REST_FRAMEWORK) patched_drf_setting['PAGE_SIZE'] = 2 sitemap = AddonSitemap() with override_settings(REST_FRAMEWORK=patched_drf_setting): items_with_ratings = list(sitemap.items()) # only one extra url, for a second ratings page, because PAGE_SIZE = 2 extra_rating = AddonSitemap.item_tuple( self.addon_c.last_updated, self.addon_c.slug, 'ratings.list', 2 ) assert extra_rating in items_with_ratings assert set(items_with_ratings) - set(self.expected) == {extra_rating} item = items_with_ratings[-3] assert sitemap.location(item).endswith('/reviews/?page=2') assert sitemap.lastmod(item) == item.last_updated
def test_addon_sitemap(): it = AddonSitemap.item_tuple addon_a = addon_factory( slug='addon-a', privacy_policy='privacy!', eula='eula!', version_kw={'license': license_factory()}, ) # addon_factory generates licenses by default, but always with a builtin >0 addon_b = addon_factory(slug='addon-b') addon_b.update(last_updated=datetime.datetime(2020, 1, 1, 1, 1, 1)) addon_c = addon_factory( slug='addon-c', eula='only eula', version_kw={'license': license_factory(builtin=1)}, ) addon_d = addon_factory(slug='addon-d', privacy_policy='only privacy') # throw in an edge case of an empty policy in a non-default locale Translation.objects.create(id=addon_d.privacy_policy_id, localized_string='', locale='fr') addon_e = addon_factory(slug='addon-e', eula='', privacy_policy='') # empty addon_factory(status=amo.STATUS_NOMINATED) # shouldn't show up sitemap = AddonSitemap() expected = [ it(addon_e.last_updated, addon_e.slug, 'detail', 1), it(addon_d.last_updated, addon_d.slug, 'detail', 1), it(addon_c.last_updated, addon_c.slug, 'detail', 1), it(addon_a.last_updated, addon_a.slug, 'detail', 1), it(addon_b.last_updated, addon_b.slug, 'detail', 1), it(addon_d.last_updated, addon_d.slug, 'privacy', 1), it(addon_a.last_updated, addon_a.slug, 'privacy', 1), it(addon_c.last_updated, addon_c.slug, 'eula', 1), it(addon_a.last_updated, addon_a.slug, 'eula', 1), it(addon_a.last_updated, addon_a.slug, 'license', 1), it(addon_e.last_updated, addon_e.slug, 'ratings.list', 1), it(addon_d.last_updated, addon_d.slug, 'ratings.list', 1), it(addon_c.last_updated, addon_c.slug, 'ratings.list', 1), it(addon_a.last_updated, addon_a.slug, 'ratings.list', 1), it(addon_b.last_updated, addon_b.slug, 'ratings.list', 1), ] items = list(sitemap.items()) assert items == expected for item in sitemap.items(): assert sitemap.location(item) == reverse('addons.' + item.urlname, args=[item.slug]) assert '/en-US/firefox/' in sitemap.location(item) assert sitemap.lastmod(item) == item.last_updated # add some ratings to test the rating page pagination rating_factory(addon_c) rating_factory(addon_c) rating_factory(addon_c) rating_factory(addon_a) rating_factory(addon_a) # only 2 for addon_a patched_drf_setting = dict(settings.REST_FRAMEWORK) patched_drf_setting['PAGE_SIZE'] = 2 with override_settings(REST_FRAMEWORK=patched_drf_setting): items_with_ratings = list(sitemap.items()) # only one extra url, for a second ratings page, because PAGE_SIZE = 2 extra_rating = it(addon_c.last_updated, addon_c.slug, 'ratings.list', 2) assert extra_rating in items_with_ratings assert set(items_with_ratings) - set(expected) == {extra_rating} item = items_with_ratings[-3] assert sitemap.location(item).endswith('/reviews/?page=2') assert sitemap.lastmod(item) == item.last_updated