Commit 1ad643ac by Adam Palay

allow sending emails to course modes even if they've expired (EDUCATOR-364)

parent 73c41388
...@@ -217,7 +217,7 @@ class CourseModeTarget(Target): ...@@ -217,7 +217,7 @@ class CourseModeTarget(Target):
if mode_slug is None: if mode_slug is None:
raise ValueError("Cannot create a CourseModeTarget without specifying a mode_slug.") raise ValueError("Cannot create a CourseModeTarget without specifying a mode_slug.")
try: try:
validate_course_mode(unicode(course_id), mode_slug) validate_course_mode(unicode(course_id), mode_slug, include_expired=True)
except CourseModeNotFoundError: except CourseModeNotFoundError:
raise ValueError( raise ValueError(
"Track {track} does not exist in course {course_id}".format( "Track {track} does not exist in course {course_id}".format(
......
""" """
Unit tests for bulk-email-related models. Unit tests for bulk-email-related models.
""" """
from django.test import TestCase import datetime
from django.core.management import call_command
from student.tests.factories import UserFactory
from mock import patch, Mock
from nose.plugins.attrib import attr
import ddt
from bulk_email.models import ( from bulk_email.models import (
CourseEmail, CourseEmail,
SEND_TO_COHORT, SEND_TO_COHORT,
...@@ -19,13 +14,22 @@ from bulk_email.models import ( ...@@ -19,13 +14,22 @@ from bulk_email.models import (
BulkEmailFlag BulkEmailFlag
) )
from course_modes.models import CourseMode from course_modes.models import CourseMode
from openedx.core.djangoapps.course_groups.models import CourseCohort from django.core.management import call_command
from django.test import TestCase
from mock import patch, Mock
from nose.plugins.attrib import attr
from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.keys import CourseKey
from student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from openedx.core.djangoapps.course_groups.models import CourseCohort
@ddt.ddt
@attr(shard=1) @attr(shard=1)
@patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message', autospec=True)) @patch('bulk_email.models.html_to_text', Mock(return_value='Mocking CourseEmail.text_message', autospec=True))
class CourseEmailTest(TestCase): class CourseEmailTest(ModuleStoreTestCase):
"""Test the CourseEmail model.""" """Test the CourseEmail model."""
def test_creation(self): def test_creation(self):
...@@ -69,15 +73,27 @@ class CourseEmailTest(TestCase): ...@@ -69,15 +73,27 @@ class CourseEmailTest(TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
CourseEmail.create(course_id, sender, to_option, subject, html_message) CourseEmail.create(course_id, sender, to_option, subject, html_message)
def test_track_target(self): @ddt.data(
course_id = CourseKey.from_string('abc/123/doremi') datetime.datetime(1999, 1, 1),
datetime.datetime(datetime.MAXYEAR, 1, 1),
)
def test_track_target(self, expiration_datetime):
"""
Tests that emails can be sent to a specific track. Also checks that
emails can be sent to an expired track (EDUCATOR-364)
"""
course = CourseFactory.create()
course_id = course.id
sender = UserFactory.create() sender = UserFactory.create()
to_option = 'track:test' to_option = 'track:test'
subject = "dummy subject" subject = "dummy subject"
html_message = "<html>dummy message</html>" html_message = "<html>dummy message</html>"
CourseMode.objects.create(mode_slug='test', mode_display_name='Test', course_id=course_id) CourseMode.objects.create(
with patch('bulk_email.models.validate_course_mode'): mode_slug='test',
# we don't have a real course, so validation will fail. Mock it out! mode_display_name='Test',
course_id=course_id,
expiration_datetime=expiration_datetime,
)
email = CourseEmail.create(course_id, sender, [to_option], subject, html_message) email = CourseEmail.create(course_id, sender, [to_option], subject, html_message)
self.assertEqual(len(email.targets.all()), 1) self.assertEqual(len(email.targets.all()), 1)
target = email.targets.all()[0] target = email.targets.all()[0]
......
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