Move test_multiple_enrollments into the schedules management command base test class
This commit is contained in:
@@ -57,29 +57,6 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
|
||||
enqueue_config = 'enqueue_recurring_nudge'
|
||||
expected_offsets = (-3, -10)
|
||||
|
||||
@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 = [
|
||||
ScheduleFactory.create(
|
||||
start=datetime.datetime(2017, 8, 3, 19, 44, 30, tzinfo=pytz.UTC),
|
||||
enrollment__user=user,
|
||||
enrollment__course__id=CourseLocator('edX', 'toy', 'Course{}'.format(course_num))
|
||||
)
|
||||
for course_num in (1, 2, 3)
|
||||
]
|
||||
|
||||
test_datetime = datetime.datetime(2017, 8, 3, 19, 44, 30, tzinfo=pytz.UTC)
|
||||
test_datetime_str = serialize(test_datetime)
|
||||
with self.assertNumQueries(NUM_QUERIES_WITH_MATCHES + NUM_QUERIES_NO_ORG_LIST, table_blacklist=WAFFLE_TABLES):
|
||||
self.tested_task.apply(kwargs=dict(
|
||||
site_id=self.site_config.site.id, target_day_str=test_datetime_str, day_offset=-3,
|
||||
bin_num=user.id % resolvers.RECURRING_NUDGE_NUM_BINS,
|
||||
))
|
||||
self.assertEqual(mock_schedule_send.apply_async.call_count, 1)
|
||||
self.assertFalse(mock_ace.send.called)
|
||||
|
||||
@ddt.data(*itertools.product((1, 10, 100), (-3, -10)))
|
||||
@ddt.unpack
|
||||
def test_templates(self, message_count, day):
|
||||
|
||||
@@ -75,36 +75,6 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase):
|
||||
expiration_datetime=datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=30),
|
||||
)
|
||||
|
||||
@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 = [
|
||||
ScheduleFactory.create(
|
||||
upgrade_deadline=datetime.datetime(2017, 8, 3, 19, 44, 30, tzinfo=pytz.UTC),
|
||||
enrollment__user=user,
|
||||
enrollment__course__self_paced=True,
|
||||
enrollment__course__id=CourseLocator('edX', 'toy', 'Course{}'.format(course_num))
|
||||
)
|
||||
for course_num in (1, 2, 3)
|
||||
]
|
||||
|
||||
course_switch_queries = len(set(s.enrollment.course.id for s in schedules))
|
||||
org_switch_queries = len(set(s.enrollment.course.id.org for s in schedules))
|
||||
|
||||
test_datetime = datetime.datetime(2017, 8, 3, 19, 44, 30, tzinfo=pytz.UTC)
|
||||
test_datetime_str = serialize(test_datetime)
|
||||
expected_query_count = (
|
||||
NUM_QUERIES_FIRST_MATCH + course_switch_queries + org_switch_queries + NUM_QUERIES_NO_ORG_LIST
|
||||
)
|
||||
with self.assertNumQueries(expected_query_count, table_blacklist=WAFFLE_TABLES):
|
||||
self.tested_task.apply(kwargs=dict(
|
||||
site_id=self.site_config.site.id, target_day_str=test_datetime_str, day_offset=2,
|
||||
bin_num=self._calculate_bin_for_user(user),
|
||||
))
|
||||
self.assertEqual(mock_schedule_send.apply_async.call_count, 1)
|
||||
self.assertFalse(mock_ace.send.called)
|
||||
|
||||
@ddt.data(1, 10, 100)
|
||||
def test_templates(self, message_count):
|
||||
now = datetime.datetime.now(pytz.UTC)
|
||||
|
||||
@@ -291,3 +291,28 @@ class ScheduleBaseEmailTestBase(SharedModuleStoreTestCase):
|
||||
self.assertFalse(mock_schedule_send.apply_async.called)
|
||||
else:
|
||||
self.assertTrue(mock_schedule_send.apply_async.called)
|
||||
|
||||
@patch.object(tasks, 'ace')
|
||||
def test_multiple_enrollments(self, mock_ace):
|
||||
user = UserFactory.create()
|
||||
current_day, offset, target_day = self._get_dates()
|
||||
num_courses = 3
|
||||
for course_index in range(num_courses):
|
||||
ScheduleFactory.create(
|
||||
start=target_day,
|
||||
upgrade_deadline=target_day,
|
||||
enrollment__course__self_paced=True,
|
||||
enrollment__user=user,
|
||||
enrollment__course__id=CourseKey.from_string('edX/toy/course{}'.format(course_index))
|
||||
)
|
||||
|
||||
course_queries = num_courses if self.has_course_queries else 0
|
||||
expected_query_count = NUM_QUERIES_FIRST_MATCH + course_queries + NUM_QUERIES_NO_ORG_LIST
|
||||
with self.assertNumQueries(expected_query_count, table_blacklist=WAFFLE_TABLES):
|
||||
with patch.object(self.tested_task, 'async_send_task') as mock_schedule_send:
|
||||
self.tested_task.apply(kwargs=dict(
|
||||
site_id=self.site_config.site.id, target_day_str=serialize(target_day), day_offset=offset,
|
||||
bin_num=self._calculate_bin_for_user(user),
|
||||
))
|
||||
self.assertEqual(mock_schedule_send.apply_async.call_count, 1)
|
||||
self.assertFalse(mock_ace.send.called)
|
||||
|
||||
Reference in New Issue
Block a user