'test lookup for the valid registration code
and that registration code has been redeemed by user
and then mark the registration code as in_valid
when marking as invalidate, it also lookup for
registration redemption entry and also delete
that redemption entry and un_enroll the student
who used that registration code for their enrollment.'

def test_look_up_valid_registration_code(self):

    for i in range(2):
        CourseRegistrationCode.objects.create(code='reg_code{}'.format(i), course_id=unicode(self.course.id), created_by=self.instructor, invoice=self.sale_invoice, invoice_item=self.invoice_item, mode_slug=CourseMode.DEFAULT_MODE_SLUG)
    reg_code = CourseRegistrationCode.objects.all()[0]
    student = UserFactory()
    enrollment = CourseEnrollment.enroll(student, self.course.id)
    RegistrationCodeRedemption.objects.create(registration_code=reg_code, redeemed_by=student, course_enrollment=enrollment)
    data = {'registration_code': reg_code.code}
    response = self.client.get(self.lookup_code_url, data)
    self.assertEqual(response.status_code, 200)
    json_dict = json.loads(response.content)
    self.assertTrue(json_dict['is_registration_code_valid'])
    self.assertTrue(json_dict['is_registration_code_redeemed'])
    data = {'registration_code': reg_code.code, 'action_type': 'invalidate_registration_code'}
    response = self.client.post(self.registration_code_detail_url, data)
    self.assertEqual(response.status_code, 200)
    json_dict = json.loads(response.content)
    message = _('This    enrollment    code    has    been    canceled.    It    can    no    longer    be    used.')
    self.assertEqual(message, json_dict['message'])
    reg_code = CourseRegistrationCode.objects.get(code=reg_code.code)
    self.assertEqual(reg_code.is_valid, False)
    redemption = RegistrationCodeRedemption.get_registration_code_redemption(reg_code.code, self.course.id)
    self.assertIsNone(redemption)
    enrollment = CourseEnrollment.get_enrollment(student, self.course.id)
    self.assertEqual(enrollment.is_active, False)
