Commit 1bb23a13 by Nimisha Asthagiri

Move test_site_config into the schedules management command base test class

parent 81da729a
......@@ -83,56 +83,6 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
@patch.object(tasks, 'ace')
@patch.object(tested_task, 'async_send_task')
@ddt.data(
((['filtered_org'], [], 1)),
(([], ['filtered_org'], 2))
)
@ddt.unpack
def test_site_config(self, this_org_list, other_org_list, expected_message_count, mock_schedule_send, mock_ace):
filtered_org = 'filtered_org'
unfiltered_org = 'unfiltered_org'
this_config = SiteConfigurationFactory.create(values={'course_org_filter': this_org_list})
other_config = SiteConfigurationFactory.create(values={'course_org_filter': other_org_list})
for config in (this_config, other_config):
ScheduleConfigFactory.create(site=config.site)
user1 = UserFactory.create(id=resolvers.RECURRING_NUDGE_NUM_BINS)
user2 = UserFactory.create(id=resolvers.RECURRING_NUDGE_NUM_BINS * 2)
ScheduleFactory.create(
start=datetime.datetime(2017, 8, 3, 17, 44, 30, tzinfo=pytz.UTC),
enrollment__course__org=filtered_org,
enrollment__user=user1,
)
ScheduleFactory.create(
start=datetime.datetime(2017, 8, 3, 17, 44, 30, tzinfo=pytz.UTC),
enrollment__course__org=unfiltered_org,
enrollment__user=user1,
)
ScheduleFactory.create(
start=datetime.datetime(2017, 8, 3, 17, 44, 30, tzinfo=pytz.UTC),
enrollment__course__org=unfiltered_org,
enrollment__user=user2,
)
test_datetime = datetime.datetime(2017, 8, 3, 17, tzinfo=pytz.UTC)
test_datetime_str = serialize(test_datetime)
expected_queries = NUM_QUERIES_WITH_MATCHES
if not this_org_list:
expected_queries += NUM_QUERIES_NO_ORG_LIST
with self.assertNumQueries(expected_queries, table_blacklist=WAFFLE_TABLES):
self.tested_task.apply(kwargs=dict(
site_id=this_config.site.id, target_day_str=test_datetime_str, day_offset=-3, bin_num=0
))
self.assertEqual(mock_schedule_send.apply_async.call_count, expected_message_count)
self.assertFalse(mock_ace.send.called)
@patch.object(tasks, 'ace')
@patch.object(tested_task, 'async_send_task')
def test_multiple_enrollments(self, mock_schedule_send, mock_ace):
user = UserFactory.create()
schedules = [
......
......@@ -77,61 +77,6 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase):
@patch.object(tasks, 'ace')
@patch.object(tested_task, 'async_send_task')
@ddt.data(
((['filtered_org'], [], 1)),
(([], ['filtered_org'], 2))
)
@ddt.unpack
def test_site_config(self, this_org_list, other_org_list, expected_message_count, mock_schedule_send, mock_ace):
filtered_org = 'filtered_org'
unfiltered_org = 'unfiltered_org'
this_config = SiteConfigurationFactory.create(values={'course_org_filter': this_org_list})
other_config = SiteConfigurationFactory.create(values={'course_org_filter': other_org_list})
for config in (this_config, other_config):
ScheduleConfigFactory.create(site=config.site)
user1 = UserFactory.create(id=resolvers.UPGRADE_REMINDER_NUM_BINS)
user2 = UserFactory.create(id=resolvers.UPGRADE_REMINDER_NUM_BINS * 2)
ScheduleFactory.create(
upgrade_deadline=datetime.datetime(2017, 8, 3, 17, 44, 30, tzinfo=pytz.UTC),
enrollment__course__org=filtered_org,
enrollment__course__self_paced=True,
enrollment__user=user1,
)
ScheduleFactory.create(
upgrade_deadline=datetime.datetime(2017, 8, 3, 17, 44, 30, tzinfo=pytz.UTC),
enrollment__course__org=unfiltered_org,
enrollment__course__self_paced=True,
enrollment__user=user1,
)
ScheduleFactory.create(
upgrade_deadline=datetime.datetime(2017, 8, 3, 17, 44, 30, tzinfo=pytz.UTC),
enrollment__course__org=unfiltered_org,
enrollment__course__self_paced=True,
enrollment__user=user2,
)
test_datetime = datetime.datetime(2017, 8, 3, 17, tzinfo=pytz.UTC)
test_datetime_str = serialize(test_datetime)
course_switch_queries = 1
org_switch_queries = 1
expected_queries = NUM_QUERIES_FIRST_MATCH + course_switch_queries + org_switch_queries
if not this_org_list:
expected_queries += NUM_QUERIES_NO_ORG_LIST
with self.assertNumQueries(expected_queries, table_blacklist=WAFFLE_TABLES):
self.tested_task.apply(kwargs=dict(
site_id=this_config.site.id, target_day_str=test_datetime_str, day_offset=-3, bin_num=0
))
self.assertEqual(mock_schedule_send.apply_async.call_count, expected_message_count)
self.assertFalse(mock_ace.send.called)
@patch.object(tasks, 'ace')
@patch.object(tested_task, 'async_send_task')
def test_multiple_enrollments(self, mock_schedule_send, mock_ace):
user = UserFactory.create()
schedules = [
......
......@@ -15,6 +15,7 @@ from openedx.core.djangoapps.schedules import resolvers, tasks
from openedx.core.djangoapps.schedules.tests.factories import ScheduleConfigFactory, ScheduleFactory
from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, FilteredQueryCountMixin
from student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
......@@ -214,3 +215,52 @@ class ScheduleBaseEmailTestBase(SharedModuleStoreTestCase):
self.assertTrue(mock_apply_async.called)
else:
self.assertFalse(mock_apply_async.called)
@patch.object(tasks, 'ace')
@ddt.data(
((['filtered_org'], [], 1)),
(([], ['filtered_org'], 2))
)
@ddt.unpack
def test_site_config(self, this_org_list, other_org_list, expected_message_count, mock_ace):
filtered_org = 'filtered_org'
unfiltered_org = 'unfiltered_org'
this_config = SiteConfigurationFactory.create(values={'course_org_filter': this_org_list})
other_config = SiteConfigurationFactory.create(values={'course_org_filter': other_org_list})
for config in (this_config, other_config):
ScheduleConfigFactory.create(site=config.site)
user1 = UserFactory.create(id=self.tested_task.num_bins)
user2 = UserFactory.create(id=self.tested_task.num_bins * 2)
current_day, offset, target_day = self._get_dates()
ScheduleFactory.create(
upgrade_deadline=target_day,
start=target_day,
enrollment__course__org=filtered_org,
enrollment__course__self_paced=True,
enrollment__user=user1,
)
ScheduleFactory.create(
upgrade_deadline=target_day,
start=target_day,
enrollment__course__org=unfiltered_org,
enrollment__course__self_paced=True,
enrollment__user=user1,
)
ScheduleFactory.create(
upgrade_deadline=target_day,
start=target_day,
enrollment__course__org=unfiltered_org,
enrollment__course__self_paced=True,
enrollment__user=user2,
)
with patch.object(self.tested_task, 'async_send_task') as mock_schedule_send:
self.tested_task.apply(kwargs=dict(
site_id=this_config.site.id, target_day_str=serialize(target_day), day_offset=offset, bin_num=0
))
self.assertEqual(mock_schedule_send.apply_async.call_count, expected_message_count)
self.assertFalse(mock_ace.send.called)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment