From 5bf111a40dd45430a1cdb4e3a68e008c501f9eff Mon Sep 17 00:00:00 2001 From: Stuart Colville Date: Mon, 16 Sep 2013 15:32:48 +0000 Subject: [PATCH] Remove paid app region command and update cron to use enable_new_regions (bug 916843) --- mkt/developers/cron.py | 15 ++-- .../email_developers_about_new_paid_region.py | 27 -------- .../emails/new_payments_region.html | 8 --- mkt/developers/tests/test_commands.py | 69 +------------------ mkt/developers/tests/test_cron.py | 16 +++-- 5 files changed, 21 insertions(+), 114 deletions(-) delete mode 100644 mkt/developers/management/commands/email_developers_about_new_paid_region.py delete mode 100644 mkt/developers/templates/developers/emails/new_payments_region.html diff --git a/mkt/developers/cron.py b/mkt/developers/cron.py index 3cdd3ab617..e16d7a05ab 100644 --- a/mkt/developers/cron.py +++ b/mkt/developers/cron.py @@ -18,10 +18,11 @@ def _region_email(ids, regions): def send_new_region_emails(regions): """Email app developers notifying them of new regions added.""" excluded = (AddonExcludedRegion.objects - .filter(region__in=[r.id for r in regions] + - [mkt.regions.WORLDWIDE.id]) + .filter(region__in=[r.id for r in regions]) .values_list('addon', flat=True)) - ids = Webapp.objects.exclude(id__in=excluded).values_list('id', flat=True) + ids = (Webapp.objects.exclude(id__in=excluded) + .filter(enable_new_regions=True) + .values_list('id', flat=True)) _region_email(ids, regions) @@ -37,6 +38,10 @@ def exclude_new_region(regions): Update regional blacklist for app developers who opted out of being automatically added to new regions. """ - ids = (AddonExcludedRegion.objects.values_list('addon', flat=True) - .filter(region=mkt.regions.WORLDWIDE.id)) + excluded = (AddonExcludedRegion.objects + .filter(region__in=[r.id for r in regions]) + .values_list('addon', flat=True)) + ids = (Webapp.objects.exclude(id__in=excluded) + .filter(enable_new_regions=False) + .values_list('id', flat=True)) _region_exclude(ids, regions) diff --git a/mkt/developers/management/commands/email_developers_about_new_paid_region.py b/mkt/developers/management/commands/email_developers_about_new_paid_region.py deleted file mode 100644 index 9540bb777f..0000000000 --- a/mkt/developers/management/commands/email_developers_about_new_paid_region.py +++ /dev/null @@ -1,27 +0,0 @@ -from django.core.management.base import BaseCommand, CommandError - -from celery.task.sets import TaskSet - -import amo -from amo.utils import chunked -from mkt.constants.regions import REGIONS_CHOICES_SLUG -from mkt.developers.tasks import new_payments_region_email -from mkt.webapps.models import Webapp - - -class Command(BaseCommand): - help = 'Email developers of public paid apps about a newly added region.' - args = '' - - def handle(self, *args, **options): - if len(args) != 1: - regions = ', '.join(dict(REGIONS_CHOICES_SLUG[1:]).keys()) - raise CommandError(('You must enter a single region slug. ' - 'Available choices: %s' % regions)) - region_slug = args[0] - ids = (Webapp.objects.filter(premium_type__in=amo.ADDON_HAS_PAYMENTS) - .exclude(status__in=amo.WEBAPPS_EXCLUDED_STATUSES) - .values_list('id', flat=True)) - ts = [new_payments_region_email.subtask(args=[chunk, region_slug]) - for chunk in chunked(ids, 100)] - TaskSet(ts).apply_async() diff --git a/mkt/developers/templates/developers/emails/new_payments_region.html b/mkt/developers/templates/developers/emails/new_payments_region.html deleted file mode 100644 index 758e4c0e68..0000000000 --- a/mkt/developers/templates/developers/emails/new_payments_region.html +++ /dev/null @@ -1,8 +0,0 @@ -{{ _('Dear App Developer,') }} - -{{ _("We've added a new payments region to the Firefox Marketplace. The Marketplace will soon be accepting payments for") }} {{ region }}. - -{{ _('If you would like your app,') }} {{ app }}, {{ _('to be available in that region you will need to visit the Firefox Marketplace Developer Hub and update your app settings on the "Compatibility & Payments" page:') }} {{ payments_url }} - -{{ _('Thanks,') }} -{{ _('Firefox Marketplace Team') }} diff --git a/mkt/developers/tests/test_commands.py b/mkt/developers/tests/test_commands.py index 355470fc51..74b7de2f16 100644 --- a/mkt/developers/tests/test_commands.py +++ b/mkt/developers/tests/test_commands.py @@ -1,76 +1,11 @@ # -*- coding: utf-8 -*- -from django.core import mail -from django.core.management.base import CommandError - -from nose.tools import eq_, raises +from nose.tools import eq_ import amo import amo.tests from addons.models import Addon, AddonPremium -from mkt.developers.management.commands import (cleanup_addon_premium, - email_developers_about_new_paid_region) +from mkt.developers.management.commands import cleanup_addon_premium from mkt.site.fixtures import fixture -from mkt.webapps.models import Webapp - - -class TestCommand(amo.tests.TestCase): - fixtures = fixture('webapp_337141') - - def test_email_developers_about_new_paid_region(self): - app = Webapp.objects.get(id=337141) - app.update(premium_type=amo.ADDON_PREMIUM) - email_developers_about_new_paid_region.Command().handle('uk') - msg = mail.outbox[0] - eq_(msg.subject, - '%s: United Kingdom region added to the Firefox Marketplace' - % app.name) - - def test_email_developers_locale(self): - app = Webapp.objects.get(id=337141) - app.update(premium_type=amo.ADDON_PREMIUM) - author = app.authors.all()[0] - eq_(author.lang, None) - email_developers_about_new_paid_region.Command().handle('uk') - msg = mail.outbox[0] - eq_(msg.subject, - (u'Something Something Steamcube!: United Kingdom region added ' - u'to the Firefox Marketplace')) - assert 'payments for United Kingdom' in msg.body - assert 'your app, Something Something Steamcube!' in msg.body - - mail.outbox = [] - author.update(lang=u'es') - email_developers_about_new_paid_region.Command().handle('uk') - msg = mail.outbox[0] - eq_(msg.subject, - (u'Algo Algo Steamcube!: Reino Unido regiĆ³n agregada a ' - u'Firefox Marketplace')) - assert u'pagos para Reino Unido' in msg.body - assert u'tu aplicaciĆ³n Algo Algo Steamcube!' in msg.body - - def test_email_developers_about_new_paid_region_with_pending_status(self): - app = Webapp.objects.get(id=337141) - app.update(premium_type=amo.ADDON_PREMIUM, status=amo.STATUS_PENDING) - email_developers_about_new_paid_region.Command().handle('uk') - msg = mail.outbox[0] - eq_(msg.subject, - '%s: United Kingdom region added to the Firefox Marketplace' - % app.name) - - def test_email_developers_about_new_paid_region_without_premium(self): - Webapp.objects.get(id=337141).update(premium_type=amo.ADDON_FREE) - email_developers_about_new_paid_region.Command().handle('uk') - eq_(len(mail.outbox), 0) - - def test_email_developers_about_new_paid_region_with_rejected_status(self): - Webapp.objects.get(id=337141).update(premium_type=amo.ADDON_PREMIUM, - status=amo.STATUS_REJECTED) - email_developers_about_new_paid_region.Command().handle('uk') - eq_(len(mail.outbox), 0) - - @raises(CommandError) - def test_email_developers_about_new_paid_region_without_region(self): - email_developers_about_new_paid_region.Command().handle() class TestCommandViews(amo.tests.TestCase): diff --git a/mkt/developers/tests/test_cron.py b/mkt/developers/tests/test_cron.py index f018e47d26..b5b1551dd0 100644 --- a/mkt/developers/tests/test_cron.py +++ b/mkt/developers/tests/test_cron.py @@ -12,6 +12,7 @@ class TestSendNewRegionEmails(amo.tests.WebappTestCase): @mock.patch('mkt.developers.cron._region_email') def test_called(self, _region_email_mock): + self.app.update(enable_new_regions=True) send_new_region_emails([mkt.regions.UK]) eq_(list(_region_email_mock.call_args_list[0][0][0]), [self.app.id]) @@ -24,9 +25,9 @@ class TestSendNewRegionEmails(amo.tests.WebappTestCase): eq_(list(_region_email_mock.call_args_list[0][0][0]), []) @mock.patch('mkt.developers.cron._region_email') - def test_not_called_with_future_exclusions(self, _region_email_mock): - AddonExcludedRegion.objects.create(addon=self.app, - region=mkt.regions.WORLDWIDE.id) + def test_not_called_with_enable_new_regions_false(self, _region_email_mock): + # Check enable_new_regions is False by default. + eq_(self.app.enable_new_regions, False) send_new_region_emails([mkt.regions.UK]) eq_(list(_region_email_mock.call_args_list[0][0][0]), []) @@ -34,7 +35,8 @@ class TestSendNewRegionEmails(amo.tests.WebappTestCase): class TestExcludeNewRegion(amo.tests.WebappTestCase): @mock.patch('mkt.developers.cron._region_exclude') - def test_not_called_by_default(self, _region_exclude_mock): + def test_not_called_enable_new_regions_true(self, _region_exclude_mock): + self.app.update(enable_new_regions=True) exclude_new_region([mkt.regions.UK]) eq_(list(_region_exclude_mock.call_args_list[0][0][0]), []) @@ -47,8 +49,8 @@ class TestExcludeNewRegion(amo.tests.WebappTestCase): eq_(list(_region_exclude_mock.call_args_list[0][0][0]), []) @mock.patch('mkt.developers.cron._region_exclude') - def test_called_with_future_exclusions(self, _region_exclude_mock): - AddonExcludedRegion.objects.create(addon=self.app, - region=mkt.regions.WORLDWIDE.id) + def test_called_with_enable_new_regions_false(self, _region_exclude_mock): + # Check enable_new_regions is False by default. + eq_(self.app.enable_new_regions, False) exclude_new_region([mkt.regions.UK]) eq_(list(_region_exclude_mock.call_args_list[0][0][0]), [self.app.id])