'test to check the user enrollment source and payment status in the
enrollment detailed report'

def test_student_used_enrollment_code_for_course_enrollment(self):

    student = UserFactory()
    self.client.login(username=student.username, password='test')
    student_cart = Order.get_cart_for_user(student)
    paid_course_reg_item = PaidCourseRegistration.add_to_order(student_cart, self.course.id)
    resp = self.client.post(reverse('shoppingcart.views.update_user_cart'), {'ItemId': paid_course_reg_item.id, 'qty': '4'})
    self.assertEqual(resp.status_code, 200)
    student_cart.purchase()
    course_reg_codes = CourseRegistrationCode.objects.filter(order=student_cart)
    redeem_url = reverse('register_code_redemption', args=[course_reg_codes[0].code])
    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)
    task_input = {'features': []}
    with patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task'):
        result = upload_enrollment_report(None, None, self.course.id, task_input, 'generating_enrollment_report')
    self.assertDictContainsSubset({'attempted': 1, 'succeeded': 1, 'failed': 0}, result)
    self._verify_cell_data_in_csv(student.username, 'Enrollment    Source', 'Used    Registration    Code')
    self._verify_cell_data_in_csv(student.username, 'Payment    Status', 'purchased')
