Commit da95676e by Nimisha Asthagiri

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

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