Commit da95676e by Nimisha Asthagiri

Schedules: rename test class variables that aren't test methods

parent 08d31e1a
...@@ -75,13 +75,13 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase): ...@@ -75,13 +75,13 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
DynamicUpgradeDeadlineConfiguration.objects.create(enabled=True) DynamicUpgradeDeadlineConfiguration.objects.create(enabled=True)
def _calculate_bin_for_user(self, user): def _calculate_bin_for_user(self, user):
return user.id % self.tested_task.num_bins return user.id % self.task.num_bins
def _get_dates(self, offset=None): def _get_dates(self, offset=None):
current_day = _get_datetime_beginning_of_day(datetime.datetime.now(pytz.UTC)) current_day = _get_datetime_beginning_of_day(datetime.datetime.now(pytz.UTC))
offset = offset or self.expected_offsets[0] offset = offset or self.expected_offsets[0]
target_day = current_day + datetime.timedelta(days=offset) target_day = current_day + datetime.timedelta(days=offset)
if self.tested_resolver.schedule_date_field == 'upgrade_deadline': if self.resolver.schedule_date_field == 'upgrade_deadline':
upgrade_deadline = target_day upgrade_deadline = target_day
else: else:
upgrade_deadline = current_day + datetime.timedelta(days=7) upgrade_deadline = current_day + datetime.timedelta(days=7)
...@@ -93,12 +93,12 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase): ...@@ -93,12 +93,12 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
return templates_override return templates_override
def test_command_task_binding(self): def test_command_task_binding(self):
self.assertEqual(self.tested_command.async_send_task, self.tested_task) self.assertEqual(self.command.async_send_task, self.task)
def test_handle(self): def test_handle(self):
with patch.object(self.tested_command, 'async_send_task') as mock_send: with patch.object(self.command, 'async_send_task') as mock_send:
test_day = datetime.datetime(2017, 8, 1, tzinfo=pytz.UTC) test_day = datetime.datetime(2017, 8, 1, tzinfo=pytz.UTC)
self.tested_command().handle(date='2017-08-01', site_domain_name=self.site_config.site.domain) self.command().handle(date='2017-08-01', site_domain_name=self.site_config.site.domain)
for offset in self.expected_offsets: for offset in self.expected_offsets:
mock_send.enqueue.assert_any_call( mock_send.enqueue.assert_any_call(
...@@ -111,14 +111,14 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase): ...@@ -111,14 +111,14 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
@patch.object(tasks, 'ace') @patch.object(tasks, 'ace')
def test_resolver_send(self, mock_ace): def test_resolver_send(self, mock_ace):
current_day, offset, target_day, _ = self._get_dates() current_day, offset, target_day, _ = self._get_dates()
with patch.object(self.tested_task, 'apply_async') as mock_apply_async: with patch.object(self.task, 'apply_async') as mock_apply_async:
self.tested_task.enqueue(self.site_config.site, current_day, offset) self.task.enqueue(self.site_config.site, current_day, offset)
mock_apply_async.assert_any_call( mock_apply_async.assert_any_call(
(self.site_config.site.id, serialize(target_day), offset, 0, None), (self.site_config.site.id, serialize(target_day), offset, 0, None),
retry=False, retry=False,
) )
mock_apply_async.assert_any_call( mock_apply_async.assert_any_call(
(self.site_config.site.id, serialize(target_day), offset, self.tested_task.num_bins - 1, None), (self.site_config.site.id, serialize(target_day), offset, self.task.num_bins - 1, None),
retry=False, retry=False,
) )
self.assertFalse(mock_ace.send.called) self.assertFalse(mock_ace.send.called)
...@@ -127,7 +127,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase): ...@@ -127,7 +127,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
@patch.object(tasks, 'ace') @patch.object(tasks, 'ace')
@patch.object(resolvers, 'set_custom_metric') @patch.object(resolvers, 'set_custom_metric')
def test_schedule_bin(self, schedule_count, mock_metric, mock_ace): def test_schedule_bin(self, schedule_count, mock_metric, mock_ace):
with patch.object(self.tested_task, 'async_send_task') as mock_schedule_send: with patch.object(self.task, 'async_send_task') as mock_schedule_send:
current_day, offset, target_day, upgrade_deadline = self._get_dates() current_day, offset, target_day, upgrade_deadline = self._get_dates()
schedules = [ schedules = [
ScheduleFactory.create( ScheduleFactory.create(
...@@ -141,7 +141,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase): ...@@ -141,7 +141,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
is_first_match = True is_first_match = True
target_day_str = serialize(target_day) target_day_str = serialize(target_day)
for b in range(self.tested_task.num_bins): for b in range(self.task.num_bins):
LOG.debug('Running bin %d', b) LOG.debug('Running bin %d', b)
expected_queries = NUM_QUERIES_NO_MATCHING_SCHEDULES expected_queries = NUM_QUERIES_NO_MATCHING_SCHEDULES
if b in bins_in_use: if b in bins_in_use:
...@@ -156,7 +156,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase): ...@@ -156,7 +156,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
expected_queries = NUM_QUERIES_WITH_MATCHES expected_queries = NUM_QUERIES_WITH_MATCHES
with self.assertNumQueries(expected_queries, table_blacklist=WAFFLE_TABLES): with self.assertNumQueries(expected_queries, table_blacklist=WAFFLE_TABLES):
self.tested_task.apply(kwargs=dict( self.task.apply(kwargs=dict(
site_id=self.site_config.site.id, target_day_str=target_day_str, day_offset=offset, bin_num=b, site_id=self.site_config.site.id, target_day_str=target_day_str, day_offset=offset, bin_num=b,
)) ))
...@@ -179,9 +179,9 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase): ...@@ -179,9 +179,9 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
schedule.enrollment.course_id = CourseKey.from_string('edX/toy/Not_2012_Fall') schedule.enrollment.course_id = CourseKey.from_string('edX/toy/Not_2012_Fall')
schedule.enrollment.save() schedule.enrollment.save()
with patch.object(self.tested_task, 'async_send_task') as mock_schedule_send: with patch.object(self.task, 'async_send_task') as mock_schedule_send:
for b in range(self.tested_task.num_bins): for b in range(self.task.num_bins):
self.tested_task.apply(kwargs=dict( self.task.apply(kwargs=dict(
site_id=self.site_config.site.id, site_id=self.site_config.site.id,
target_day_str=serialize(target_day), target_day_str=serialize(target_day),
day_offset=offset, day_offset=offset,
...@@ -222,8 +222,8 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase): ...@@ -222,8 +222,8 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
ScheduleConfigFactory.create(**schedule_config_kwargs) ScheduleConfigFactory.create(**schedule_config_kwargs)
current_datetime = datetime.datetime(2017, 8, 1, tzinfo=pytz.UTC) current_datetime = datetime.datetime(2017, 8, 1, tzinfo=pytz.UTC)
with patch.object(self.tested_task, 'apply_async') as mock_apply_async: with patch.object(self.task, 'apply_async') as mock_apply_async:
self.tested_task.enqueue(self.site_config.site, current_datetime, 3) self.task.enqueue(self.site_config.site, current_datetime, 3)
if is_enabled: if is_enabled:
self.assertTrue(mock_apply_async.called) self.assertTrue(mock_apply_async.called)
...@@ -245,8 +245,8 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase): ...@@ -245,8 +245,8 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
for config in (this_config, other_config): for config in (this_config, other_config):
ScheduleConfigFactory.create(site=config.site) ScheduleConfigFactory.create(site=config.site)
user1 = UserFactory.create(id=self.tested_task.num_bins) user1 = UserFactory.create(id=self.task.num_bins)
user2 = UserFactory.create(id=self.tested_task.num_bins * 2) user2 = UserFactory.create(id=self.task.num_bins * 2)
current_day, offset, target_day, upgrade_deadline = self._get_dates() current_day, offset, target_day, upgrade_deadline = self._get_dates()
ScheduleFactory.create( ScheduleFactory.create(
...@@ -271,8 +271,8 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase): ...@@ -271,8 +271,8 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
enrollment__user=user2, enrollment__user=user2,
) )
with patch.object(self.tested_task, 'async_send_task') as mock_schedule_send: with patch.object(self.task, 'async_send_task') as mock_schedule_send:
self.tested_task.apply(kwargs=dict( self.task.apply(kwargs=dict(
site_id=this_config.site.id, target_day_str=serialize(target_day), day_offset=offset, bin_num=0 site_id=this_config.site.id, target_day_str=serialize(target_day), day_offset=offset, bin_num=0
)) ))
...@@ -281,7 +281,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase): ...@@ -281,7 +281,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
@ddt.data(True, False) @ddt.data(True, False)
def test_course_end(self, has_course_ended): def test_course_end(self, has_course_ended):
user1 = UserFactory.create(id=self.tested_task.num_bins) user1 = UserFactory.create(id=self.task.num_bins)
current_day, offset, target_day, upgrade_deadline = self._get_dates() current_day, offset, target_day, upgrade_deadline = self._get_dates()
schedule = ScheduleFactory.create( schedule = ScheduleFactory.create(
...@@ -296,8 +296,8 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase): ...@@ -296,8 +296,8 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
schedule.enrollment.course.end = current_day + datetime.timedelta(days=end_date_offset) schedule.enrollment.course.end = current_day + datetime.timedelta(days=end_date_offset)
schedule.enrollment.course.save() schedule.enrollment.course.save()
with patch.object(self.tested_task, 'async_send_task') as mock_schedule_send: with patch.object(self.task, 'async_send_task') as mock_schedule_send:
self.tested_task.apply(kwargs=dict( self.task.apply(kwargs=dict(
site_id=self.site_config.site.id, target_day_str=serialize(target_day), day_offset=offset, bin_num=0, site_id=self.site_config.site.id, target_day_str=serialize(target_day), day_offset=offset, bin_num=0,
)) ))
...@@ -323,8 +323,8 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase): ...@@ -323,8 +323,8 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
additional_course_queries = num_courses - 1 if self.queries_deadline_for_each_course else 0 additional_course_queries = num_courses - 1 if self.queries_deadline_for_each_course else 0
expected_query_count = NUM_QUERIES_FIRST_MATCH + additional_course_queries expected_query_count = NUM_QUERIES_FIRST_MATCH + additional_course_queries
with self.assertNumQueries(expected_query_count, table_blacklist=WAFFLE_TABLES): with self.assertNumQueries(expected_query_count, table_blacklist=WAFFLE_TABLES):
with patch.object(self.tested_task, 'async_send_task') as mock_schedule_send: with patch.object(self.task, 'async_send_task') as mock_schedule_send:
self.tested_task.apply(kwargs=dict( self.task.apply(kwargs=dict(
site_id=self.site_config.site.id, target_day_str=serialize(target_day), day_offset=offset, site_id=self.site_config.site.id, target_day_str=serialize(target_day), day_offset=offset,
bin_num=self._calculate_bin_for_user(user), bin_num=self._calculate_bin_for_user(user),
)) ))
...@@ -361,7 +361,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase): ...@@ -361,7 +361,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
sent_messages = [] sent_messages = []
with self.settings(TEMPLATES=self._get_template_overrides()): with self.settings(TEMPLATES=self._get_template_overrides()):
with patch.object(self.tested_task, 'async_send_task') as mock_schedule_send: with patch.object(self.task, 'async_send_task') as mock_schedule_send:
mock_schedule_send.apply_async = lambda args, *_a, **_kw: sent_messages.append(args) mock_schedule_send.apply_async = lambda args, *_a, **_kw: sent_messages.append(args)
num_expected_queries = NUM_QUERIES_FIRST_MATCH num_expected_queries = NUM_QUERIES_FIRST_MATCH
...@@ -369,7 +369,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase): ...@@ -369,7 +369,7 @@ class ScheduleSendEmailTestBase(SharedModuleStoreTestCase):
num_expected_queries += (message_count - 1) num_expected_queries += (message_count - 1)
with self.assertNumQueries(num_expected_queries, table_blacklist=WAFFLE_TABLES): with self.assertNumQueries(num_expected_queries, table_blacklist=WAFFLE_TABLES):
self.tested_task.apply(kwargs=dict( self.task.apply(kwargs=dict(
site_id=self.site_config.site.id, target_day_str=serialize(target_day), day_offset=offset, site_id=self.site_config.site.id, target_day_str=serialize(target_day), day_offset=offset,
bin_num=self._calculate_bin_for_user(user), bin_num=self._calculate_bin_for_user(user),
)) ))
......
...@@ -19,10 +19,10 @@ class TestSendCourseUpdate(ScheduleUpsellTestMixin, ScheduleSendEmailTestBase): ...@@ -19,10 +19,10 @@ class TestSendCourseUpdate(ScheduleUpsellTestMixin, ScheduleSendEmailTestBase):
__test__ = True __test__ = True
# pylint: disable=protected-access # pylint: disable=protected-access
tested_resolver = resolvers.CourseUpdateResolver resolver = resolvers.CourseUpdateResolver
tested_task = tasks.ScheduleCourseUpdate task = tasks.ScheduleCourseUpdate
deliver_task = tasks._course_update_schedule_send deliver_task = tasks._course_update_schedule_send
tested_command = nudge.Command command = nudge.Command
deliver_config = 'deliver_course_update' deliver_config = 'deliver_course_update'
enqueue_config = 'enqueue_course_update' enqueue_config = 'enqueue_course_update'
expected_offsets = xrange(-7, -77, -7) expected_offsets = xrange(-7, -77, -7)
......
...@@ -18,10 +18,10 @@ class TestSendRecurringNudge(ScheduleUpsellTestMixin, ScheduleSendEmailTestBase) ...@@ -18,10 +18,10 @@ class TestSendRecurringNudge(ScheduleUpsellTestMixin, ScheduleSendEmailTestBase)
__test__ = True __test__ = True
# pylint: disable=protected-access # pylint: disable=protected-access
tested_resolver = resolvers.RecurringNudgeResolver resolver = resolvers.RecurringNudgeResolver
tested_task = tasks.ScheduleRecurringNudge task = tasks.ScheduleRecurringNudge
deliver_task = tasks._recurring_nudge_schedule_send deliver_task = tasks._recurring_nudge_schedule_send
tested_command = nudge.Command command = nudge.Command
deliver_config = 'deliver_recurring_nudge' deliver_config = 'deliver_recurring_nudge'
enqueue_config = 'enqueue_recurring_nudge' enqueue_config = 'enqueue_recurring_nudge'
expected_offsets = (-3, -10) expected_offsets = (-3, -10)
......
...@@ -27,10 +27,10 @@ LOG = logging.getLogger(__name__) ...@@ -27,10 +27,10 @@ LOG = logging.getLogger(__name__)
class TestUpgradeReminder(ScheduleSendEmailTestBase): class TestUpgradeReminder(ScheduleSendEmailTestBase):
__test__ = True __test__ = True
tested_resolver = resolvers.UpgradeReminderResolver resolver = resolvers.UpgradeReminderResolver
tested_task = tasks.ScheduleUpgradeReminder task = tasks.ScheduleUpgradeReminder
deliver_task = tasks._upgrade_reminder_schedule_send deliver_task = tasks._upgrade_reminder_schedule_send
tested_command = reminder.Command command = reminder.Command
deliver_config = 'deliver_upgrade_reminder' deliver_config = 'deliver_upgrade_reminder'
enqueue_config = 'enqueue_upgrade_reminder' enqueue_config = 'enqueue_upgrade_reminder'
expected_offsets = (2,) expected_offsets = (2,)
...@@ -41,7 +41,7 @@ class TestUpgradeReminder(ScheduleSendEmailTestBase): ...@@ -41,7 +41,7 @@ class TestUpgradeReminder(ScheduleSendEmailTestBase):
@ddt.data(True, False) @ddt.data(True, False)
@patch.object(tasks, 'ace') @patch.object(tasks, 'ace')
def test_verified_learner(self, is_verified, mock_ace): def test_verified_learner(self, is_verified, mock_ace):
user = UserFactory.create(id=self.tested_task.num_bins) user = UserFactory.create(id=self.task.num_bins)
current_day, offset, target_day, upgrade_deadline = self._get_dates() current_day, offset, target_day, upgrade_deadline = self._get_dates()
ScheduleFactory.create( ScheduleFactory.create(
upgrade_deadline=upgrade_deadline, upgrade_deadline=upgrade_deadline,
...@@ -50,7 +50,7 @@ class TestUpgradeReminder(ScheduleSendEmailTestBase): ...@@ -50,7 +50,7 @@ class TestUpgradeReminder(ScheduleSendEmailTestBase):
enrollment__mode=CourseMode.VERIFIED if is_verified else CourseMode.AUDIT, enrollment__mode=CourseMode.VERIFIED if is_verified else CourseMode.AUDIT,
) )
self.tested_task.apply(kwargs=dict( self.task.apply(kwargs=dict(
site_id=self.site_config.site.id, target_day_str=serialize(target_day), day_offset=offset, site_id=self.site_config.site.id, target_day_str=serialize(target_day), day_offset=offset,
bin_num=self._calculate_bin_for_user(user), bin_num=self._calculate_bin_for_user(user),
)) ))
...@@ -73,10 +73,10 @@ class TestUpgradeReminder(ScheduleSendEmailTestBase): ...@@ -73,10 +73,10 @@ class TestUpgradeReminder(ScheduleSendEmailTestBase):
] ]
sent_messages = [] sent_messages = []
with patch.object(self.tested_task, 'async_send_task') as mock_schedule_send: with patch.object(self.task, 'async_send_task') as mock_schedule_send:
mock_schedule_send.apply_async = lambda args, *_a, **_kw: sent_messages.append(args[1]) mock_schedule_send.apply_async = lambda args, *_a, **_kw: sent_messages.append(args[1])
self.tested_task.apply(kwargs=dict( self.task.apply(kwargs=dict(
site_id=self.site_config.site.id, target_day_str=serialize(target_day), day_offset=offset, site_id=self.site_config.site.id, target_day_str=serialize(target_day), day_offset=offset,
bin_num=self._calculate_bin_for_user(user), bin_num=self._calculate_bin_for_user(user),
)) ))
......
...@@ -41,9 +41,9 @@ class ScheduleUpsellTestMixin(object): ...@@ -41,9 +41,9 @@ class ScheduleUpsellTestMixin(object):
) )
sent_messages = [] sent_messages = []
with patch.object(self.tested_task, 'async_send_task') as mock_schedule_send: with patch.object(self.task, 'async_send_task') as mock_schedule_send:
mock_schedule_send.apply_async = lambda args, *_a, **_kw: sent_messages.append(args[1]) mock_schedule_send.apply_async = lambda args, *_a, **_kw: sent_messages.append(args[1])
self.tested_task.apply(kwargs=dict( self.task.apply(kwargs=dict(
site_id=self.site_config.site.id, target_day_str=serialize(target_day), day_offset=offset, site_id=self.site_config.site.id, target_day_str=serialize(target_day), day_offset=offset,
bin_num=self._calculate_bin_for_user(schedule.enrollment.user), bin_num=self._calculate_bin_for_user(schedule.enrollment.user),
)) ))
......
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