Commit c4302df0 by Calen Pennington Committed by Nimisha Asthagiri

Move test_resolver_send into the schedule management command base test class

parent 77a2638d
...@@ -54,21 +54,6 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase): ...@@ -54,21 +54,6 @@ class TestSendRecurringNudge(ScheduleBaseEmailTestBase):
tested_command = nudge.Command tested_command = nudge.Command
expected_offsets = (-3, -10) expected_offsets = (-3, -10)
@patch.object(tasks, 'ace')
def test_resolver_send(self, mock_ace):
current_day = 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_day, -3)
test_day = current_day + datetime.timedelta(days=-3)
mock_apply_async.assert_any_call(
(self.site_config.site.id, serialize(test_day), -3, 0, None),
retry=False,
)
mock_apply_async.assert_any_call(
(self.site_config.site.id, serialize(test_day), -3, resolvers.RECURRING_NUDGE_NUM_BINS - 1, None),
retry=False,
)
self.assertFalse(mock_ace.send.called)
@ddt.data(1, 10, 100) @ddt.data(1, 10, 100)
@patch.object(tasks, 'ace') @patch.object(tasks, 'ace')
......
...@@ -88,24 +88,6 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase): ...@@ -88,24 +88,6 @@ class TestUpgradeReminder(ScheduleBaseEmailTestBase, SharedModuleStoreTestCase):
expiration_datetime=datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=30), expiration_datetime=datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=30),
) )
@patch.object(tasks, 'ace')
def test_resolver_send(self, mock_ace):
current_day = datetime.datetime(2017, 8, 1, tzinfo=pytz.UTC)
test_day = current_day + datetime.timedelta(days=2)
ScheduleFactory.create(upgrade_deadline=datetime.datetime(2017, 8, 3, 15, 34, 30, tzinfo=pytz.UTC))
with patch.object(self.tested_task, 'apply_async') as mock_apply_async:
self.tested_task.enqueue(self.site_config.site, current_day, 2)
mock_apply_async.assert_any_call(
(self.site_config.site.id, serialize(test_day), 2, 0, None),
retry=False,
)
mock_apply_async.assert_any_call(
(self.site_config.site.id, serialize(test_day), 2, resolvers.UPGRADE_REMINDER_NUM_BINS - 1, None),
retry=False,
)
self.assertFalse(mock_ace.send.called)
@ddt.data(1, 10, 100) @ddt.data(1, 10, 100)
@patch.object(tasks, 'ace') @patch.object(tasks, 'ace')
@patch.object(tested_task, 'async_send_task') @patch.object(tested_task, 'async_send_task')
......
import datetime import datetime
from edx_ace.utils.date import serialize
from mock import patch from mock import patch
import pytz import pytz
from courseware.models import DynamicUpgradeDeadlineConfiguration from courseware.models import DynamicUpgradeDeadlineConfiguration
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, FilteredQueryCountMixin from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, FilteredQueryCountMixin
from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory, SiteFactory from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory, SiteFactory
from openedx.core.djangoapps.schedules import tasks
from openedx.core.djangoapps.schedules.tests.factories import ScheduleConfigFactory from openedx.core.djangoapps.schedules.tests.factories import ScheduleConfigFactory
class ScheduleBaseEmailTestBase(FilteredQueryCountMixin, CacheIsolationTestCase): class ScheduleBaseEmailTestBase(FilteredQueryCountMixin, CacheIsolationTestCase):
__test__ = False __test__ = False
...@@ -39,3 +42,21 @@ class ScheduleBaseEmailTestBase(FilteredQueryCountMixin, CacheIsolationTestCase) ...@@ -39,3 +42,21 @@ class ScheduleBaseEmailTestBase(FilteredQueryCountMixin, CacheIsolationTestCase)
offset, offset,
None None
) )
@patch.object(tasks, 'ace')
def test_resolver_send(self, mock_ace):
current_day = datetime.datetime(2017, 8, 1, tzinfo=pytz.UTC)
offset = self.expected_offsets[0]
target_day = current_day + datetime.timedelta(days=offset)
with patch.object(self.tested_task, 'apply_async') as mock_apply_async:
self.tested_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),
retry=False,
)
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