From 77a2638d686d594623de09b5e6c84d8cebcb78db Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Wed, 25 Oct 2017 12:53:57 -0400 Subject: [PATCH] Move test_handle into the base class for schedule management command tests --- .../tests/test_send_recurring_nudge.py | 15 +++------------ .../tests/test_send_upgrade_reminder.py | 12 +----------- .../management/commands/tests/tools.py | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_recurring_nudge.py b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_recurring_nudge.py index 520e02a859..244ad1aae5 100644 --- a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_recurring_nudge.py +++ b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_recurring_nudge.py @@ -47,21 +47,12 @@ NUM_COURSE_MODES_QUERIES = 1 @skipUnless('openedx.core.djangoapps.schedules.apps.SchedulesConfig' in settings.INSTALLED_APPS, "Can't test schedules if the app isn't installed") class TestSendRecurringNudge(ScheduleBaseEmailTestBase): + __test__ = True + # pylint: disable=protected-access tested_task = tasks.ScheduleRecurringNudge tested_command = nudge.Command - - @patch.object(tested_command, 'async_send_task') - def test_handle(self, 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) - for day in (-3, -10): - mock_send.enqueue.assert_any_call( - self.site_config.site, - test_day, - day, - None - ) + expected_offsets = (-3, -10) @patch.object(tasks, 'ace') def test_resolver_send(self, mock_ace): diff --git a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py index dfff5b9ab3..85759bdb5d 100644 --- a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py +++ b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py @@ -64,6 +64,7 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase): tested_task = tasks.ScheduleUpgradeReminder tested_command = reminder.Command + expected_offsets = (2,) @classmethod def setUpClass(cls): @@ -87,17 +88,6 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase): expiration_datetime=datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=30), ) - @patch.object(tested_command, 'async_send_task') - def test_handle(self, 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) - mock_send.enqueue.assert_called_with( - self.site_config.site, - test_day, - 2, - None - ) - @patch.object(tasks, 'ace') def test_resolver_send(self, mock_ace): current_day = datetime.datetime(2017, 8, 1, tzinfo=pytz.UTC) diff --git a/openedx/core/djangoapps/schedules/management/commands/tests/tools.py b/openedx/core/djangoapps/schedules/management/commands/tests/tools.py index 447d1ea83b..18abc343e4 100644 --- a/openedx/core/djangoapps/schedules/management/commands/tests/tools.py +++ b/openedx/core/djangoapps/schedules/management/commands/tests/tools.py @@ -1,3 +1,8 @@ +import datetime + +from mock import patch +import pytz + from courseware.models import DynamicUpgradeDeadlineConfiguration from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, FilteredQueryCountMixin from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory, SiteFactory @@ -21,3 +26,16 @@ class ScheduleBaseEmailTestBase(FilteredQueryCountMixin, CacheIsolationTestCase) def test_command_task_binding(self): self.assertEqual(self.tested_command.async_send_task, self.tested_task) + + def test_handle(self): + with patch.object(self.tested_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) + + for offset in self.expected_offsets: + mock_send.enqueue.assert_any_call( + self.site_config.site, + test_day, + offset, + None + )