def setUpTestData(cls): with mute_signals(post_save): cls.profile = ProfileFactory.create() cls.program = ProgramFactory.create(financial_aid_availability=True) cls.tiers = { "0k": TierProgramFactory.create(program=cls.program, income_threshold=0, current=True), "15k": TierProgramFactory.create(program=cls.program, income_threshold=15000, current=True), "50k": TierProgramFactory.create(program=cls.program, income_threshold=50000, current=True), "100k": TierProgramFactory.create(program=cls.program, income_threshold=100000, current=True), "150k_not_current": TierProgramFactory.create(program=cls.program, income_threshold=150000, current=False) } cls.program_enrollment = ProgramEnrollment.objects.create( user=cls.profile.user, program=cls.program)
def test_fa_discount_too_large(self): """discount greater then courses price""" TierProgramFactory.create(program=self.program, current=True, discount_amount=int(self.program.price + 30), income_threshold=1000) assert (validate_prices()[0] == 'Discount is higher than course price for program {0}'.format( self.program.title))
def test_create_tier_does_not_create_for_programs_with_existing_tier_programs(self): """ Test that this won't create tiers if the programs already have existing tier programs """ TierProgramFactory.create(program=self.program1) assert TierProgram.objects.filter(program=self.program1).count() == 1 assert TierProgram.objects.filter(program=self.program2).count() == 0 self.command.handle("create_tiers", tiers=4, program_id=None, add_to_existing=False) assert TierProgram.objects.filter(program=self.program1).count() == 1 assert TierProgram.objects.filter(program=self.program2).count() == 4
def test_create_tier_with_add_to_existing_parameter(self): """ Test that passing the --add-to-existing parameter will add to programs with existing tiers """ TierProgramFactory.create(program=self.program1) assert TierProgram.objects.filter(program=self.program1).count() == 1 assert TierProgram.objects.filter(program=self.program2).count() == 0 self.command.handle("create_tiers", tiers=4, program_id=None, add_to_existing=True) assert TierProgram.objects.filter(program=self.program1).count() == 4 # Default is 4 assert TierProgram.objects.filter(program=self.program2).count() == 4
def setUpTestData(cls): super().setUpTestData() cls.user = UserFactory.create() cls.program = ProgramFactory.create(live=True, financial_aid_availability=True, price=1000) cls.min_tier_program = TierProgramFactory.create(program=cls.program, discount_amount=750, current=True) cls.max_tier_program = TierProgramFactory.create(program=cls.program, discount_amount=0, current=True)
def test_fa_discount_too_large(self): """discount greater then courses price""" TierProgramFactory.create( program=self.program, current=True, discount_amount=int(self.program.price + 30), income_threshold=1000 ) assert ( validate_prices()[0] == 'Discount is higher than course price for program {0}'.format(self.program.title) )
def test_create_tier_does_not_create_for_programs_with_existing_tier_programs( self): """ Test that this won't create tiers if the programs already have existing tier programs """ TierProgramFactory.create(program=self.program1) assert TierProgram.objects.filter(program=self.program1).count() == 1 assert TierProgram.objects.filter(program=self.program2).count() == 0 self.command.handle("create_tiers", tiers=4, program_id=None, add_to_existing=False) assert TierProgram.objects.filter(program=self.program1).count() == 1 assert TierProgram.objects.filter(program=self.program2).count() == 4
def test_create_tier_with_add_to_existing_parameter(self): """ Test that passing the --add-to-existing parameter will add to programs with existing tiers """ TierProgramFactory.create(program=self.program1) assert TierProgram.objects.filter(program=self.program1).count() == 1 assert TierProgram.objects.filter(program=self.program2).count() == 0 self.command.handle("create_tiers", tiers=4, program_id=None, add_to_existing=True) assert TierProgram.objects.filter( program=self.program1).count() == 4 # Default is 4 assert TierProgram.objects.filter(program=self.program2).count() == 4
def setUpTestData(cls): super().setUpTestData() cls.user = UserFactory.create() cls.program = ProgramFactory.create(live=True, financial_aid_availability=True, price=1000) cls.min_tier_program = TierProgramFactory.create( program=cls.program, discount_amount=750, current=True ) cls.max_tier_program = TierProgramFactory.create( program=cls.program, discount_amount=0, current=True )
def test_not_current(self): """ Not current tier """ not_current = TierProgramFactory.create(program=self.program, income_threshold=75000, current=False) self.data["tier_program_id"] = not_current.id self.make_http_request(self.client.patch, self.action_url, status.HTTP_400_BAD_REQUEST, data=self.data)
def setUpTestData(cls): cls.user = SocialUserFactory.create() cls.run_fa = CourseRunFactory.create( freeze_grade_date=now_in_utc() - timedelta(days=1), course__program__financial_aid_availability=True, ) cls.run_fa_with_cert = CourseRunFactory.create( freeze_grade_date=None, course__program=cls.run_fa.course.program, ) cls.run_no_fa = CourseRunFactory.create( freeze_grade_date=now_in_utc() + timedelta(days=1), course__program__financial_aid_availability=False, ) cls.run_no_fa_with_cert = CourseRunFactory.create( course__program=cls.run_no_fa.course.program, ) all_course_runs = ( cls.run_fa, cls.run_fa_with_cert, cls.run_no_fa, cls.run_no_fa_with_cert, ) for run in all_course_runs: if run.course.program.financial_aid_availability: FinancialAidFactory.create( user=cls.user, tier_program=TierProgramFactory.create( program=run.course.program, income_threshold=0, current=True), status=FinancialAidStatus.RESET, ) cls.enrollments = { course_run.edx_course_key: CachedEnrollmentFactory.create(user=cls.user, course_run=course_run) for course_run in all_course_runs } cls.current_grades = { course_run.edx_course_key: CachedCurrentGradeFactory.create(user=cls.user, course_run=course_run) for course_run in all_course_runs } cls.certificates = { course_run.edx_course_key: CachedCertificateFactory.create(user=cls.user, course_run=course_run) for course_run in (cls.run_fa_with_cert, cls.run_no_fa_with_cert) } cls.user_edx_data = CachedEdxUserData(cls.user)
def test_determine_tier_program_not_current(self): """ A current=False tier should be ignored """ not_current = TierProgramFactory.create(program=self.program, income_threshold=75000, current=False) assert determine_tier_program(self.program, 34938234) != not_current
def setUpTestData(cls): super().setUpTestData() cls.financial_aid = FinancialAidFactory.create( tier_program=TierProgramFactory.create(program=cls.program)) cls.url = reverse('financial_aid_mail_api', kwargs={'financial_aid_id': cls.financial_aid.id}) cls.request_data = { 'email_subject': 'email subject', 'email_body': 'email body' }
def create_program(create_tiers=True, past=False): """ Helper function to create a financial aid program Returns: courses.models.Program: A new program """ end_date = None program = ProgramFactory.create(financial_aid_availability=True, live=True) course = CourseFactory.create(program=program) if past: end_date = now_in_utc() - timedelta(days=100) else: end_date = now_in_utc() + timedelta(days=100) CourseRunFactory.create(end_date=end_date, enrollment_end=now_in_utc() + timedelta(hours=1), course=course) tier_programs = None if create_tiers: tier_programs = { "0k": TierProgramFactory.create(program=program, income_threshold=0, current=True), "25k": TierProgramFactory.create(program=program, income_threshold=25000, current=True), "50k": TierProgramFactory.create(program=program, income_threshold=50000, current=True), "75k": TierProgramFactory.create(program=program, income_threshold=75000, current=True, discount_amount=0), } return program, tier_programs
def setUpTestData(cls): super().setUpTestData() cls.financial_aid = FinancialAidFactory.create( tier_program=TierProgramFactory.create(program=cls.program) ) cls.url = reverse( 'financial_aid_mail_api', kwargs={'financial_aid_id': cls.financial_aid.id} ) cls.request_data = { 'email_subject': 'email subject', 'email_body': 'email body' }
def create_program(create_tiers=True, past=False): """ Helper function to create a financial aid program Returns: courses.models.Program: A new program """ end_date = None program = ProgramFactory.create( financial_aid_availability=True, live=True ) course = CourseFactory.create(program=program) if past: end_date = now_in_utc() - timedelta(days=100) else: end_date = now_in_utc() + timedelta(days=100) CourseRunFactory.create( end_date=end_date, enrollment_end=now_in_utc() + timedelta(hours=1), course=course ) tier_programs = None if create_tiers: tier_programs = { "0k": TierProgramFactory.create(program=program, income_threshold=0, current=True), "25k": TierProgramFactory.create(program=program, income_threshold=25000, current=True), "50k": TierProgramFactory.create(program=program, income_threshold=50000, current=True), "75k": TierProgramFactory.create( program=program, income_threshold=75000, current=True, discount_amount=0 ), } return program, tier_programs
def setUpTestData(cls): cls.user = SocialUserFactory.create() cls.run_fa = CourseRunFactory.create( freeze_grade_date=now_in_utc()-timedelta(days=1), course__program__financial_aid_availability=True, ) cls.run_fa_with_cert = CourseRunFactory.create( freeze_grade_date=None, course__program=cls.run_fa.course.program, ) cls.run_no_fa = CourseRunFactory.create( freeze_grade_date=now_in_utc()+timedelta(days=1), course__program__financial_aid_availability=False, ) cls.run_no_fa_with_cert = CourseRunFactory.create( course__program=cls.run_no_fa.course.program, ) all_course_runs = (cls.run_fa, cls.run_fa_with_cert, cls.run_no_fa, cls.run_no_fa_with_cert, ) for run in all_course_runs: if run.course.program.financial_aid_availability: FinancialAidFactory.create( user=cls.user, tier_program=TierProgramFactory.create( program=run.course.program, income_threshold=0, current=True ), status=FinancialAidStatus.RESET, ) cls.enrollments = { course_run.edx_course_key: CachedEnrollmentFactory.create( user=cls.user, course_run=course_run) for course_run in all_course_runs } cls.current_grades = { course_run.edx_course_key: CachedCurrentGradeFactory.create( user=cls.user, course_run=course_run) for course_run in all_course_runs } cls.certificates = { course_run.edx_course_key: CachedCertificateFactory.create( user=cls.user, course_run=course_run) for course_run in (cls.run_fa_with_cert, cls.run_no_fa_with_cert) } cls.user_edx_data = CachedEdxUserData(cls.user)
def test_invalid(self): """Not part of the same program""" self.data["tier_program_id"] = TierProgramFactory.create().id # Will be part of a different program self.make_http_request(self.client.patch, self.action_url, status.HTTP_400_BAD_REQUEST, data=self.data)
def test_determine_tier_program_not_current(self): """ A current=False tier should be ignored """ not_current = TierProgramFactory.create(program=self.program, income_threshold=75000, current=False) assert determine_tier_program(self.program, 34938234) != not_current