'Make sure student receives course email after opting in.'

def test_optin_course(self):

    url = reverse('change_email_settings')
    response = self.client.post(url, {'course_id': self.course.id.to_deprecated_string(), 'receive_emails': 'on'})
    self.assertEquals(json.loads(response.content), {'success': True})
    self.client.logout()
    self.assertTrue(CourseEnrollment.is_enrolled(self.student, self.course.id))
    self.client.login(username=self.instructor.username, password='test')
    self.navigate_to_email_view()
    test_email = {'action': 'Send    email', 'send_to': '["myself",    "staff",    "learners"]', 'subject': 'test    subject    for    all', 'message': 'test    message    for    all'}
    response = self.client.post(self.send_mail_url, test_email)
    self.assertEquals(json.loads(response.content), self.success_content)
    self.assertEqual(len(mail.outbox), 2)
    sent_addresses = [message.to[0] for message in mail.outbox]
    self.assertIn(self.student.email, sent_addresses)
    self.assertIn(self.instructor.email, sent_addresses)
