def test_postpone_override_teaching_materials(self): """In this test, we ensure that postponement will override encoded in future""" luy_in_future = self.luys[ self.ac_years_containers.academic_years[2]] # Take ac year 2017 teaching_material_in_future = TeachingMaterialFactory( learning_unit_year=luy_in_future) ac_year_2015 = self.ac_years_containers.academic_years[0] start_luy = self.luys[ac_year_2015] teaching_material_postponed = TeachingMaterialFactory( learning_unit_year=start_luy) # Make postponement postpone_teaching_materials(start_luy) # Ensure that teaching_material_in_future is deleted self.assertFalse( TeachingMaterial.objects.filter( pk=teaching_material_in_future.pk).exists()) expected_result = [{ 'title': teaching_material_postponed.title, 'mandatory': teaching_material_postponed.mandatory, 'learning_unit_year_id': luy_in_future.id }] result = TeachingMaterial.objects.filter(learning_unit_year=luy_in_future)\ .values('title', 'mandatory', 'learning_unit_year_id') self.assertListEqual(list(result), expected_result)
def test_postpone_teaching_materials(self): # Create multiple teaching material in 2015 NB_TO_CREATE = 10 ac_year_2015 = self.ac_years_containers.academic_years[0] start_luy = self.luys[ac_year_2015] for i in range(0, NB_TO_CREATE): TeachingMaterialFactory(learning_unit_year=start_luy) # Make postponement postpone_teaching_materials(start_luy) # Check if the teaching material has been postponed in future for ac_year in self.ac_years_containers.academic_years: self.assertEqual( TeachingMaterial.objects.filter( learning_unit_year__academic_year=ac_year).count(), NB_TO_CREATE)
def check_teaching_materials_postponement(luy): if is_pedagogy_data_must_be_postponed(luy): from base.models import teaching_material teaching_material.postpone_teaching_materials(luy) # For sync purpose, we need to trigger an update of the bibliography when we update teaching materials update_bibliography_changed_field_in_cms(luy)