'Students purchases the courses using enrollment
and coupon codes.'

def students_purchases(self):

    self.client.login(username=self.student1.username, password='test')
    paid_course_reg_item = PaidCourseRegistration.add_to_order(self.student1_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)
    resp = self.client.post(reverse('shoppingcart.views.use_code'), {'code': 'coupon1'})
    self.assertEqual(resp.status_code, 200)
    self.student1_cart.purchase()
    course_reg_codes = CourseRegistrationCode.objects.filter(order=self.student1_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)
    self.client.login(username=self.student2.username, password='test')
    PaidCourseRegistration.add_to_order(self.student2_cart, self.course.id)
    resp = self.client.post(reverse('shoppingcart.views.use_code'), {'code': 'coupon1'})
    self.assertEqual(resp.status_code, 200)
    self.student2_cart.purchase()
