Commit 08d31e1a by Nimisha Asthagiri

Schedules: Tests for Course Update messages

parent 03e496bd
from mock import patch
from unittest import skipUnless
from django.conf import settings
from openedx.core.djangoapps.schedules import resolvers, tasks
from openedx.core.djangoapps.schedules.management.commands import send_course_update as nudge
from openedx.core.djangoapps.schedules.management.commands.tests.send_email_base import ScheduleSendEmailTestBase
from openedx.core.djangoapps.schedules.management.commands.tests.upsell_base import ScheduleUpsellTestMixin
from openedx.core.djangolib.testing.utils import skip_unless_lms
@skip_unless_lms
@skipUnless(
'openedx.core.djangoapps.schedules.apps.SchedulesConfig' in settings.INSTALLED_APPS,
"Can't test schedules if the app isn't installed",
)
class TestSendCourseUpdate(ScheduleUpsellTestMixin, ScheduleSendEmailTestBase):
__test__ = True
# pylint: disable=protected-access
tested_resolver = resolvers.CourseUpdateResolver
tested_task = tasks.ScheduleCourseUpdate
deliver_task = tasks._course_update_schedule_send
tested_command = nudge.Command
deliver_config = 'deliver_course_update'
enqueue_config = 'enqueue_course_update'
expected_offsets = xrange(-7, -77, -7)
queries_deadline_for_each_course = True
def setUp(self):
super(TestSendCourseUpdate, self).setUp()
patcher = patch('openedx.core.djangoapps.schedules.resolvers.get_week_highlights')
mock_highlights = patcher.start()
mock_highlights.return_value = ['Highlight {}'.format(num + 1) for num in range(3)]
self.addCleanup(patcher.stop)
......@@ -2,7 +2,7 @@ from unittest import skipUnless
from django.conf import settings
from openedx.core.djangoapps.schedules import tasks
from openedx.core.djangoapps.schedules import resolvers, tasks
from openedx.core.djangoapps.schedules.management.commands import send_recurring_nudge as nudge
from openedx.core.djangoapps.schedules.management.commands.tests.send_email_base import ScheduleSendEmailTestBase
from openedx.core.djangoapps.schedules.management.commands.tests.upsell_base import ScheduleUpsellTestMixin
......@@ -18,9 +18,12 @@ class TestSendRecurringNudge(ScheduleUpsellTestMixin, ScheduleSendEmailTestBase)
__test__ = True
# pylint: disable=protected-access
tested_resolver = resolvers.RecurringNudgeResolver
tested_task = tasks.ScheduleRecurringNudge
deliver_task = tasks._recurring_nudge_schedule_send
tested_command = nudge.Command
deliver_config = 'deliver_recurring_nudge'
enqueue_config = 'enqueue_recurring_nudge'
expected_offsets = (-3, -10)
consolidates_emails_for_learner = True
......@@ -5,11 +5,11 @@ import ddt
from django.conf import settings
from edx_ace import Message
from edx_ace.utils.date import serialize
from mock import Mock, patch
from mock import patch
from opaque_keys.edx.locator import CourseLocator
from course_modes.models import CourseMode
from openedx.core.djangoapps.schedules import tasks
from openedx.core.djangoapps.schedules import resolvers, tasks
from openedx.core.djangoapps.schedules.management.commands import send_upgrade_reminder as reminder
from openedx.core.djangoapps.schedules.management.commands.tests.send_email_base import ScheduleSendEmailTestBase
from openedx.core.djangoapps.schedules.tests.factories import ScheduleFactory
......@@ -27,6 +27,7 @@ LOG = logging.getLogger(__name__)
class TestUpgradeReminder(ScheduleSendEmailTestBase):
__test__ = True
tested_resolver = resolvers.UpgradeReminderResolver
tested_task = tasks.ScheduleUpgradeReminder
deliver_task = tasks._upgrade_reminder_schedule_send
tested_command = reminder.Command
......@@ -34,15 +35,16 @@ class TestUpgradeReminder(ScheduleSendEmailTestBase):
enqueue_config = 'enqueue_upgrade_reminder'
expected_offsets = (2,)
has_course_queries = True
queries_deadline_for_each_course = True
consolidates_emails_for_learner = True
@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)
current_day, offset, target_day = self._get_dates()
current_day, offset, target_day, upgrade_deadline = self._get_dates()
ScheduleFactory.create(
upgrade_deadline=target_day,
upgrade_deadline=upgrade_deadline,
enrollment__course__self_paced=True,
enrollment__user=user,
enrollment__mode=CourseMode.VERIFIED if is_verified else CourseMode.AUDIT,
......@@ -56,12 +58,12 @@ class TestUpgradeReminder(ScheduleSendEmailTestBase):
self.assertEqual(mock_ace.send.called, not is_verified)
def test_filter_out_verified_schedules(self):
current_day, offset, target_day = self._get_dates()
current_day, offset, target_day, upgrade_deadline = self._get_dates()
user = UserFactory.create()
schedules = [
ScheduleFactory.create(
upgrade_deadline=target_day,
upgrade_deadline=upgrade_deadline,
enrollment__user=user,
enrollment__course__self_paced=True,
enrollment__course__id=CourseLocator('edX', 'toy', 'Course{}'.format(i)),
......
......@@ -29,7 +29,7 @@ class ScheduleUpsellTestMixin(object):
def test_upsell(self, enable_config, testcase):
DynamicUpgradeDeadlineConfiguration.objects.create(enabled=enable_config)
current_day, offset, target_day = self._get_dates()
current_day, offset, target_day, _ = self._get_dates()
upgrade_deadline = None
if testcase.set_deadline:
upgrade_deadline = current_day + datetime.timedelta(days=testcase.deadline_offset)
......
......@@ -224,11 +224,11 @@ class InvalidContextError(Exception):
pass
class ScheduleStartResolver(BinnedSchedulesBaseResolver):
class RecurringNudgeResolver(BinnedSchedulesBaseResolver):
"""
Send a message to all users whose schedule started at ``self.current_date`` + ``day_offset``.
"""
log_prefix = 'Scheduled Nudge'
log_prefix = 'Recurring Nudge'
schedule_date_field = 'start'
num_bins = RECURRING_NUDGE_NUM_BINS
......
......@@ -147,7 +147,7 @@ class ScheduleRecurringNudge(ScheduleMessageBaseTask):
num_bins = resolvers.RECURRING_NUDGE_NUM_BINS
enqueue_config_var = 'enqueue_recurring_nudge'
log_prefix = RECURRING_NUDGE_LOG_PREFIX
resolver = resolvers.ScheduleStartResolver
resolver = resolvers.RecurringNudgeResolver
async_send_task = _recurring_nudge_schedule_send
def make_message_type(self, day_offset):
......
......@@ -4,8 +4,11 @@
Welcome to week {{ week_num }} of our {{ course_name }} course!
Here is what you can look forward to learning this week:
{{ week_summary }}
{% endblocktrans %}
{% for highlight in week_highlights %}
* {{ highlight }}
{% endfor %}
{% include "schedules/edx_ace/common/upsell_cta.txt"%}
......@@ -25,3 +25,5 @@ class ScheduleConfigFactory(factory.DjangoModelFactory):
deliver_recurring_nudge = True
enqueue_upgrade_reminder = True
deliver_upgrade_reminder = True
enqueue_course_update = True
deliver_course_update = True
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