'test to lookup for the valid and redeemed registration code
and then mark that registration code as un_redeemed
which will unenroll the user and delete the redemption
entry from the database.'

def test_lookup_valid_redeemed_registration_code(self):

    student = UserFactory()
    self.client.login(username=student.username, password='test')
    cart = Order.get_cart_for_user(student)
    cart.order_type = 'business'
    cart.save()
    CourseRegCodeItem.add_to_order(cart, self.course.id, 2)
    cart.purchase()
    reg_code = CourseRegistrationCode.objects.filter(order=cart)[0]
    enrollment = CourseEnrollment.enroll(student, self.course.id)
    RegistrationCodeRedemption.objects.create(registration_code=reg_code, redeemed_by=student, course_enrollment=enrollment)
    self.client.login(username=self.instructor.username, password='test')
    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': 'unredeem_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    marked    as    unused.')
    self.assertEqual(message, json_dict['message'])
    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)
