def test_models_course_run_mark_dirty_delete_course_run_to_be_scheduled(self): """ Deleting a course run yet to be scheduled should not mark the related course page dirty. """ field = random.choice(["start", "enrollment_start"]) course_run = CourseRunFactory(**{field: None}) self.assertTrue(course_run.direct_course.extended_object.publish("en")) title_obj = course_run.direct_course.extended_object.title_set.first() course_run.refresh_from_db() course_run.delete() title_obj.refresh_from_db() self.assertEqual(title_obj.publisher_state, PUBLISHER_STATE_DEFAULT)
def test_models_course_run_mark_dirty_delete_course_run(self): """ Deleting a scheduled course run should mark the related course page dirty. """ course_run = CourseRunFactory() self.assertTrue(course_run.direct_course.extended_object.publish("en")) title_obj = course_run.direct_course.extended_object.title_set.first() course_run.refresh_from_db() self.assertEqual(title_obj.publisher_state, PUBLISHER_STATE_DEFAULT) course_run.delete() title_obj.refresh_from_db() self.assertEqual(title_obj.publisher_state, PUBLISHER_STATE_DIRTY)
def test_models_course_run_delete_draft(self): """ Deleting a draft course run that is not published should delete all its related translations. """ course = CourseFactory(page_languages=["en", "fr"]) course_run = CourseRunFactory(direct_course=course) CourseRunTranslation.objects.create(master=course_run, language_code="fr", title="mon titre") self.assertEqual(CourseRun.objects.count(), 1) self.assertEqual(CourseRunTranslation.objects.count(), 2) course_run.delete() self.assertFalse(CourseRun.objects.exists()) self.assertFalse(CourseRunTranslation.objects.exists())
def test_models_course_run_delete_published_cascade(self): """ Deleting a draft course run that is published should delete its public counterpart and all its translations by cascade. """ course = CourseFactory(page_languages=["en", "fr"]) course_run = CourseRunFactory(direct_course=course) CourseRunTranslation.objects.create(master=course_run, language_code="fr", title="mon titre") self.assertTrue(course_run.direct_course.extended_object.publish("en")) self.assertTrue(course_run.direct_course.extended_object.publish("fr")) self.assertEqual(CourseRun.objects.count(), 2) self.assertEqual(CourseRunTranslation.objects.count(), 4) course_run.delete() self.assertFalse(CourseRun.objects.exists()) self.assertFalse(CourseRunTranslation.objects.exists())