'Make sure email sent to a cohort does not go to unenrolled members of the cohort.'

def test_send_to_cohort_unenrolled(self):

    self.students.append(UserFactory())
    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])
