def test_not_live(self): """ Purchasable course runs must be live """ course_run, user = create_purchasable_course_run() program = course_run.course.program program.live = False program.save() with self.assertRaises(Http404): get_purchasable_course_run(course_run.edx_course_key, user)
def test_no_valid_price(self): """ Purchasable course runs must have a valid price """ course_run, user = create_purchasable_course_run() course_price = course_run.courseprice_set.get(is_valid=True) course_price.is_valid = False course_price.save() with self.assertRaises(Http404): get_purchasable_course_run(course_run.edx_course_key, user)
def test_financial_aid_not_available(self): """ Purchasable course runs must have financial aid available """ course_run, user = create_purchasable_course_run() program = course_run.course.program program.financial_aid_availability = False program.save() with self.assertRaises(Http404): get_purchasable_course_run(course_run.edx_course_key, user)
def test_no_current_financial_aid(self): """ Purchasable course runs must have financial aid available """ course_run, user = create_purchasable_course_run() program = course_run.course.program tier_program = program.tier_programs.first() tier_program.current = False tier_program.save() with self.assertRaises(ValidationError) as ex: get_purchasable_course_run(course_run.edx_course_key, user) assert ex.exception.args[0] == ( "Course run {} does not have a current attached financial aid application" .format(course_run.edx_course_key))
def test_success(self): """ A course run which is live, has financial aid, has a price, and was not already purchased, should be purchasable """ course_run, user = create_purchasable_course_run() assert get_purchasable_course_run(course_run.edx_course_key, user) == course_run
def test_financial_aid_for_user(self): """ Purchasable course runs must have a financial aid attached for the given user """ course_run, user = create_purchasable_course_run() program = course_run.course.program tier_program = program.tier_programs.first() financial_aid = tier_program.financialaid_set.first() financial_aid.user = UserFactory.create() financial_aid.save() with self.assertRaises(ValidationError) as ex: get_purchasable_course_run(course_run.edx_course_key, user) assert ex.exception.args[0] == ( "Course run {} does not have a current attached financial aid application" .format(course_run.edx_course_key))
def test_already_purchased(self): """ Purchasable course runs must not be already purchased """ course_run, user = create_purchasable_course_run() order = create_unfulfilled_order(course_run.edx_course_key, user) # succeeds because order is unfulfilled assert course_run == get_purchasable_course_run(course_run.edx_course_key, user) order.status = Order.FULFILLED order.save() with self.assertRaises(ValidationError) as ex: get_purchasable_course_run(course_run.edx_course_key, user) assert ex.exception.args[0] == 'Course run {} is already purchased'.format(course_run.edx_course_key)
def test_no_current_financial_aid(self): """ Purchasable course runs must have financial aid available """ course_run, user = create_purchasable_course_run() program = course_run.course.program tier_program = program.tier_programs.first() tier_program.current = False tier_program.save() with self.assertRaises(ValidationError) as ex: get_purchasable_course_run(course_run.edx_course_key, user) assert ex.exception.args[0] == ( "Course run {} does not have a current attached financial aid application".format( course_run.edx_course_key ) )
def test_already_purchased(self, order_status, has_to_pay): """ Purchasable course runs must not be already purchased """ course_run, user = create_purchasable_course_run() order = create_unfulfilled_order(course_run.edx_course_key, user) # succeeds because order is unfulfilled assert course_run == get_purchasable_course_run(course_run.edx_course_key, user) order.status = order_status order.save() with self.assertRaises(ValidationError) as ex: get_purchasable_course_run(course_run.edx_course_key, user) assert ex.exception.args[0] == 'Course run {} is already purchased'.format(course_run.edx_course_key) assert has_to_pay.call_count == 1
def test_financial_aid_terminal_status(self): """ FinancialAid must have a status which allows purchase to happen """ course_run, user = create_purchasable_course_run() program = course_run.course.program tier_program = program.tier_programs.first() financial_aid = tier_program.financialaid_set.first() for status in set(FinancialAidStatus.ALL_STATUSES).difference( set(FinancialAidStatus.TERMINAL_STATUSES)): financial_aid.status = status financial_aid.save() with self.assertRaises(ValidationError) as ex: get_purchasable_course_run(course_run.edx_course_key, user) assert ex.exception.args[0] == ( "Course run {} does not have a current attached financial aid application" .format(course_run.edx_course_key))
def test_financial_aid_for_user(self): """ Purchasable course runs must have a financial aid attached for the given user """ course_run, user = create_purchasable_course_run() program = course_run.course.program tier_program = program.tier_programs.first() financial_aid = tier_program.financialaid_set.first() financial_aid.user = UserFactory.create() financial_aid.save() with self.assertRaises(ValidationError) as ex: get_purchasable_course_run(course_run.edx_course_key, user) assert ex.exception.args[0] == ( "Course run {} does not have a current attached financial aid application".format( course_run.edx_course_key ) )
def test_financial_aid_terminal_status(self): """ FinancialAid must have a status which allows purchase to happen """ course_run, user = create_purchasable_course_run() program = course_run.course.program tier_program = program.tier_programs.first() financial_aid = tier_program.financialaid_set.first() for status in set(FinancialAidStatus.ALL_STATUSES).difference(set(FinancialAidStatus.TERMINAL_STATUSES)): financial_aid.status = status financial_aid.save() with self.assertRaises(ValidationError) as ex: get_purchasable_course_run(course_run.edx_course_key, user) assert ex.exception.args[0] == ( "Course run {} does not have a current attached financial aid application".format( course_run.edx_course_key ) )
def test_already_purchased_but_need_exam_attempts(self, order_status, has_to_pay): """ Can purchase a course run again if failed all exam attempts """ course_run, user = create_purchasable_course_run() order = create_unfulfilled_order(course_run.edx_course_key, user) order.status = order_status order.save() assert get_purchasable_course_run(course_run.edx_course_key, user) == course_run assert has_to_pay.call_count == 1