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_learning_units_summary_list_by_client_xls_empty(self): # Generate data now = datetime.datetime.now() EntityVersionFactory(entity=self.an_entity, start_date=now, end_date=datetime.datetime(now.year+1, 9, 15), entity_type='INSTITUTE') luy = self._create_learning_unit_year_for_entity(self.an_entity, "LBIR1100") self._create_entity_calendar(self.an_entity) TeachingMaterialFactory(learning_unit_year=luy, title="Magic wand", mandatory=False) TeachingMaterialFactory(learning_unit_year=luy, title="Broomsticks", mandatory=False) luy_without_mandatory_teaching_material = self._create_learning_unit_year_for_entity(self.an_entity, "LBIR1101") TeachingMaterialFactory(learning_unit_year=luy_without_mandatory_teaching_material, title="cauldron", mandatory=False) # Test the view self.client.force_login(self.faculty_user) response = self.client.get(self.url, data={ 'academic_year_id': starting_academic_year().id, 'xls_status': 'xls_teaching_material' }) # OK, the server will stay in the page self.assertEqual(response.status_code, 200) # A warning message should be generated messages = list(get_messages(response.wsgi_request)) self.assertEqual(len(messages), 1) self.assertEqual(str(messages[0]), _("the list to generate is empty.").capitalize())
def setUpTestData(cls): now = datetime.datetime.now() cls.academic_year = create_current_academic_year() cls.previous_academic_year = GenerateAcademicYear( cls.academic_year.year - 1, cls.academic_year.year - 1).academic_years[0] AcademicCalendarFactory( academic_year=cls.previous_academic_year, start_date=now - datetime.timedelta(days=5), end_date=now + datetime.timedelta(days=15), reference=academic_calendar_type.SUMMARY_COURSE_SUBMISSION) cls.requirement_entity_version = EntityVersionFactory( entity__organization__type=organization_type.MAIN, start_date=now, end_date=datetime.datetime(now.year + 1, 9, 15), entity_type=entity_type.INSTITUTE) cls.url = reverse('learning_units_summary') cls.faculty_person = FacultyManagerFactory( 'can_access_learningunit', 'can_edit_learningunit_pedagogy') PersonEntityFactory(person=cls.faculty_person, entity=cls.requirement_entity_version.entity) # Generate data for XLS export cls.learning_unit_year_with_mandatory_teaching_materials = LearningUnitYearFactory( acronym="LBIR1100", academic_year=cls.academic_year, learning_container_year__academic_year=cls.academic_year, learning_container_year__acronym="LBIR1100", learning_container_year__requirement_entity=cls. requirement_entity_version.entity) TeachingMaterialFactory( learning_unit_year=cls. learning_unit_year_with_mandatory_teaching_materials, title="Magic wand", mandatory=True, ) TeachingMaterialFactory( learning_unit_year=cls. learning_unit_year_with_mandatory_teaching_materials, title="Broomsticks", mandatory=False, ) cls.learning_unit_year_without_mandatory_teaching_materials = LearningUnitYearFactory( acronym="LDROI1600", academic_year=cls.academic_year, learning_container_year__academic_year=cls.academic_year, learning_container_year__acronym="LDROI1600", learning_container_year__requirement_entity=cls. requirement_entity_version.entity) TeachingMaterialFactory( learning_unit_year=cls. learning_unit_year_without_mandatory_teaching_materials, title="cauldron", mandatory=False, )
def test_build_description_fiche_cols(self): teaching_material_1 = TeachingMaterialFactory( learning_unit_year=self.luy, title='Title mandatory', mandatory=True) teaching_material_2 = TeachingMaterialFactory( learning_unit_year=self.luy, title='Title non-mandatory', mandatory=False) _initialize_cms_data_description_fiche(self.gey) description_fiche = _build_description_fiche_cols(self.luy, self.gey) self.assertEqual(description_fiche.resume, "{}".format(CMS_TXT_WITH_LIST_AFTER_FORMATTING)) self.assertEqual(description_fiche.resume_en, "{}".format(CMS_TXT_WITH_LIST_AFTER_FORMATTING)) self.assertEqual(description_fiche.teaching_methods, "{}".format(CMS_TXT_WITH_LIST_AFTER_FORMATTING)) self.assertEqual(description_fiche.teaching_methods_en, "{}".format(CMS_TXT_WITH_LIST_AFTER_FORMATTING)) self.assertEqual(description_fiche.evaluation_methods, "{}".format(CMS_TXT_WITH_LIST_AFTER_FORMATTING)) self.assertEqual(description_fiche.evaluation_methods_en, "{}".format(CMS_TXT_WITH_LIST_AFTER_FORMATTING)) self.assertEqual(description_fiche.other_informations, "{}".format(CMS_TXT_WITH_LIST_AFTER_FORMATTING)) self.assertEqual(description_fiche.other_informations_en, "{}".format(CMS_TXT_WITH_LIST_AFTER_FORMATTING)) self.assertEqual(description_fiche.mobility, "{}".format(CMS_TXT_WITH_LIST_AFTER_FORMATTING)) self.assertEqual(description_fiche.bibliography, "{}".format(CMS_TXT_WITH_LIST_AFTER_FORMATTING)) self.assertEqual(description_fiche.online_resources, "{}".format(CMS_TXT_WITH_LINK_AFTER_FORMATTING)) self.assertEqual(description_fiche.online_resources_en, "{}".format(CMS_TXT_WITH_LINK_AFTER_FORMATTING)) self.assertEqual( description_fiche.teaching_materials, "{} - {}\n{} - {}".format(_('Mandatory'), teaching_material_1.title, _('Non-mandatory'), teaching_material_2.title))
def test_save_with_postponement(self, mock_postpone_teaching_materials): """In this test, we ensure that if we modify UE of N+1 or N+X => The postponement until the lastest UE""" luy_in_future = self.luys[self.current_ac.year + 1] teaching_material = TeachingMaterialFactory.build(learning_unit_year=luy_in_future) post_data = _get_valid_teaching_material_form_data(teaching_material) teaching_material_form = TeachingMaterialModelForm(post_data) self.assertTrue(teaching_material_form.is_valid(), teaching_material_form.errors) teaching_material_form.save(learning_unit_year=luy_in_future) self.assertTrue(mock_postpone_teaching_materials.called)
def test_save_without_postponement(self, mock_postpone_teaching_materials): """In this test, we ensure that if we modify UE of N or N-... => The postponement is not done for teaching materials""" teaching_material = TeachingMaterialFactory.build(learning_unit_year=self.current_luy, mandatory=True) post_data = _get_valid_teaching_material_form_data(teaching_material) teaching_material_form = TeachingMaterialModelForm(post_data) self.assertTrue(teaching_material_form.is_valid(), teaching_material_form.errors) teaching_material_form.save(learning_unit_year=self.current_luy) self.assertFalse(mock_postpone_teaching_materials.called)
def setUp(self): self.teaching_material = TeachingMaterialFactory( learning_unit_year=self.learning_unit_year) self.url = reverse('teaching_material_delete', kwargs={ 'learning_unit_year_id': self.learning_unit_year.id, 'teaching_material_id': self.teaching_material.id }) self.client.force_login(self.person.user)
def setUpTestData(cls): cls.luy = LearningUnitYearFactory() cls.teaching_materials = TeachingMaterialFactory( learning_unit_year=cls.luy) cls.person = PersonFactory() url_kwargs = { 'acronym': cls.luy.acronym, 'year': cls.luy.academic_year.year } cls.url = reverse( 'learning_unit_api_v1:learningunitteachingmaterials_read', kwargs=url_kwargs)
def test_find_by_learning_unit_year(self): """This test will ensure that the order is determied by 'ORDER' field""" ac_year_2015 = self.ac_years_containers.academic_years[0] luy = self.luys[ac_year_2015] tm_1 = TeachingMaterialFactory(learning_unit_year=luy) tm_2 = TeachingMaterialFactory(learning_unit_year=luy) tm_3 = TeachingMaterialFactory(learning_unit_year=luy) result = find_by_learning_unit_year(luy) self.assertEqual(result.count(), 3) self.assertEqual(result[0], tm_1) self.assertEqual(result[1], tm_2) self.assertEqual(result[2], tm_3) # Set tm_1 to bottom and check result [Must use QS] TeachingMaterial.objects.get(pk=tm_1.pk).bottom() result = find_by_learning_unit_year(luy) self.assertEqual(result.count(), 3) self.assertEqual(result[0], tm_2) self.assertEqual(result[1], tm_3) self.assertEqual(result[2], tm_1)
def setUp(self): self.current_academic_year = create_current_academic_year() self.learning_unit_year = LearningUnitYearFactory( subtype=FULL, academic_year=self.current_academic_year, learning_container_year__academic_year=self.current_academic_year ) self.teaching_material = TeachingMaterialFactory(learning_unit_year=self.learning_unit_year) self.url = reverse('teaching_material_edit', kwargs={ 'learning_unit_year_id': self.learning_unit_year.id, 'teaching_material_id': self.teaching_material.id }) self.person = _get_central_manager_person_with_permission() self.client.force_login(self.person.user)
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 _ 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 setUpTestData(cls): cls._create_luy() cls._set_entities() cls._create_cms_data() cls.teaching_material = TeachingMaterialFactory( learning_unit_year=cls.l_unit_yr_1, title='Teaching material title') cls.learning_unit_achievement_fr = LearningAchievementFactory( learning_unit_year=cls.l_unit_yr_1, language=LanguageFactory(code='FR')) cls.learning_unit_achievement_en = LearningAchievementFactory( learning_unit_year=cls.l_unit_yr_1, language=LanguageFactory(code='EN')) cls.entity_requirement = EntityVersion.objects.filter(entity=OuterRef( 'learning_container_year__requirement_entity'), ).current( OuterRef('academic_year__start_date')).values('acronym')[:1]
def setUpTestData(cls): teaching_materials = TeachingMaterialFactory() cls.serializer = LearningUnitTeachingMaterialSerializer( teaching_materials)
def test_learning_units_summary_list_by_client_xls(self): # Generate data now = datetime.datetime.now() EntityVersionFactory(entity=self.an_entity, start_date=now, end_date=datetime.datetime(now.year+1, 9, 15), entity_type='INSTITUTE') luy = self._create_learning_unit_year_for_entity(self.an_entity, "LBIR1100") self._create_entity_calendar(self.an_entity) TeachingMaterialFactory(learning_unit_year=luy, title="Magic wand", mandatory=True) TeachingMaterialFactory(learning_unit_year=luy, title="Broomsticks", mandatory=False) luy_without_mandatory_teaching_material = self._create_learning_unit_year_for_entity(self.an_entity, "LBIR1101") TeachingMaterialFactory(learning_unit_year=luy_without_mandatory_teaching_material, title="cauldron", mandatory=False) bibliography = TranslatedTextFactory( text_label=TextLabelFactory(label='bibliography'), entity=LEARNING_UNIT_YEAR, text="<ul><li>Test</li></ul>", reference=luy.pk, language='fr-be' ) online_resources = TranslatedTextFactory( text_label=TextLabelFactory(label='online_resources'), entity=LEARNING_UNIT_YEAR, text="<a href='test_url'>TestURL</a>", reference=luy.pk, language='fr-be' ) online_resources_en = TranslatedTextFactory( text_label=TextLabelFactory(label='online_resources'), entity=LEARNING_UNIT_YEAR, text="<a href='test_url'>TestURL EN</a>", reference=luy.pk, language='en' ) # Test the view self.client.force_login(self.faculty_user) response = self.client.get(self.url, data={ 'academic_year_id': starting_academic_year().id, 'xls_status': 'xls_teaching_material' }) # OK, the server returned the xls file self.assertEqual(response.status_code, 200) wb = load_workbook(BytesIO(response.content), read_only=True) sheet = wb.active data = sheet['A1': 'G3'] # Check the first row content titles = next(data) title_values = list(t.value for t in titles) self.assertEqual(title_values, [ str(_('code')).title(), str(_('Title')), str(_('Req. Entity')).title(), str(_('bibliography')).title(), str(_('teaching materials')).title(), str("{} - Fr-Be".format(_('online resources'))).title(), str("{} - En".format(_('online resources'))).title(), ]) # Check data from the luy first_luy = next(data) first_luy_values = list(t.value for t in first_luy) self.assertEqual(first_luy_values, [ luy.acronym, luy.complete_title, str(luy.requirement_entity), "Test\n", "Magic wand", "TestURL - [test_url] \n", "TestURL EN - [test_url] \n" ]) # The second luy has no mandatory teaching material with self.assertRaises(StopIteration): next(data)
def _create_teaching_material_for_luy(luy, quantity=10): for _ in range(quantity): TeachingMaterialFactory(learning_unit_year=luy)
def test_learning_units_summary_list_by_client_xls(self): # Generate data now = datetime.datetime.now() EntityVersionFactory(entity=self.an_entity, start_date=now, end_date=datetime.datetime(now.year + 1, 9, 15), entity_type='INSTITUTE') luy = self._create_learning_unit_year_for_entity(self.an_entity) self._create_entity_calendar(self.an_entity) TeachingMaterialFactory(learning_unit_year=luy, title="Magic wand", mandatory=True) TeachingMaterialFactory(learning_unit_year=luy, title="Broomsticks", mandatory=False) luy_without_mandatory_teaching_material = self._create_learning_unit_year_for_entity( self.an_entity) TeachingMaterialFactory( learning_unit_year=luy_without_mandatory_teaching_material, title="cauldron", mandatory=False) # Test the view self.client.force_login(self.faculty_user) response = self.client.get(self.url, data={ 'academic_year_id': starting_academic_year().id, 'xls_status': 'xls_teaching_material' }) # OK, the server returned the xls file self.assertEqual(response.status_code, 200) wb = load_workbook(BytesIO(response.content), read_only=True) sheet = wb.active data = sheet['A1':'F3'] # Check the first row content titles = next(data) title_values = list(t.value for t in titles) self.assertEqual(title_values, [ str(_('code')).title(), str(_('title')).title(), str(_('requirement_entity_small')).title(), str(_('bibliography')).title(), str(_('teaching materials')).title(), str(_('online resources')).title(), ]) # Check data from the luy first_luy = next(data) first_luy_values = list(t.value for t in first_luy) self.assertEqual(first_luy_values, [ luy.acronym, luy.complete_title, str(luy.requirement_entity), " ", "Magic wand", " " ]) # The second luy has no mandatory teaching material with self.assertRaises(StopIteration): next(data)
def setUp(self): super().setUp() self.teaching_material = TeachingMaterialFactory( learning_unit_year=self.learning_unit_year)