def setUpTestData(cls): cls.person = PersonFactory() cls.education_group_year_1 = EducationGroupYearFactory() cls.education_group_year_2 = EducationGroupYearFactory() cls.education_group_year_3 = EducationGroupYearFactory() cls.learning_unit_year_1 = LearningUnitYearFactory() cls.learning_unit_year_2 = LearningUnitYearFactory() cls.learning_component_year_1 = LearningComponentYearFactory( learning_container_year=cls.learning_unit_year_1.learning_container_year, hourly_volume_partial_q1=10, hourly_volume_partial_q2=10) cls.learning_component_year_2 = LearningComponentYearFactory( learning_container_year=cls.learning_unit_year_1.learning_container_year, hourly_volume_partial_q1=10, hourly_volume_partial_q2=10) cls.learning_unit_component_1 = LearningUnitComponentFactory( learning_component_year=cls.learning_component_year_1, learning_unit_year=cls.learning_unit_year_1) cls.learning_unit_component_2 = LearningUnitComponentFactory( learning_component_year=cls.learning_component_year_2, learning_unit_year=cls.learning_unit_year_1) cls.group_element_year_1 = GroupElementYearFactory(parent=cls.education_group_year_1, child_branch=cls.education_group_year_2) cls.group_element_year_2 = GroupElementYearFactory(parent=cls.education_group_year_2, child_branch=None, child_leaf=cls.learning_unit_year_1) cls.group_element_year_3 = GroupElementYearFactory(parent=cls.education_group_year_1, child_branch=cls.education_group_year_3) cls.group_element_year_4 = GroupElementYearFactory(parent=cls.education_group_year_3, child_branch=None, child_leaf=cls.learning_unit_year_2) cls.a_superuser = SuperUserFactory()
def _create_learning_container_with_components( acronym, academic_year, volume_lecturing=None, volume_practical_exercices=None): l_container = LearningContainerYearFactory(acronym=acronym, academic_year=academic_year) a_learning_unit_year = LearningUnitYearFactory( acronym=acronym, academic_year=academic_year, specific_title=l_container.common_title, learning_container_year=l_container) if volume_lecturing: a_component = LearningComponentYearFactory( learning_container_year=l_container, type=learning_component_year_type.LECTURING, volume_declared_vacant=volume_lecturing) LearningUnitComponentFactory(learning_unit_year=a_learning_unit_year, learning_component_year=a_component, type=component_type.LECTURING) if volume_practical_exercices: a_component = LearningComponentYearFactory( learning_container_year=l_container, type=learning_component_year_type.PRACTICAL_EXERCISES, volume_declared_vacant=volume_practical_exercices) LearningUnitComponentFactory(learning_unit_year=a_learning_unit_year, learning_component_year=a_component, type=component_type.PRACTICAL_EXERCISES)
def _link_components_and_learning_unit_year_to_container( l_container, acronym, volume_lecturing=None, volume_practical_exercices=None, subtype=learning_unit_year_subtypes.FULL): a_learning_unit_year = LearningUnitYearFactory( acronym=acronym, academic_year=l_container.academic_year, specific_title=l_container.common_title, subtype=subtype) if volume_lecturing: a_component = LearningComponentYearFactory( learning_container_year=l_container, type=learning_component_year_type.LECTURING, volume_declared_vacant=volume_lecturing) LearningUnitComponentFactory(learning_unit_year=a_learning_unit_year, learning_component_year=a_component, type=component_type.LECTURING) if volume_practical_exercices: a_component = LearningComponentYearFactory( learning_container_year=l_container, type=learning_component_year_type.PRACTICAL_EXERCISES, volume_declared_vacant=volume_practical_exercices) LearningUnitComponentFactory(learning_unit_year=a_learning_unit_year, learning_component_year=a_component, type=component_type.PRACTICAL_EXERCISES) return l_container
def test_learning_unit_usage_two_usages(self): learning_container_yr = LearningContainerYearFactory( academic_year=self.current_academic_year, acronym='LBIOL') learning_unit_yr_1 = LearningUnitYearFactory( academic_year=self.current_academic_year, acronym='LBIOLA', quadrimester='Q1', learning_container_year=learning_container_yr) learning_unit_yr_2 = LearningUnitYearFactory( academic_year=self.current_academic_year, acronym='LBIOLB', learning_container_year=learning_container_yr) learning_component_yr = LearningComponentYearFactory( learning_container_year=learning_container_yr) LearningUnitComponentFactory( learning_unit_year=learning_unit_yr_1, learning_component_year=learning_component_yr) LearningUnitComponentFactory( learning_unit_year=learning_unit_yr_2, learning_component_year=learning_component_yr) self.assertEqual( learning_unit_business._learning_unit_usage(learning_component_yr), 'LBIOLA (Q1), LBIOLB (?)')
def setUp(self): self.current_academic_year = create_current_academic_year() self.person = PersonFactory() self.education_group_year_1 = EducationGroupYearFactory() self.education_group_year_2 = EducationGroupYearFactory() self.education_group_year_3 = EducationGroupYearFactory() self.learning_unit_year_1 = LearningUnitYearFactory() self.learning_component_year_1 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_1. learning_container_year, hourly_volume_partial_q1=10, hourly_volume_partial_q2=10) self.learning_component_year_2 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_1. learning_container_year, hourly_volume_partial_q1=10, hourly_volume_partial_q2=10) self.learning_unit_component_1 = LearningUnitComponentFactory( learning_component_year=self.learning_component_year_1, learning_unit_year=self.learning_unit_year_1) self.learning_unit_component_2 = LearningUnitComponentFactory( learning_component_year=self.learning_component_year_2, learning_unit_year=self.learning_unit_year_1) self.learning_unit_year_without_container = LearningUnitYearFactory( learning_container_year=None) self.group_element_year_1 = GroupElementYearFactory( parent=self.education_group_year_1, child_branch=self.education_group_year_2) self.group_element_year_2 = GroupElementYearFactory( parent=self.education_group_year_1, child_branch=None, child_leaf=self.learning_unit_year_1) self.group_element_year_3 = GroupElementYearFactory( parent=self.education_group_year_1, child_branch=self.education_group_year_3) self.group_element_year_without_container = GroupElementYearFactory( parent=self.education_group_year_1, child_branch=None, child_leaf=self.learning_unit_year_without_container) self.user = UserFactory() self.person = PersonFactory(user=self.user) self.user.user_permissions.add( Permission.objects.get(codename="can_access_education_group")) self.url = reverse("education_group_content", args=[ self.education_group_year_1.id, self.education_group_year_1.id, ]) self.client.force_login(self.user)
def _create_learning_unit_year_with_components(l_container, create_lecturing_component=True, create_pratical_component=True): language = LanguageFactory(code='EN', name='English') a_learning_unit_year = LearningUnitYearFactory( learning_container_year=l_container, acronym=l_container.acronym, academic_year=l_container.academic_year, status=True, language=language, campus=CampusFactory(name='MIT')) if create_lecturing_component: a_component = LearningComponentYearFactory( learning_container_year=l_container, type=learning_component_year_type.LECTURING, planned_classes=1) LearningUnitComponentFactory(learning_unit_year=a_learning_unit_year, learning_component_year=a_component) if create_pratical_component: a_component = LearningComponentYearFactory( learning_container_year=l_container, type=learning_component_year_type.PRACTICAL_EXERCISES, planned_classes=1) LearningUnitComponentFactory(learning_unit_year=a_learning_unit_year, learning_component_year=a_component) return a_learning_unit_year
def test_search(self): a_learning_unit_year = LearningUnitYearFactory(academic_year=self.an_academic_year) lecturing_learning_unit_component = LearningUnitComponentFactory(learning_unit_year=a_learning_unit_year, type=component_type.LECTURING) practical_learning_unit_component = LearningUnitComponentFactory(learning_unit_year=a_learning_unit_year, type=component_type.PRACTICAL_EXERCISES) self.assertCountEqual(mdl_base.learning_unit_component.search(a_learning_unit_year, None), [lecturing_learning_unit_component, practical_learning_unit_component])
def _create_parent_with_components(self, learning_container_year): # Create learning unit year full luy_full = LearningUnitYearFactory( learning_container_year=learning_container_year, academic_year=learning_container_year.academic_year, acronym="LBIR1100", subtype=learning_unit_year_subtypes.FULL) ## Create component CM cm_component = LearningComponentYearFactory( acronym="CM", type=learning_component_year_type.LECTURING, learning_container_year=learning_container_year, planned_classes=1) LearningUnitComponentFactory(learning_unit_year=luy_full, learning_component_year=cm_component) ### Assign Volume cm_volume_parent = { entity_container_year_link_type.REQUIREMENT_ENTITY: { 'vol_tot': 50 }, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1: { 'vol_tot': 10 }, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_2: { 'vol_tot': 20 }, } _assign_volume(learning_container_year, cm_component, cm_volume_parent) ## Create component TP tp_component = LearningComponentYearFactory( acronym="TP", type=learning_component_year_type.PRACTICAL_EXERCISES, learning_container_year=learning_container_year, planned_classes=1) LearningUnitComponentFactory(learning_unit_year=luy_full, learning_component_year=tp_component) ### Assign Volume tp_volume_parent = { entity_container_year_link_type.REQUIREMENT_ENTITY: { 'vol_tot': 30 }, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1: { 'vol_tot': 10 }, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_2: { 'vol_tot': 10 }, } _assign_volume(learning_container_year, tp_component, tp_volume_parent) return luy_full
def setUpTestData(cls): cls.person = PersonFactory() cls.education_group_year_1 = EducationGroupYearFactory( title_english="") cls.education_group_year_2 = EducationGroupYearFactory( title_english="") cls.education_group_year_3 = EducationGroupYearFactory( title_english="") cls.learning_unit_year_1 = LearningUnitYearFactory( specific_title_english="") cls.learning_unit_year_2 = LearningUnitYearFactory( specific_title_english="") cls.learning_component_year_1 = LearningComponentYearFactory( learning_container_year=cls.learning_unit_year_1. learning_container_year, hourly_volume_partial_q1=10, hourly_volume_partial_q2=10) cls.learning_component_year_2 = LearningComponentYearFactory( learning_container_year=cls.learning_unit_year_1. learning_container_year, hourly_volume_partial_q1=10, hourly_volume_partial_q2=10) cls.learning_unit_component_1 = LearningUnitComponentFactory( learning_component_year=cls.learning_component_year_1, learning_unit_year=cls.learning_unit_year_1) cls.learning_unit_component_2 = LearningUnitComponentFactory( learning_component_year=cls.learning_component_year_2, learning_unit_year=cls.learning_unit_year_1) cls.group_element_year_1 = GroupElementYearFactory( parent=cls.education_group_year_1, child_branch=cls.education_group_year_2) cls.group_element_year_2 = GroupElementYearFactory( parent=cls.education_group_year_2, child_branch=None, child_leaf=cls.learning_unit_year_1) cls.group_element_year_3 = GroupElementYearFactory( parent=cls.education_group_year_1, child_branch=cls.education_group_year_3) cls.group_element_year_4 = GroupElementYearFactory( parent=cls.education_group_year_3, child_branch=None, child_leaf=cls.learning_unit_year_2) cls.user = UserFactory() cls.person = PersonFactory(user=cls.user) cls.user.user_permissions.add( Permission.objects.get(codename="can_access_education_group")) cls.url = reverse("education_group_utilization", args=[ cls.education_group_year_2.id, cls.education_group_year_2.id, ])
def _create_learning_unit_year_with_components(academic_year, l_container, acronym, subtype): l_unit_year = LearningUnitYearFactory(academic_year=academic_year, learning_container_year=l_container, acronym=acronym, subtype=subtype) # Create component - CM - TP l_component_cm = LearningComponentYearFactory(learning_container_year=l_container, type=learning_component_year_type.LECTURING, acronym="CM") l_component_tp = LearningComponentYearFactory(learning_container_year=l_container, type=learning_component_year_type.PRACTICAL_EXERCISES, acronym="TP") # Create Link between UE and component LearningUnitComponentFactory(learning_unit_year=l_unit_year, learning_component_year=l_component_cm) LearningUnitComponentFactory(learning_unit_year=l_unit_year, learning_component_year=l_component_tp)
def setUp(self): self.academic_year = AcademicYearFactory(year=2016) self.learning_unit_years = [ LearningUnitYearFactory(academic_year=self.academic_year) for x in range(2) ] self.learning_container_years = [ LearningContainerYearFactory(academic_year=self.academic_year) for x in range(2) ] self.learning_component_years = [ LearningComponentYearFactory( learning_container_year=self.learning_container_years[x]) for x in range(2) ] self.learning_unit_components = [ LearningUnitComponentFactory( learning_unit_year=self.learning_unit_years[x], learning_component_year=self.learning_component_years[x]) for x in range(2) ] self.learning_class_years = [ LearningClassYearFactory( learning_component_year=self.learning_component_years[x]) for x in range(2) ]
def create_learning_unit_years_and_dependencies(self): l1 = LearningUnitFactory() learning_unit_years = [] for year in range(4): ac_year = AcademicYearFactory(year=2000 + year) l_containeryear = LearningContainerYearFactory( academic_year=ac_year) EntityContainerYearFactory( learning_container_year=l_containeryear, entity=self.entity_version.entity, type=entity_container_year_link_type.REQUIREMENT_ENTITY) learning_unit_year = LearningUnitYearFactory( learning_unit=l1, academic_year=ac_year, learning_container_year=l_containeryear) learning_unit_years.append(learning_unit_year) learning_unit_years[1].subtype = learning_unit_year_subtypes.FULL learning_unit_years[1].save() lcomponent = LearningComponentYearFactory() LearningClassYearFactory(learning_component_year=lcomponent) LearningClassYearFactory(learning_component_year=lcomponent) LearningUnitComponentFactory(learning_unit_year=learning_unit_years[1], learning_component_year=lcomponent) return learning_unit_years
def _setup_learning_component_year(learning_unit_year, component_type): component = LearningComponentYearFactory(learning_container_year=learning_unit_year.learning_container_year, type=component_type) LearningUnitComponentFactory(learning_unit_year=learning_unit_year, learning_component_year=component) return component
def setUp(self): self.academic_year = AcademicYearFactory(year=timezone.now().year) self.l_unit_1 = LearningUnitYearFactory( acronym="LBIR1212", academic_year=self.academic_year, subtype=learning_unit_year_subtypes.FULL) component = LearningUnitComponentFactory( learning_unit_year=self.l_unit_1) self.attribution_charge_news = [ AttributionChargeNewFactory( learning_component_year=component.learning_component_year) for _ in range(5) ]
def setUp(self): generator_container = GenerateContainer(datetime.date.today().year-2, datetime.date.today().year) self.learning_unit_yr_1 = generator_container.generated_container_years[0].learning_unit_year_full self.learning_unit_yr_1.entities = { entity_container_year_link_type.REQUIREMENT_ENTITY: EntityVersionFactory(acronym=ACRONYM_REQUIREMENT), entity_container_year_link_type.ALLOCATION_ENTITY: EntityVersionFactory(acronym=ACRONYM_ALLOCATION) } component_1 = LearningUnitComponentFactory(learning_unit_year=self.learning_unit_yr_1) self.attribution_1 = AttributionChargeNewFactory(learning_component_year=component_1.learning_component_year) self.learning_unit_yr_1.attribution_charge_news = attribution_charge_new. \ find_attribution_charge_new_by_learning_unit_year(self.learning_unit_yr_1) self.user = UserFactory()
def _create_learning_unit_year_with_components(l_container, create_lecturing_component=True, create_pratical_component=True): a_learning_unit_year = LearningUnitYearFactory(learning_container_year=l_container, acronym=l_container.acronym, academic_year=l_container.academic_year, status=True) if create_lecturing_component: a_component = LearningComponentYearFactory( learning_container_year=l_container, type=learning_component_year_type.LECTURING, planned_classes=1 ) LearningUnitComponentFactory(learning_unit_year=a_learning_unit_year, learning_component_year=a_component) if create_pratical_component: a_component = LearningComponentYearFactory( learning_container_year=l_container, type=learning_component_year_type.PRACTICAL_EXERCISES, planned_classes=1 ) LearningUnitComponentFactory(learning_unit_year=a_learning_unit_year, learning_component_year=a_component) return a_learning_unit_year
def test_component_save(self): learning_unit_yr = LearningUnitYearFactory( academic_year=self.current_academic_year, learning_container_year=self.learning_container_yr) learning_unit_compnt = LearningUnitComponentFactory( learning_unit_year=learning_unit_yr, learning_component_year=self.learning_component_yr) url = reverse('learning_unit_component_edit', args=[learning_unit_yr.id]) qs = 'learning_component_year_id={}'.format( self.learning_component_yr.id) response = self.client.post('{}?{}'.format(url, qs), data={"used_by": "on"}) self.learning_component_yr.refresh_from_db() self.assertEqual(response.status_code, 302)
def test_delete_learning_unit_component_class(self): # Composant annualisé est associé à son composant et à son conteneur annualisé learning_component_year = LearningComponentYearFactory( title="Cours magistral", acronym="/C", comment="TEST") learning_container_year = learning_component_year.learning_container_year number_classes = 10 for x in range(number_classes): LearningClassYearFactory( learning_component_year=learning_component_year) # Association du conteneur et de son composant dont les années académiques diffèrent l'une de l'autre learning_unit_component = LearningUnitComponentFactory( learning_component_year=learning_component_year) learning_unit_year = learning_unit_component.learning_unit_year learning_unit_year.learning_unit.start_year = 1900 learning_unit_year.subtype = learning_unit_year_subtypes.PARTIM learning_unit_year.save() msg = learning_unit_deletion.delete_from_given_learning_unit_year( learning_unit_year) msg_success = _( "%(subtype)s %(acronym)s has been deleted for the year %(year)s") self.assertEqual( msg_success % { 'subtype': _('The partim'), 'acronym': learning_unit_year.acronym, 'year': learning_unit_year.academic_year }, msg.pop()) self.assertEqual(LearningClassYear.objects.all().count(), 0) self.assertEqual(len(msg), number_classes) with self.assertRaises(ObjectDoesNotExist): LearningUnitComponent.objects.get(id=learning_component_year.id) with self.assertRaises(ObjectDoesNotExist): LearningUnitComponent.objects.get(id=learning_unit_component.id) # The learning_unit_container won't be deleted because the learning_unit_year is a partim self.assertEqual( learning_container_year, LearningContainerYear.objects.get(id=learning_container_year.id))
def test_component_save_delete_link(self): learning_unit_yr = LearningUnitYearFactory( academic_year=self.current_academic_year, learning_container_year=self.learning_container_yr) learning_unit_compnt = LearningUnitComponentFactory( learning_unit_year=learning_unit_yr, learning_component_year=self.learning_component_yr) url = reverse('learning_unit_component_edit', args=[learning_unit_yr.id]) qs = 'learning_component_year_id={}'.format( self.learning_component_yr.id) response = self.client.post('{}?{}'.format(url, qs), data={"planned_classes": "1"}) self.assertRaises( ObjectDoesNotExist, learning_unit_component.LearningUnitComponent.objects.filter( pk=learning_unit_compnt.id).first())
def test_learning_unit_usage_with_complete_LU(self): learning_container_yr = LearningContainerYearFactory( academic_year=self.current_academic_year, acronym='LBIOL') learning_unit_yr_1 = LearningUnitYearFactory( academic_year=self.current_academic_year, acronym='LBIOL', learning_container_year=learning_container_yr) learning_component_yr = LearningComponentYearFactory( learning_container_year=learning_container_yr) LearningUnitComponentFactory( learning_unit_year=learning_unit_yr_1, learning_component_year=learning_component_yr) self.assertEqual( learning_unit_view._learning_unit_usage(learning_component_yr), 'LBIOL')
def test_class_save_create_link(self): learning_unit_yr = LearningUnitYearFactory( academic_year=self.current_academic_year, learning_container_year=self.learning_container_yr) learning_unit_compnt = LearningUnitComponentFactory( learning_unit_year=learning_unit_yr, learning_component_year=self.learning_component_yr) learning_class_yr = LearningClassYearFactory( learning_component_year=self.learning_component_yr) response = self.client.post('{}?{}&{}'.format( reverse('learning_class_year_edit', args=[learning_unit_yr.id]), 'learning_component_year_id={}'.format( self.learning_component_yr.id), 'learning_class_year_id={}'.format(learning_class_yr.id)), data={"used_by": "on"}) self.assertTrue( learning_unit_component_class.search(learning_unit_compnt, learning_class_yr).exists())
def setUp(self): self.country = CountryFactory() self.academic_yr = AcademicYearFactory(year=timezone.now().year) self.start_date = self.academic_yr.start_date self.end_date = self.academic_yr.end_date self.list_learning_unit_container_year = self._create_list_containers( 4) self.list_learning_unit_year = self._create_list_learning_units_from_containers( self.list_learning_unit_container_year) self.list_entity_version = self._create_list_entities_version() self.list_entity_container_year = self._create_list_entity_container_years( self.list_entity_version, self.list_learning_unit_container_year) self.tutor = TutorFactory() self.attribution = AttributionNewFactory(tutor=self.tutor) self.learning_unit_component = LearningUnitComponentFactory( learning_unit_year=self.list_learning_unit_year[0]) self.attribution_charge_new = \ AttributionChargeNewFactory(attribution=self.attribution, learning_component_year=self.learning_unit_component.learning_component_year)
def test_delete_all_learning_units_year_case_error_have_attributionnew_with_charge(self): learning_unit_years = self.learning_unit_year_list ly1 = learning_unit_years[1] attrib_new_1 = AttributionNewFactory(learning_container_year=ly1.learning_container_year) learning_component_year_1 = LearningComponentYearFactory(learning_container_year=ly1.learning_container_year) LearningUnitComponentFactory(learning_unit_year=ly1, learning_component_year=learning_component_year_1) AttributionChargeNewFactory(attribution=attrib_new_1, learning_component_year=learning_component_year_1) request_factory = RequestFactory() request = request_factory.post(reverse(delete_all_learning_units_year, args=[ly1.id])) request.user = self.user setattr(request, 'session', 'session') setattr(request, '_messages', FallbackStorage(request)) response = delete_all_learning_units_year(request, ly1.id) # Get message from context msg = [m.message for m in get_messages(request)] msg_level = [m.level for m in get_messages(request)] self.assertEqual(len(msg), 1) self.assertIn(messages.ERROR, msg_level) # Check error message subtype = _('The partim') if ly1.is_partim() else _('The learning unit') self.assertIn(_("%(subtype)s %(acronym)s is assigned to %(tutor)s for the year %(year)s") % {'subtype': subtype, 'acronym': ly1.acronym, 'tutor': attrib_new_1.tutor, 'year': ly1.academic_year}, msg) # Check that record is not deleted self.assertTrue(LearningUnitYear.objects.filter(pk=ly1.pk).exists()) # Check redirection to identification self.assertEqual(response.status_code, 302) self.assertEqual(response.url, reverse('learning_unit', kwargs={'learning_unit_year_id': ly1.pk}))
def test_class_save_delete_link(self): learning_unit_yr = LearningUnitYearFactory( academic_year=self.current_academic_year, learning_container_year=self.learning_container_yr) learning_unit_compnt = LearningUnitComponentFactory( learning_unit_year=learning_unit_yr, learning_component_year=self.learning_component_yr) learning_class_yr = LearningClassYearFactory( learning_component_year=self.learning_component_yr) a_link = LearningUnitComponentClassFactory( learning_unit_component=learning_unit_compnt, learning_class_year=learning_class_yr) response = self.client.post('{}?{}&{}'.format( reverse('learning_class_year_edit', args=[learning_unit_yr.id]), 'learning_component_year_id={}'.format( self.learning_component_yr.id), 'learning_class_year_id={}'.format(learning_class_yr.id)), data={}) self.assertRaises( ObjectDoesNotExist, learning_unit_component_class.LearningUnitComponentClass.objects. filter(pk=a_link.id).first())
def test_learning_unit_usage_by_class_with_complete_LU(self): academic_year = AcademicYearFactory(year=2016) learning_container_yr = LearningContainerYearFactory( academic_year=academic_year, acronym='LBIOL') learning_unit_yr_1 = LearningUnitYearFactory( academic_year=academic_year, acronym='LBIOL', learning_container_year=learning_container_yr) learning_component_yr = LearningComponentYearFactory( learning_container_year=learning_container_yr) learning_unit_component = LearningUnitComponentFactory( learning_unit_year=learning_unit_yr_1, learning_component_year=learning_component_yr) learning_class_year = LearningClassYearFactory( learning_component_year=learning_component_yr) LearningUnitComponentClassFactory( learning_unit_component=learning_unit_component, learning_class_year=learning_class_year) self.assertEqual( learning_unit_business._learning_unit_usage_by_class( learning_class_year), 'LBIOL')
def setUp(self): self.education_group_year_1 = EducationGroupYearFactory(credits=10) self.education_group_year_2 = EducationGroupYearFactory(credits=20) self.learning_unit_year_1 = LearningUnitYearFactory() self.learning_unit_year_2 = LearningUnitYearFactory( periodicity=BIENNIAL_ODD) self.learning_unit_year_3 = LearningUnitYearFactory(status=False) self.learning_unit_year_4 = LearningUnitYearFactory( periodicity=BIENNIAL_EVEN) self.group_element_year_1 = GroupElementYearFactory( parent=self.education_group_year_1, child_branch=self.education_group_year_2, is_mandatory=True) self.group_element_year_2 = GroupElementYearFactory( parent=self.education_group_year_2, child_branch=None, child_leaf=self.learning_unit_year_1, is_mandatory=True) self.group_element_year_3 = GroupElementYearFactory( parent=self.education_group_year_2, child_branch=None, child_leaf=self.learning_unit_year_2, is_mandatory=True) self.group_element_year_4 = GroupElementYearFactory( parent=self.education_group_year_2, child_branch=None, child_leaf=self.learning_unit_year_3, is_mandatory=True) self.learning_component_year_1 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_1. learning_container_year, type=LECTURING) self.learning_component_year_2 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_1. learning_container_year, type=PRACTICAL_EXERCISES) self.learning_component_year_3 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_2. learning_container_year, type=LECTURING) self.learning_component_year_4 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_2. learning_container_year, type=PRACTICAL_EXERCISES) self.learning_component_year_5 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_3. learning_container_year, type=LECTURING) self.learning_component_year_6 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_3. learning_container_year, type=PRACTICAL_EXERCISES) self.learning_component_year_7 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_4. learning_container_year, type=LECTURING) self.learning_unit_component_1 = LearningUnitComponentFactory( learning_unit_year=self.learning_unit_year_1, learning_component_year=self.learning_component_year_1) self.learning_unit_component_2 = LearningUnitComponentFactory( learning_unit_year=self.learning_unit_year_1, learning_component_year=self.learning_component_year_2) self.learning_unit_component_3 = LearningUnitComponentFactory( learning_unit_year=self.learning_unit_year_2, learning_component_year=self.learning_component_year_3) self.learning_unit_component_4 = LearningUnitComponentFactory( learning_unit_year=self.learning_unit_year_2, learning_component_year=self.learning_component_year_4) self.learning_unit_component_5 = LearningUnitComponentFactory( learning_unit_year=self.learning_unit_year_3, learning_component_year=self.learning_component_year_5) self.learning_unit_component_6 = LearningUnitComponentFactory( learning_unit_year=self.learning_unit_year_3, learning_component_year=self.learning_component_year_6) self.learning_unit_component_7 = LearningUnitComponentFactory( learning_unit_year=self.learning_unit_year_4, learning_component_year=self.learning_component_year_7)
def test_get_data_part2(self): learning_container_luy = LearningContainerYearFactory( academic_year=self.current_academic_year) luy = LearningUnitYearFactory( academic_year=self.current_academic_year, learning_container_year=learning_container_luy, periodicity=learning_unit_year_periodicity.ANNUAL, status=True, language=None, ) component_lecturing = LearningComponentYearFactory( learning_container_year=learning_container_luy, type=learning_component_year_type.LECTURING, hourly_volume_total_annual=15, hourly_volume_partial_q1=10, hourly_volume_partial_q2=5, planned_classes=1) component_practical = LearningComponentYearFactory( learning_container_year=learning_container_luy, type=learning_component_year_type.PRACTICAL_EXERCISES, hourly_volume_total_annual=15, hourly_volume_partial_q1=10, hourly_volume_partial_q2=5, planned_classes=1) LearningUnitComponentFactory( learning_unit_year=luy, learning_component_year=component_lecturing) LearningUnitComponentFactory( learning_unit_year=luy, learning_component_year=component_practical) a_tutor = TutorFactory() an_attribution = AttributionNewFactory(tutor=a_tutor, start_year=2017) attribution_charge_new_lecturing = AttributionChargeNewFactory( learning_component_year=component_lecturing, attribution=an_attribution, allocation_charge=15.0) attribution_charge_new_practical = AttributionChargeNewFactory( learning_component_year=component_practical, attribution=an_attribution, allocation_charge=5.0) luy.attribution_charge_news = attribution_charge_new.find_attribution_charge_new_by_learning_unit_year( luy) expected_common = [ xls_build.translate(luy.periodicity), xls_build.translate(luy.status), component_lecturing.hourly_volume_total_annual, component_lecturing.hourly_volume_partial_q1, component_lecturing.hourly_volume_partial_q2, component_lecturing.planned_classes, component_practical.hourly_volume_total_annual, component_practical.hourly_volume_partial_q1, component_practical.hourly_volume_partial_q2, component_practical.planned_classes, xls_build.translate(luy.quadrimester), xls_build.translate(luy.session), "", '' ] self.assertEqual(_get_data_part2(luy, False), expected_common) self.assertEqual( _get_data_part2(luy, True), expected_attribution_data(attribution_charge_new_lecturing, attribution_charge_new_practical, expected_common, luy))
def test_get_data_part2(self): learning_container_luy = LearningContainerYearFactory( academic_year=self.current_academic_year) luy = LearningUnitYearFactory( academic_year=self.current_academic_year, learning_container_year=learning_container_luy, periodicity=learning_unit_year_periodicity.ANNUAL, status=True, language=None, ) component_lecturing = LearningComponentYearFactory( learning_container_year=learning_container_luy, type=learning_component_year_type.LECTURING, hourly_volume_total_annual=15, hourly_volume_partial_q1=10, hourly_volume_partial_q2=5, planned_classes=1) component_practical = LearningComponentYearFactory( learning_container_year=learning_container_luy, type=learning_component_year_type.PRACTICAL_EXERCISES, hourly_volume_total_annual=15, hourly_volume_partial_q1=10, hourly_volume_partial_q2=5, planned_classes=1) LearningUnitComponentFactory( learning_unit_year=luy, learning_component_year=component_lecturing) LearningUnitComponentFactory( learning_unit_year=luy, learning_component_year=component_practical) a_tutor = TutorFactory() an_attribution = AttributionNewFactory(tutor=a_tutor, start_year=2017) attribution_charge_new_lecturing = AttributionChargeNewFactory( learning_component_year=component_lecturing, attribution=an_attribution, allocation_charge=15.0) attribution_charge_new_practical = AttributionChargeNewFactory( learning_component_year=component_practical, attribution=an_attribution, allocation_charge=5.0) # Simulate annotate luy = annotate_qs(LearningUnitYear.objects.filter(pk=luy.pk)).first() luy.entity_requirement = EntityVersionFactory() luy.attribution_charge_news = attribution_charge_new.find_attribution_charge_new_by_learning_unit_year_as_dict( luy) expected_common = [ str(_(luy.periodicity.title())), str(_('yes')) if luy.status else str(_('no')), component_lecturing.hourly_volume_total_annual, component_lecturing.hourly_volume_partial_q1, component_lecturing.hourly_volume_partial_q2, component_lecturing.planned_classes, component_practical.hourly_volume_total_annual, component_practical.hourly_volume_partial_q1, component_practical.hourly_volume_partial_q2, component_practical.planned_classes, luy.get_quadrimester_display() or '', luy.get_session_display() or '', "", ] self.assertEqual(_get_data_part2(luy, False), expected_common) self.assertEqual( _get_data_part2(luy, True), expected_attribution_data(attribution_charge_new_lecturing, attribution_charge_new_practical, expected_common, luy))
def test_check_related_partims_deletion(self): l_container_year = LearningContainerYearFactory() LearningUnitYearFactory(acronym="LBIR1212", learning_container_year=l_container_year, academic_year=self.academic_year, subtype=learning_unit_year_subtypes.FULL, learning_unit=self.learning_unit) msg = learning_unit_deletion._check_related_partims_deletion( l_container_year) self.assertEqual(len(msg.values()), 0) l_unit_2 = LearningUnitYearFactory( acronym="LBIR1212", learning_container_year=l_container_year, academic_year=self.academic_year, subtype=learning_unit_year_subtypes.PARTIM) LearningUnitEnrollmentFactory(learning_unit_year=l_unit_2) LearningUnitEnrollmentFactory(learning_unit_year=l_unit_2) LearningUnitEnrollmentFactory(learning_unit_year=l_unit_2) group_1 = GroupElementYearFactory(child_leaf=l_unit_2) group_2 = GroupElementYearFactory(child_leaf=l_unit_2) component = LearningUnitComponentFactory(learning_unit_year=l_unit_2) attribution_1 = AttributionNewFactory( learning_container_year=l_unit_2.learning_container_year) attribution_2 = AttributionNewFactory( learning_container_year=l_unit_2.learning_container_year) AttributionChargeNewFactory( learning_component_year=component.learning_component_year, attribution=attribution_1) AttributionChargeNewFactory( learning_component_year=component.learning_component_year, attribution=attribution_1) AttributionChargeNewFactory( learning_component_year=component.learning_component_year, attribution=attribution_2) msg = learning_unit_deletion._check_related_partims_deletion( l_container_year) msg = list(msg.values()) self.assertEqual(len(msg), 5) self.assertIn( _("There is %(count)d enrollments in %(subtype)s %(acronym)s for the year %(year)s" ) % { 'subtype': _('The partim'), 'acronym': l_unit_2.acronym, 'year': l_unit_2.academic_year, 'count': 3 }, msg) msg_delete_tutor = _( "%(subtype)s %(acronym)s is assigned to %(tutor)s for the year %(year)s" ) self.assertIn( msg_delete_tutor % { 'subtype': _('The partim'), 'acronym': l_unit_2.acronym, 'year': l_unit_2.academic_year, 'tutor': attribution_1.tutor }, msg) self.assertIn( msg_delete_tutor % { 'subtype': _('The partim'), 'acronym': l_unit_2.acronym, 'year': l_unit_2.academic_year, 'tutor': attribution_2.tutor }, msg) msg_delete_offer_type = _('lu_included_in_group') self.assertIn( msg_delete_offer_type % { 'subtype': _('The partim'), 'acronym': l_unit_2.acronym, 'group': group_1.parent.acronym, 'program': group_1.parent.education_group_type, 'year': l_unit_2.academic_year }, msg) self.assertIn( msg_delete_offer_type % { 'subtype': _('The partim'), 'acronym': l_unit_2.acronym, 'group': group_2.parent.acronym, 'program': group_2.parent.education_group_type, 'year': l_unit_2.academic_year }, msg)