2012-08-03 22:43:32 +04:00
|
|
|
import mock
|
2012-02-17 02:22:59 +04:00
|
|
|
from nose.tools import eq_
|
|
|
|
|
|
|
|
import amo.tests
|
2012-08-03 22:43:32 +04:00
|
|
|
|
|
|
|
import mkt
|
|
|
|
from mkt.developers.cron import exclude_new_region, send_new_region_emails
|
|
|
|
from mkt.webapps.models import AddonExcludedRegion
|
2012-02-17 02:22:59 +04:00
|
|
|
|
|
|
|
|
2012-08-03 22:43:32 +04:00
|
|
|
class TestSendNewRegionEmails(amo.tests.WebappTestCase):
|
|
|
|
|
|
|
|
@mock.patch('mkt.developers.cron._region_email')
|
|
|
|
def test_called(self, _region_email_mock):
|
2013-09-16 19:32:48 +04:00
|
|
|
self.app.update(enable_new_regions=True)
|
2013-01-15 08:26:55 +04:00
|
|
|
send_new_region_emails([mkt.regions.UK])
|
2012-08-03 22:43:32 +04:00
|
|
|
eq_(list(_region_email_mock.call_args_list[0][0][0]),
|
|
|
|
[self.app.id])
|
|
|
|
|
|
|
|
@mock.patch('mkt.developers.cron._region_email')
|
|
|
|
def test_not_called_with_exclusions(self, _region_email_mock):
|
|
|
|
AddonExcludedRegion.objects.create(addon=self.app,
|
2013-01-15 08:26:55 +04:00
|
|
|
region=mkt.regions.UK.id)
|
|
|
|
send_new_region_emails([mkt.regions.UK])
|
2012-08-03 22:43:32 +04:00
|
|
|
eq_(list(_region_email_mock.call_args_list[0][0][0]), [])
|
|
|
|
|
|
|
|
@mock.patch('mkt.developers.cron._region_email')
|
2013-09-16 19:32:48 +04:00
|
|
|
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)
|
2013-01-15 08:26:55 +04:00
|
|
|
send_new_region_emails([mkt.regions.UK])
|
2012-08-03 22:43:32 +04:00
|
|
|
eq_(list(_region_email_mock.call_args_list[0][0][0]), [])
|
|
|
|
|
|
|
|
|
|
|
|
class TestExcludeNewRegion(amo.tests.WebappTestCase):
|
|
|
|
|
|
|
|
@mock.patch('mkt.developers.cron._region_exclude')
|
2013-09-16 19:32:48 +04:00
|
|
|
def test_not_called_enable_new_regions_true(self, _region_exclude_mock):
|
|
|
|
self.app.update(enable_new_regions=True)
|
2013-01-15 08:26:55 +04:00
|
|
|
exclude_new_region([mkt.regions.UK])
|
2012-08-03 22:43:32 +04:00
|
|
|
eq_(list(_region_exclude_mock.call_args_list[0][0][0]),
|
|
|
|
[])
|
|
|
|
|
|
|
|
@mock.patch('mkt.developers.cron._region_exclude')
|
|
|
|
def test_not_called_with_ordinary_exclusions(self, _region_exclude_mock):
|
|
|
|
AddonExcludedRegion.objects.create(addon=self.app,
|
2013-01-15 08:26:55 +04:00
|
|
|
region=mkt.regions.UK.id)
|
|
|
|
exclude_new_region([mkt.regions.UK])
|
2012-08-03 22:43:32 +04:00
|
|
|
eq_(list(_region_exclude_mock.call_args_list[0][0][0]), [])
|
|
|
|
|
|
|
|
@mock.patch('mkt.developers.cron._region_exclude')
|
2013-09-16 19:32:48 +04:00
|
|
|
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)
|
2013-01-15 08:26:55 +04:00
|
|
|
exclude_new_region([mkt.regions.UK])
|
2012-08-03 22:43:32 +04:00
|
|
|
eq_(list(_region_exclude_mock.call_args_list[0][0][0]), [self.app.id])
|