def test_cohort_target(self):
     course_id = CourseKey.from_string('abc/123/doremi')
     sender = UserFactory.create()
     to_option = 'cohort:test cohort'
     subject = "dummy subject"
     html_message = "<html>dummy message</html>"
     CourseCohort.create(cohort_name='test cohort', course_id=course_id)
     email = CourseEmail.create(course_id, sender, [to_option], subject, html_message)
     self.assertEqual(len(email.targets.all()), 1)
     target = email.targets.all()[0]
     self.assertEqual(target.target_type, SEND_TO_COHORT)
     self.assertEqual(target.short_display(), 'cohort-test cohort')
     self.assertEqual(target.long_display(), 'Cohort: test cohort')
示例#2
0
 def test_cohort_target(self):
     course_id = CourseKey.from_string('abc/123/doremi')
     sender = UserFactory.create()
     to_option = 'cohort:test cohort'
     subject = "dummy subject"
     html_message = "<html>dummy message</html>"
     CourseCohort.create(cohort_name='test cohort', course_id=course_id)
     email = CourseEmail.create(course_id, sender, [to_option], subject, html_message)
     self.assertEqual(len(email.targets.all()), 1)
     target = email.targets.all()[0]
     self.assertEqual(target.target_type, SEND_TO_COHORT)
     self.assertEqual(target.short_display(), 'cohort-test cohort')
     self.assertEqual(target.long_display(), 'Cohort: test cohort')
示例#3
0
    def test_send_to_cohort(self):
        """
        Make sure email sent to a cohort goes there.
        """
        cohort = CourseCohort.create(cohort_name='test cohort', course_id=self.course.id)
        for student in self.students:
            add_user_to_cohort(cohort.course_user_group, student.username)
        test_email = {
            'action': 'Send email',
            'send_to': f'["cohort:{cohort.course_user_group.name}"]',
            'subject': 'test subject for cohort',
            'message': 'test message for cohort'
        }
        response = self.client.post(self.send_mail_url, test_email)
        assert json.loads(response.content.decode('utf-8')) == self.success_content

        assert len([e.to[0] for e in mail.outbox]) == len([s.email for s in self.students])
示例#4
0
    def test_send_to_cohort_unenrolled(self):
        """
        Make sure email sent to a cohort does not go to unenrolled members of the cohort.
        """
        self.students.append(UserFactory())  # user will be added to cohort, but not enrolled in course
        cohort = CourseCohort.create(cohort_name='test cohort', course_id=self.course.id)
        for student in self.students:
            add_user_to_cohort(cohort.course_user_group, student.username)
        test_email = {
            'action': 'Send email',
            'send_to': '["cohort:{}"]'.format(cohort.course_user_group.name),
            'subject': 'test subject for cohort',
            'message': 'test message for cohort'
        }
        response = self.client.post(self.send_mail_url, test_email)
        self.assertEquals(json.loads(response.content), self.success_content)

        self.assertEquals(len(mail.outbox), len(self.students) - 1)
        self.assertNotIn(self.students[-1].email, [e.to[0] for e in mail.outbox])
示例#5
0
    def test_send_to_cohort_unenrolled(self):
        """
        Make sure email sent to a cohort does not go to unenrolled members of the cohort.
        """
        self.students.append(UserFactory())  # user will be added to cohort, but not enrolled in course
        cohort = CourseCohort.create(cohort_name='test cohort', course_id=self.course.id)
        for student in self.students:
            add_user_to_cohort(cohort.course_user_group, student.username)
        test_email = {
            'action': 'Send email',
            'send_to': '["cohort:{}"]'.format(cohort.course_user_group.name),
            'subject': 'test subject for cohort',
            'message': 'test message for cohort'
        }
        response = self.client.post(self.send_mail_url, test_email)
        self.assertEquals(json.loads(response.content.decode('utf-8')), self.success_content)

        self.assertEquals(len(mail.outbox), len(self.students) - 1)
        self.assertNotIn(self.students[-1].email, [e.to[0] for e in mail.outbox])
示例#6
0
    def test_send_to_cohort(self):
        """
        Make sure email sent to a cohort goes there.
        """
        cohort = CourseCohort.create(cohort_name='test cohort',
                                     course_id=self.course.id)
        for student in self.students:
            add_user_to_cohort(cohort.course_user_group, student.username)
        test_email = {
            'action': 'Send email',
            'send_to': '["cohort:{}"]'.format(cohort.course_user_group.name),
            'subject': 'test subject for cohort',
            'message': 'test message for cohort'
        }
        response = self.client.post(self.send_mail_url, test_email)
        self.assertEquals(json.loads(response.content), self.success_content)

        self.assertItemsEqual([e.to[0] for e in mail.outbox],
                              [s.email for s in self.students])
示例#7
0
    def test_send_to_cohort(self):
        """
        Make sure email sent to a cohort goes there.
        """
        cohort = CourseCohort.create(cohort_name='test cohort', course_id=self.course.id)
        for student in self.students:
            add_user_to_cohort(cohort.course_user_group, student.username)
        test_email = {
            'action': 'Send email',
            'send_to': '["cohort:{}"]'.format(cohort.course_user_group.name),
            'subject': 'test subject for cohort',
            'message': 'test message for cohort'
        }
        response = self.client.post(self.send_mail_url, test_email)
        self.assertEquals(json.loads(response.content), self.success_content)

        self.assertItemsEqual(
            [e.to[0] for e in mail.outbox],
            [s.email for s in self.students]
        )