'test to unenroll allow to enroll user.'

def test_unenrolled_allowed_to_enroll_user(self):

    paid_course = self.create_paid_course()
    url = reverse('students_update_enrollment', kwargs={'course_id': paid_course.id.to_deprecated_string()})
    params = {'identifiers': self.notregistered_email, 'action': 'enroll', 'email_students': False, 'auto_enroll': False, 'reason': 'testing..'}
    response = self.client.post(url, params)
    manual_enrollments = ManualEnrollmentAudit.objects.all()
    self.assertEqual(manual_enrollments.count(), 1)
    self.assertEqual(manual_enrollments[0].state_transition, UNENROLLED_TO_ALLOWEDTOENROLL)
    self.assertEqual(response.status_code, 200)
    UserFactory(email=self.notregistered_email)
    url = reverse('students_update_enrollment', kwargs={'course_id': paid_course.id.to_deprecated_string()})
    params = {'identifiers': self.notregistered_email, 'action': 'enroll', 'email_students': False, 'auto_enroll': False, 'reason': 'testing'}
    response = self.client.post(url, params)
    manual_enrollments = ManualEnrollmentAudit.objects.all()
    self.assertEqual(manual_enrollments.count(), 2)
    self.assertEqual(manual_enrollments[1].state_transition, ALLOWEDTOENROLL_TO_ENROLLED)
    self.assertEqual(response.status_code, 200)
    expected = {'action': 'enroll', 'auto_enroll': False, 'results': [{'identifier': self.notregistered_email, 'before': {'enrollment': False, 'auto_enroll': False, 'user': True, 'allowed': True}, 'after': {'enrollment': True, 'auto_enroll': False, 'user': True, 'allowed': True}}]}
    res_json = json.loads(response.content)
    self.assertEqual(res_json, expected)
