def test_already_has_program_certificate(self): """ Test already has a certificate """ MicromastersProgramCertificate.objects.create(user=self.user, program=self.program) # should not raise an exception api.generate_program_certificate(self.user, self.program)
def handle(self, *args, **kwargs): # pylint: disable=unused-argument programs = Program.objects.filter(live=True, financial_aid_availability=True) for program in programs: if program.has_frozen_grades_for_all_courses(): enrollments = ProgramEnrollment.objects.filter(program=program) for enrollment in enrollments: generate_program_certificate(enrollment.user, program)
def test_successful_program_certificate_generation_with_electives(self): """ Test has final grade and a certificate with elective courses """ run_2 = CourseRunFactory.create( freeze_grade_date=now_in_utc() - timedelta(days=1), course__program=self.program, ) electives_set = ElectivesSet.objects.create(program=self.program, required_number=1) for run in [self.run_1, run_2]: final_grade = FinalGradeFactory.create( user=self.user, course_run=run, passed=True, status='complete', grade=0.7 ) CourseRunGradingStatus.objects.create(course_run=run, status='complete') ElectiveCourse.objects.create(course=run.course, electives_set=electives_set) with mute_signals(post_save): MicromastersCourseCertificate.objects.create(course=final_grade.course_run.course, user=self.user) cert_qset = MicromastersProgramCertificate.objects.filter(user=self.user, program=self.program) assert cert_qset.exists() is False api.generate_program_certificate(self.user, self.program) assert cert_qset.exists() is True
def test_has_no_final_grade(self): """ Test has no final grade """ CourseRunGradingStatus.objects.create(course_run=self.run_1, status='complete') cert_qset = MicromastersProgramCertificate.objects.filter(user=self.user, program=self.program) api.generate_program_certificate(self.user, self.program) assert cert_qset.exists() is False
def test_final_grade_with_no_certificate(self): """ Test has a final grade but no certificate """ FinalGradeFactory.create( user=self.user, course_run=self.run_1, passed=True, status='complete', grade=0.8 ) CourseRunGradingStatus.objects.create(course_run=self.run_1, status='complete') cert_qset = MicromastersProgramCertificate.objects.filter(user=self.user, program=self.program) assert cert_qset.exists() is False api.generate_program_certificate(self.user, self.program) assert cert_qset.exists() is False
def handle_create_coursecertificate(sender, instance, created, **kwargs): # pylint: disable=unused-argument """ When a MicromastersCourseCertificate model is created """ if created: user = instance.user program = instance.course.program transaction.on_commit(lambda: generate_program_certificate(user, program))
def test_successful_program_certificate_generation(self): """ Test has final grade and a certificate """ final_grade = FinalGradeFactory.create( user=self.user, course_run=self.run_1, passed=True, status='complete', grade=0.8 ) CourseRunGradingStatus.objects.create(course_run=self.run_1, status='complete') with mute_signals(post_save): MicromastersCourseCertificate.objects.create(course=final_grade.course_run.course, user=self.user) cert_qset = MicromastersProgramCertificate.objects.filter(user=self.user, program=self.program) assert cert_qset.exists() is False api.generate_program_certificate(self.user, self.program) assert cert_qset.exists() is True