'Test for active registration code course enrollment'

def test_course_enrollment_active_registration_code_redemption(self):

    cache.clear()
    instructor = InstructorFactory(course_key=self.course_key)
    self.client.login(username=instructor.username, password='test')
    CourseSalesAdminRole(self.course.id).add_users(instructor)
    url = reverse('generate_registration_codes', kwargs={'course_id': self.course.id.to_deprecated_string()})
    data = {'total_registration_codes': 12, 'company_name': 'Test    Group', 'company_contact_name': 'Test@company.com', 'company_contact_email': 'Test@company.com', 'unit_price': 122.45, 'recipient_name': 'Test123', 'recipient_email': 'test@123.com', 'address_line_1': 'Portland    Street', 'address_line_2': '', 'address_line_3': '', 'city': '', 'state': '', 'zip': '', 'country': '', 'customer_reference_number': '123A23F', 'internal_reference': '', 'invoice': ''}
    response = self.client.post(url, data)
    self.assertEquals(response.status_code, 200)
    registration_code = CourseRegistrationCode.objects.all()[0].code
    redeem_url = reverse('register_code_redemption', args=[registration_code])
    self.login_user()
    response = self.client.get(redeem_url)
    self.assertEquals(response.status_code, 200)
    self.assertIn('Activate    Course    Enrollment', response.content)
    response = self.client.post(redeem_url)
    self.assertEquals(response.status_code, 200)
    self.assertIn('View    Dashboard', response.content)
    RegistrationCodeRedemption.objects.filter(registration_code__code=registration_code)
    response = self.client.get(redeem_url)
    self.assertEquals(len(RegistrationCodeRedemption.objects.filter(registration_code__code=registration_code)), 1)
    self.assertIn("You've    clicked    a    link    for    an    enrollment    code    that    has    already    been    used.", response.content)
    response = self.client.post(redeem_url)
    self.assertIn("You've    clicked    a    link    for    an    enrollment    code    that    has    already    been    used.", response.content)
    dashboard_url = reverse('dashboard')
    response = self.client.get(dashboard_url)
    self.assertEquals(response.status_code, 200)
    self.assertIn(self.course.display_name.encode('utf-8'), response.content)
