def setup_featured_tools_and_extensions(self): # Pretend all Add-ons are search-related: Addon.objects.update(type=amo.ADDON_SEARCH) # One will be an extension in the search category: limon = Addon.objects.get( name__localized_string='Limon free English-Hebrew dictionary') limon.type = amo.ADDON_EXTENSION limon.status = amo.STATUS_PUBLIC limon.save() AppSupport(addon=limon, app_id=amo.FIREFOX.id).save() # Another will be a search add-on in the search category: readit = Addon.objects.get(name__localized_string='Read It Later') readit.type = amo.ADDON_SEARCH readit.status = amo.STATUS_PUBLIC readit.save() # Un-feature all others: Feature.objects.all().delete() # Feature foxy : foxy = Addon.objects.get(name__localized_string='FoxyProxy Standard') Feature(addon=foxy, application_id=amo.FIREFOX.id, start=datetime.now(), end=datetime.now() + timedelta(days=30)).save() # Feature Limon Dictionary and Read It Later as a category feature: s = Category.objects.get(slug='search-tools') s.addoncategory_set.add(AddonCategory(addon=limon, feature=True)) s.addoncategory_set.add(AddonCategory(addon=readit, feature=True)) s.save() reset_featured_addons()
def reset_featured_addons(self): from addons.cron import reset_featured_addons from addons.utils import FeaturedManager, CreaturedManager reset_featured_addons() # Clear the in-process caches. FeaturedManager.featured_ids.clear() CreaturedManager.creatured_ids.clear()
def _pre_setup(self): super(TestCase, self)._pre_setup() from addons.cron import reset_featured_addons from addons.utils import FeaturedManager, CreaturedManager reset_featured_addons() # Clear the in-process caches. FeaturedManager.featured_ids.clear() CreaturedManager.creatured_ids.clear()
def test_is_featured(self): self.assertContains(make_call("addon/5299", version=1.5), "<featured>0</featured>") c = CollectionAddon.objects.create(addon=Addon.objects.get(id=5299), collection=Collection.objects.create()) FeaturedCollection.objects.create( locale="ja", application=Application.objects.get(id=amo.FIREFOX.id), collection=c.collection ) FeaturedManager.redis().kv.clear() reset_featured_addons() for lang, app, result in [("ja", "firefox", 1), ("en-US", "firefox", 0), ("ja", "seamonkey", 0)]: self.assertContains( make_call("addon/5299", version=1.5, lang=lang, app=app), "<featured>%s</featured>" % result )
def test_edit_categories_disclaimer(self): """Ensure that there is a disclaimer for creatured add-ons.""" self._feature_addon() # TODO: remove this when NEW_FEATURES goes away. It's here because # build() was already called in setUp(). from addons.cron import reset_featured_addons reset_featured_addons() r = self.client.get(self.basic_edit_url) doc = pq(r.content) eq_(doc('#addon-categories-edit div.addon-app-cats').length, 0) eq_(doc('#addon-categories-edit > p').length, 2) eq_(doc('#addon-categories-edit p.addon-app-cats').text(), 'Firefox: %s' % unicode(Category.objects.get(id=22).name))
def test_is_featured(self): self.assertContains(make_call("addon/5299", version=1.5), "<featured>0</featured>") Feature.objects.create( addon_id=5299, start=datetime.now() - timedelta(days=10), end=datetime.now() + timedelta(days=10), application_id=amo.FIREFOX.id, locale="ja", ) reset_featured_addons() for lang, app, result in [("ja", "firefox", 1), ("en-US", "firefox", 0), ("ja", "seamonkey", 0)]: self.assertContains( make_call("addon/5299", version=1.5, lang=lang, app=app), "<featured>%s</featured>" % result )
def test_edit_categories_add_new_creatured(self): """Ensure that categories cannot be changed for creatured add-ons.""" self._feature_addon() # TODO: remove this when NEW_FEATURES goes away. It's here because # build() was already called in setUp(). from addons.cron import reset_featured_addons reset_featured_addons() self.cat_initial['categories'] = [22, 23] r = self.client.post(self.basic_edit_url, self.get_dict()) addon_cats = self.get_addon().categories.values_list('id', flat=True) eq_(r.context['cat_form'].errors[0]['categories'], ['Categories cannot be changed while your add-on is featured for ' 'this application.']) # This add-on's categories should not change. eq_(sorted(addon_cats), [22])
def test_is_featured(self): self.assertContains(make_call('addon/5299', version=1.5), '<featured>0</featured>') Feature.objects.create(addon_id=5299, start=datetime.now() - timedelta(days=10), end=datetime.now() + timedelta(days=10), application_id=amo.FIREFOX.id, locale='ja') reset_featured_addons() for lang, app, result in [('ja', 'firefox', 1), ('en-US', 'firefox', 0), ('ja', 'seamonkey', 0)]: self.assertContains(make_call('addon/5299', version=1.5, lang=lang, app=app), '<featured>%s</featured>' % result)
def test_edit_categories_add_new_creatured_admin(self): """Ensure that admins can change categories for creatured add-ons.""" assert self.client.login(username='******', password='******') self._feature_addon() from addons.cron import reset_featured_addons reset_featured_addons() r = self.client.get(self.basic_edit_url) doc = pq(r.content) eq_(doc('#addon-categories-edit div.addon-app-cats').length, 1) eq_(doc('#addon-categories-edit > p').length, 0) self.cat_initial['categories'] = [22, 23] r = self.client.post(self.basic_edit_url, self.get_dict()) addon_cats = self.get_addon().categories.values_list('id', flat=True) eq_('categories' in r.context['cat_form'].errors[0], False) # This add-on's categories should change. eq_(sorted(addon_cats), [22, 23])
def test_new_is_featured(self): self.assertContains(make_call('addon/5299', version=1.5), '<featured>0</featured>') c = CollectionAddon.objects.create( addon=Addon.objects.get(id=5299), collection=Collection.objects.create()) FeaturedCollection.objects.create(locale='ja', application=Application.objects.get(id=amo.FIREFOX.id), collection=c.collection) FeaturedManager.redis().kv.clear() reset_featured_addons() for lang, app, result in [('ja', 'firefox', 1), ('en-US', 'firefox', 0), ('ja', 'seamonkey', 0)]: self.assertContains(make_call('addon/5299', version=1.5, lang=lang, app=app), '<featured>%s</featured>' % result)
def test_is_featured(self): self.assertContains(make_call('addon/5299', version=1.5), '<featured>0</featured>') c = CollectionAddon.objects.create( addon=Addon.objects.get(id=5299), collection=Collection.objects.create()) FeaturedCollection.objects.create(locale='ja', application=Application.objects.get(id=amo.FIREFOX.id), collection=c.collection) FeaturedManager.redis().kv.clear() reset_featured_addons() for lang, app, result in [('ja', 'firefox', 1), ('en-US', 'firefox', 0), ('ja', 'seamonkey', 0)]: self.assertContains(make_call('addon/5299', version=1.5, lang=lang, app=app), '<featured>%s</featured>' % result)
def reset_featured_addons(self): from addons.cron import reset_featured_addons reset_featured_addons() cache.clear()
from addons.cron import reset_featured_addons print('here we go') reset_featured_addons()
def reset(self): cache.clear() FeaturedManager.redis().flushall() reset_featured_addons() FeaturedManager.featured_ids.clear() CreaturedManager.creatured_ids.clear()
from addons.cron import reset_featured_addons print 'here we go' reset_featured_addons()
def setUp(self): super(TestNewFeaturedLocale, self).setUp() patcher = mock.patch.object(settings, 'NEW_FEATURES', True) patcher.start() reset_featured_addons() self.addCleanup(patcher.stop)