def setUp(self): super(TestACEOptoutCourseEmails, self).setUp() course_title = u"ẗëṡẗ title イ乇丂イ ᄊ乇丂丂ムg乇 キo尺 ムレレ тэѕт мэѕѕаБэ" self.course = CourseFactory.create(run='testcourse1', display_name=course_title) self.instructor = AdminFactory.create() self.student = UserFactory.create() CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id) self.client.login(username=self.student.username, password="******") self._set_email_optout(False) self.policy = CourseEmailOptout()
class TestACEOptoutCourseEmails(ModuleStoreTestCase): """ Test that optouts are referenced in sending course email. """ def setUp(self): super(TestACEOptoutCourseEmails, self).setUp() course_title = u"ẗëṡẗ title イ乇丂イ ᄊ乇丂丂ムg乇 キo尺 ムレレ тэѕт мэѕѕаБэ" self.course = CourseFactory.create(run='testcourse1', display_name=course_title) self.instructor = AdminFactory.create() self.student = UserFactory.create() CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id) self.client.login(username=self.student.username, password="******") self._set_email_optout(False) self.policy = CourseEmailOptout() def _set_email_optout(self, opted_out): url = reverse('change_email_settings') # This is a checkbox, so on the post of opting out (that is, an Un-check of the box), # the Post that is sent will not contain 'receive_emails' post_data = {'course_id': text_type(self.course.id)} if not opted_out: post_data['receive_emails'] = 'on' response = self.client.post(url, post_data) self.assertEquals(json.loads(response.content), {'success': True}) def test_policy_optedout(self): """ Make sure the policy prevents ACE emails if the user is opted-out. """ self._set_email_optout(True) channel_mods = self.policy.check(self.create_test_message()) self.assertEqual(channel_mods, PolicyResult(deny={ChannelType.EMAIL})) def create_test_message(self): return Message( app_label='foo', name='bar', recipient=Recipient( username=self.student.username, email_address=self.student.email, ), context={'course_ids': [str(self.course.id)]}, ) def test_policy_optedin(self): """ Make sure the policy allows ACE emails if the user is opted-in. """ channel_mods = self.policy.check(self.create_test_message()) self.assertEqual(channel_mods, PolicyResult(deny=set())) def test_policy_no_course_id(self): """ Make sure the policy denies ACE emails if there is no course id in the context. """ message = self.create_test_message() message.context = {} channel_mods = self.policy.check(message) self.assertEqual(channel_mods, PolicyResult(deny=set()))
class TestACEOptoutCourseEmails(ModuleStoreTestCase): """ Test that optouts are referenced in sending course email. """ def setUp(self): super(TestACEOptoutCourseEmails, self).setUp() course_title = u"ẗëṡẗ title イ乇丂イ ᄊ乇丂丂ムg乇 キo尺 ムレレ тэѕт мэѕѕаБэ" self.course = CourseFactory.create(run='testcourse1', display_name=course_title) self.instructor = AdminFactory.create() self.student = UserFactory.create() CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id) self.client.login(username=self.student.username, password="******") self._set_email_optout(False) self.policy = CourseEmailOptout() def _set_email_optout(self, opted_out): url = reverse('change_email_settings') # This is a checkbox, so on the post of opting out (that is, an Un-check of the box), # the Post that is sent will not contain 'receive_emails' post_data = {'course_id': text_type(self.course.id)} if not opted_out: post_data['receive_emails'] = 'on' response = self.client.post(url, post_data) self.assertEquals(json.loads(response.content), {'success': True}) def test_policy_optedout(self): """ Make sure the policy prevents ACE emails if the user is opted-out. """ self._set_email_optout(True) channel_mods = self.policy.check(self.create_test_message()) self.assertEqual(channel_mods, PolicyResult(deny={ChannelType.EMAIL})) def create_test_message(self): return Message( app_label='foo', name='bar', recipient=Recipient( username=self.student.username, email_address=self.student.email, ), context={ 'course_ids': [str(self.course.id)] }, ) def test_policy_optedin(self): """ Make sure the policy allows ACE emails if the user is opted-in. """ channel_mods = self.policy.check(self.create_test_message()) self.assertEqual(channel_mods, PolicyResult(deny=set())) def test_policy_no_course_id(self): """ Make sure the policy denies ACE emails if there is no course id in the context. """ message = self.create_test_message() message.context = {} channel_mods = self.policy.check(message) self.assertEqual(channel_mods, PolicyResult(deny=set()))