Merge pull request #1142 from muffinresearch/update-cron-enable-new-regions-916843

Remove paid app region command and update cron to use enable_new_regions (bug 916843)
This commit is contained in:
Stuart Colville 2013-09-27 11:35:33 -07:00
Родитель 1bb5a3816b 5bf111a40d
Коммит eeeb1ec998
5 изменённых файлов: 21 добавлений и 114 удалений

Просмотреть файл

@ -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)

Просмотреть файл

@ -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 = '<region_slug>'
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()

Просмотреть файл

@ -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') }}

Просмотреть файл

@ -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):

Просмотреть файл

@ -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])