'Test unenrolling a user.'

@ddt.data(False, True)
def test_unenroll(self, use_json):

    response = self.request_bulk_enroll({'identifiers': self.enrolled_student.email, 'action': 'unenroll', 'email_students': False, 'courses': self.course_key}, use_json=use_json)
    self.assertEqual(response.status_code, 200)
    user = User.objects.get(email=self.enrolled_student.email)
    self.assertFalse(CourseEnrollment.is_enrolled(user, self.course.id))
    expected = {'action': 'unenroll', 'auto_enroll': False, 'email_students': False, 'courses': {self.course_key: {'action': 'unenroll', 'auto_enroll': False, 'results': [{'identifier': self.enrolled_student.email, 'before': {'enrollment': True, 'auto_enroll': False, 'user': True, 'allowed': False}, 'after': {'enrollment': False, 'auto_enroll': False, 'user': True, 'allowed': False}}]}}}
    manual_enrollments = ManualEnrollmentAudit.objects.all()
    self.assertEqual(manual_enrollments.count(), 1)
    self.assertEqual(manual_enrollments[0].state_transition, ENROLLED_TO_UNENROLLED)
    res_json = json.loads(response.content)
    self.assertEqual(res_json, expected)
    self.assertEqual(len(mail.outbox), 0)
