def test_models_course_run_mark_dirty_parler(self): """ Updating the value of a field translatable via parler should mark the related course page dirty (waiting to be published) only in the impacted language. """ 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")) course_run.refresh_from_db() self.assertIsNotNone(course_run.public_course_run) title_query = course_run.direct_course.extended_object.title_set title_obj_en = title_query.get(language="en") title_obj_fr = title_query.get(language="fr") self.assertEqual(title_query.count(), 2) with switch_language(course_run, "fr"): course_run.title = "nouveau titre" course_run.save() self.assertEqual(title_obj_en.publisher_state, PUBLISHER_STATE_DEFAULT) self.assertEqual(title_obj_fr.publisher_state, PUBLISHER_STATE_DEFAULT) course_run.mark_course_dirty() title_obj_en.refresh_from_db() title_obj_fr.refresh_from_db() self.assertEqual(title_obj_en.publisher_state, PUBLISHER_STATE_DEFAULT) self.assertEqual(title_obj_fr.publisher_state, PUBLISHER_STATE_DIRTY)
def test_models_course_run_mark_dirty_direct_course_field(self): """ Changing the course to which a course run is related should mark both the source and the target course pages dirty (waiting to be published). """ course_run = CourseRunFactory() course_source = course_run.direct_course course_target = CourseFactory(should_publish=True) self.assertTrue(course_source.extended_object.publish("en")) title_obj_source = course_source.extended_object.title_set.first() title_obj_target = course_target.extended_object.title_set.first() course_run.direct_course = course_target course_run.save() self.assertEqual(title_obj_source.publisher_state, PUBLISHER_STATE_DEFAULT) self.assertEqual(title_obj_target.publisher_state, PUBLISHER_STATE_DEFAULT) course_run.mark_course_dirty() title_obj_source.refresh_from_db() title_obj_target.refresh_from_db() self.assertEqual(title_obj_source.publisher_state, PUBLISHER_STATE_DIRTY) self.assertEqual(title_obj_target.publisher_state, PUBLISHER_STATE_DIRTY)
def test_models_course_run_mark_dirty_any_field(self): """ Updating the value of an editable field on the course run should mark the related course page dirty (waiting to be published). """ course_run = CourseRunFactory() self.assertTrue(course_run.direct_course.extended_object.publish("en")) title_obj = course_run.direct_course.extended_object.title_set.first() field = random.choice([ f for f in course_run._meta.fields if f.editable and not f.auto_created and not f.name == "direct_course" ]).name stub = CourseRunFactory( sync_mode="manual") # New random values to update our course run setattr(course_run, field, getattr(stub, field)) course_run.save() self.assertEqual(title_obj.publisher_state, PUBLISHER_STATE_DEFAULT) course_run.mark_course_dirty() title_obj.refresh_from_db() self.assertEqual(title_obj.publisher_state, PUBLISHER_STATE_DIRTY)
def test_models_course_run_mark_dirty_create_course_run(self): """ Creating a new course run in a scheduled state should mark the related course page dirty. """ course = CourseFactory(should_publish=True) title_obj = course.extended_object.title_set.first() self.assertEqual(title_obj.publisher_state, PUBLISHER_STATE_DEFAULT) course_run = CourseRunFactory(direct_course=course) course_run.mark_course_dirty() title_obj.refresh_from_db() self.assertEqual(title_obj.publisher_state, PUBLISHER_STATE_DIRTY)
def test_models_course_run_mark_dirty_update_to_be_scheduled_remain(self): """ Modifying a course run to be scheduled but keeping its state "to be scheduled" should not mark the related course page dirty. """ course_run = CourseRunFactory(start=None) self.assertTrue(course_run.direct_course.extended_object.publish("en")) title_obj = course_run.direct_course.extended_object.title_set.first() course_run.end = timezone.now() course_run.save() course_run.mark_course_dirty() title_obj.refresh_from_db() self.assertEqual(title_obj.publisher_state, PUBLISHER_STATE_DEFAULT)
def test_models_course_run_mark_dirty_update_to_be_scheduled_to(self): """ Resetting a scheduled course run to a state "to be scheduled" 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.start = None course_run.save() course_run.mark_course_dirty() title_obj.refresh_from_db() self.assertEqual(title_obj.publisher_state, PUBLISHER_STATE_DIRTY)
def test_models_course_run_mark_dirty_update_to_be_scheduled_from(self): """ Scheduling a course run that was to be scheduled should mark the related course page dirty. """ now = timezone.now() course_run = CourseRunFactory(start=None, enrollment_start=now) self.assertTrue(course_run.direct_course.extended_object.publish("en")) title_obj = course_run.direct_course.extended_object.title_set.first() course_run.start = now course_run.save() course_run.mark_course_dirty() title_obj.refresh_from_db() self.assertEqual(title_obj.publisher_state, PUBLISHER_STATE_DIRTY)
def test_models_course_run_mark_dirty_create_course_run_to_be_scheduled(self): """ Creating a new course run in a state "to be scheduled" should not mark the related course page dirty. """ course = CourseFactory(should_publish=True) title_obj = course.extended_object.title_set.first() self.assertEqual(title_obj.publisher_state, PUBLISHER_STATE_DEFAULT) field = random.choice(["start", "enrollment_start"]) course_run = CourseRunFactory(**{field: None}) course_run.mark_course_dirty() title_obj.refresh_from_db() self.assertEqual(title_obj.publisher_state, PUBLISHER_STATE_DEFAULT)
def test_models_course_run_mark_dirty_any_field(self): """ Updating the value of any editable field on the course run should mark the related course page dirty (waiting to be published). """ fields = map( lambda f: f.name, filter( lambda f: f.editable and not f.auto_created and not f.name == "direct_course", CourseRun._meta.fields, ), ) stub = CourseRunFactory( sync_mode="manual", catalog_visibility=CourseRunCatalogVisibility.COURSE_ONLY, ) # New random values to update our course run for field in fields: course_run = CourseRunFactory() self.assertTrue( course_run.direct_course.extended_object.publish("en")) title_obj = course_run.direct_course.extended_object.title_set.first( ) setattr(course_run, field, getattr(stub, field)) course_run.save() self.assertEqual( title_obj.publisher_state, PUBLISHER_STATE_DEFAULT, msg=f"Before refreshing from db {field:s}", ) course_run.mark_course_dirty() title_obj.refresh_from_db() self.assertEqual( title_obj.publisher_state, PUBLISHER_STATE_DIRTY, msg=f"After refreshing from db {field:s}", )