def setUpTestData(cls): anac = AcademicYearFactory() requirement_entity = EntityFactory() EntityVersionFactory( start_date=AcademicYearFactory(year=anac.year - 1).start_date, end_date=AcademicYearFactory(year=anac.year + 1).end_date, entity=requirement_entity) luy = LearningUnitYearFactory( academic_year=anac, learning_container_year__requirement_entity=requirement_entity) ExternalLearningUnitYearFactory(learning_unit_year=luy) cls.luy = LearningUnitYear.objects.filter( pk=luy.pk).annotate_full_title().get() setattr(cls.luy, "entity_requirement", "OSIS") setattr(cls.luy, "entity_allocation", "OSIS") url_kwargs = { 'acronym': cls.luy.acronym, 'year': cls.luy.academic_year.year } url = reverse('learning_unit_api_v1:learningunits_read', kwargs=url_kwargs) cls.serializer = ExternalLearningUnitDetailedSerializer( cls.luy, context={ 'request': RequestFactory().get(url), 'language': settings.LANGUAGE_CODE_EN })
def test_when_delete_additionnal_entity(self): post_data = get_valid_form_data(self.current_academic_year, self.person, self.learning_unit_year) # Assert additionnal entity exists exists if not self.learning_unit_year.learning_container_year.additional_entity_1: self.learning_unit_year.learning_container_year.additional_entity_1 = EntityFactory() self.learning_unit_year.learning_container_year.save() # Assert repartition volumes are set for additional entity component_queryset = LearningComponentYear.objects.filter( learning_unit_year__learning_container_year=self.learning_unit_year.learning_container_year ) component_queryset.update(repartition_volume_additional_entity_1=15.0) # Removing additionnal entity post_data["additional_entity_1"] = "" self.assertEqual(component_queryset.count(), 4) # Assert we are testing for Full AND Partim (2 components each) form = FullForm( self.person, self.learning_unit_year.academic_year, learning_unit_instance=self.learning_unit_year.learning_unit, data=post_data ) self.assertTrue(form.is_valid(), form.errors) form.save() self.learning_unit_year.learning_container_year.refresh_from_db() self.assertIsNone(self.learning_unit_year.learning_container_year.additional_entity_1) self.learning_unit_year.learning_container_year.refresh_from_db() self.assertIsNotNone(self.learning_unit_year.learning_container_year.requirement_entity) self.assertIsNotNone(self.learning_unit_year.learning_container_year.allocation_entity) for component in component_queryset: self.assertIsNone(component.repartition_volume_additional_entity_1)
def _create_entity_and_version_related_to(organization, acronym, parent=None): entity = EntityFactory(organization=organization) EntityVersionFactory(acronym=acronym, entity=entity, parent=parent, end_date=None) return entity
def setUp(self): self.current_academic_year = create_current_academic_year() self.generated_ac_years = GenerateAcademicYear( self.current_academic_year.year + 1, self.current_academic_year.year + 10) self.parent_education_group_year = EducationGroupYearFactory( academic_year=self.current_academic_year) self.test_categories = [ education_group_categories.GROUP, education_group_categories.TRAINING, education_group_categories.MINI_TRAINING, ] self.education_group_types = [ EducationGroupTypeFactory(category=category) for category in self.test_categories ] self.organization = OrganizationFactory(type=organization_type.MAIN) self.entity = EntityFactory(organization=self.organization) self.entity_version = EntityVersionFactory(entity=self.entity, entity_type=FACULTY, start_date=datetime.now()) self.language = LanguageFactory() self.person = PersonFactory() PersonEntityFactory(person=self.person, entity=self.entity) self.client.force_login(self.person.user) self.perm_patcher = mock.patch( "base.business.education_groups.perms._is_eligible_to_add_education_group", return_value=True) self.mocked_perm = self.perm_patcher.start()
def setUpTestData(cls): today = datetime.date.today() FacultyManagerGroupFactory() cls.faculty_user = factory_user.UserFactory() cls.faculty_person = FacultyManagerFactory('can_propose_learningunit', 'can_create_learningunit', user=cls.faculty_user) cls.super_user = factory_user.SuperUserFactory() cls.person = factory_person.CentralManagerFactory(user=cls.super_user) start_year = AcademicYearFactory(year=get_current_year()) end_year = AcademicYearFactory(year=get_current_year() + 7) cls.academic_years = GenerateAcademicYear(start_year, end_year).academic_years cls.current_academic_year = cls.academic_years[0] cls.next_academic_year = cls.academic_years[1] generate_creation_or_end_date_proposal_calendars(cls.academic_years) cls.language = LanguageFactory(code='FR') cls.organization = organization_factory.OrganizationFactory( type=organization_type.MAIN) cls.campus = campus_factory.CampusFactory( organization=cls.organization, is_administration=True) cls.entity = EntityFactory(organization=cls.organization) cls.entity_version = EntityVersionFactory( entity=cls.entity, entity_type=entity_type.FACULTY, start_date=today.replace(year=1900), end_date=None) PersonEntityFactory(person=cls.faculty_person, entity=cls.entity) PersonEntityFactory(person=cls.person, entity=cls.entity)
def test_check_postponement_conflict_on_all_sections(self): # LEARNING CONTAINER YEAR - Title modified another_learning_container_year = _build_copy( self.learning_container_year) another_learning_container_year.academic_year = self.next_academic_year another_learning_container_year.common_title = "Title Modified" another_learning_container_year.save() # LEARNING UNIT YEAR - Modify specific title another_learning_unit_year = _build_copy(self.learning_unit_year) another_learning_unit_year.academic_year = self.next_academic_year another_learning_unit_year.learning_container_year = another_learning_container_year another_learning_unit_year.specific_title = "Specific title modified" another_learning_unit_year.save() an_entity = EntityFactory() EntityVersionFactory(entity=an_entity, parent=None, end_date=None, acronym="AREC") another_learning_container_year.requirement_entity = an_entity another_learning_container_year.save() error_list = business_edition._check_postponement_conflict( self.learning_unit_year, another_learning_unit_year) self.assertIsInstance(error_list, list) self.assertEqual(len(error_list), 5)
def generate_learning_unit_year_with_associated_education_group( academic_year, same_faculty=True, same_entity=True): luy = LearningUnitYearFactory( academic_year=academic_year, learning_container_year__academic_year=academic_year, learning_container_year__requirement_entity=EntityFactory()) entity_version = EntityVersionFactory( entity=luy.learning_container_year.requirement_entity, entity_type=entity_type.SCHOOL) parent_entity = EntityVersionFactory(entity=entity_version.parent, parent=None, entity_type=entity_type.FACULTY) if not same_entity: entity_version = parent_entity if not same_faculty: entity_version = EntityVersionFactory(entity_type=entity_type.FACULTY) offer_year_entity = OfferYearEntityFactory( entity=entity_version.entity, education_group_year__academic_year=academic_year) GroupElementYearFactory( child_branch=offer_year_entity.education_group_year, parent=None) GroupElementYearFactory(child_branch=None, child_leaf=luy, parent=offer_year_entity.education_group_year) return luy
def setUp(self): today = datetime.date.today() self.faculty_user = factory_user.UserFactory() self.faculty_user.groups.add( Group.objects.get(name=FACULTY_MANAGER_GROUP)) self.faculty_person = factory_person.PersonFactory( user=self.faculty_user) self.faculty_user.user_permissions.add( Permission.objects.get(codename='can_propose_learningunit')) self.faculty_user.user_permissions.add( Permission.objects.get(codename='can_create_learningunit')) self.super_user = factory_user.SuperUserFactory() self.person = factory_person.PersonFactory(user=self.super_user) self.academic_year = AcademicYearFactory.build( start_date=today.replace(year=today.year + 1), end_date=today.replace(year=today.year + 2), year=today.year + 1) super(AcademicYear, self.academic_year).save() self.language = LanguageFactory(code='FR') self.organization = organization_factory.OrganizationFactory( type=organization_type.MAIN) self.campus = campus_factory.CampusFactory( organization=self.organization, is_administration=True) self.entity = EntityFactory(organization=self.organization) self.entity_version = EntityVersionFactory( entity=self.entity, entity_type=entity_type.SCHOOL, start_date=today - datetime.timedelta(days=1), end_date=today.replace(year=today.year + 1)) PersonEntityFactory(person=self.faculty_person, entity=self.entity)
def setUp(self): current_academic_year = create_current_academic_year() an_organization = OrganizationFactory(type=organization_type.MAIN) learning_container_year = LearningContainerYearFactory( academic_year=current_academic_year, container_type=learning_container_year_types.COURSE, ) self.learning_unit_year = LearningUnitYearFakerFactory( credits=5, subtype=learning_unit_year_subtypes.FULL, academic_year=current_academic_year, learning_container_year=learning_container_year, campus=CampusFactory(organization=an_organization, is_administration=True)) self.entity_container_year = EntityContainerYearFactory( learning_container_year=self.learning_unit_year. learning_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY) today = datetime.date.today() an_entity = EntityFactory(organization=an_organization) self.entity_version = EntityVersionFactory( entity=an_entity, entity_type=entity_type.SCHOOL, start_date=today, end_date=today.replace(year=today.year + 1))
def setUp(self): organization = OrganizationFactory(type=organization_type.MAIN) self.entities = [ EntityFactory(organization=organization) for x in range(2) ] self.entity_c_older_version = EntityVersionFactory( entity=self.entities[0], acronym="C ENTITY_V_" + str(0), entity_type=entity_type.FACULTY, start_date=datetime.date(now.year - 1, 1, 1), end_date=datetime.date(now.year - 1, 12, 31)) self.entity_c_current_version = EntityVersionFactory( entity=self.entities[0], acronym="B ENTITY_V_" + str(0), entity_type=entity_type.FACULTY, start_date=datetime.date(now.year, 1, 1), end_date=None) self.entity_a_version = EntityVersionFactory( entity=self.entities[1], acronym="A ENTITY_V_" + str(1), entity_type=entity_type.FACULTY, start_date=datetime.date(now.year, 1, 1), end_date=None)
def test_learning_unit_with_faculty_manager_when_cannot_edit_end_date( self): learning_container_year = LearningContainerYearFactory( academic_year=self.current_academic_year, container_type=learning_container_year_types.COURSE, requirement_entity=EntityFactory(), ) learning_unit_year = LearningUnitYearFactory( academic_year=self.current_academic_year, learning_container_year=learning_container_year, subtype=learning_unit_year_subtypes.FULL) EntityVersionFactory(entity=learning_container_year.requirement_entity) learning_unit_year.learning_unit.end_year = None learning_unit_year.learning_unit.save() managers = [ FacultyManagerFactory('can_access_learningunit'), ] for manager in managers: PersonEntityFactory( entity=learning_container_year.requirement_entity, person=manager) url = reverse("learning_unit", args=[learning_unit_year.id]) self.client.force_login(manager.user) response = self.client.get(url) self.assertEqual(response.context["can_edit_date"], False)
def setUp(self): today = datetime.date.today() self.faculty_user = factory_user.UserFactory() self.faculty_user.groups.add( Group.objects.get(name=FACULTY_MANAGER_GROUP)) self.faculty_person = factory_person.PersonFactory( user=self.faculty_user) self.faculty_user.user_permissions.add( Permission.objects.get(codename='can_propose_learningunit')) self.faculty_user.user_permissions.add( Permission.objects.get(codename='can_create_learningunit')) self.super_user = factory_user.SuperUserFactory() self.person = factory_person.PersonFactory(user=self.super_user) self.academic_years = GenerateAcademicYear(get_current_year(), get_current_year() + 7).academic_years self.academic_year = self.academic_years[0] self.language = LanguageFactory(code='FR') self.organization = organization_factory.OrganizationFactory( type=organization_type.MAIN) self.campus = campus_factory.CampusFactory( organization=self.organization, is_administration=True) self.entity = EntityFactory(organization=self.organization) self.entity_version = EntityVersionFactory( entity=self.entity, entity_type=entity_type.SCHOOL, start_date=today.replace(year=1900), end_date=None) PersonEntityFactory(person=self.faculty_person, entity=self.entity) PersonEntityFactory(person=self.person, entity=self.entity)
def setUpTestData(cls): entities = create_entities_hierarchy() cls.faculty = entities['child_one_entity_version'] cls.child_entity = EntityFactory(country=entities['country'], organization=entities['organization']) cls.child_entity_version = EntityVersionFactory( acronym="CHILD_1_UNDER_FAC", parent=cls.faculty.entity, entity_type=SCHOOL, end_date=None, entity=cls.child_entity, start_date=entities['start_date']) cls.academic_year = create_current_academic_year() cls.education_group = EducationGroupFactory() EducationGroupYearFactory(education_group=cls.education_group, academic_year=cls.academic_year, management_entity=cls.child_entity) cls.formation = ContinuingEducationTrainingFactory( education_group=cls.education_group, ) cls.admission = AdmissionFactory(formation=cls.formation, awareness_ucl_website=False, awareness_formation_website=False, awareness_press=False, awareness_facebook=True, awareness_linkedin=False, awareness_customized_mail=False, awareness_emailing=False, awareness_other='Other awareness', awareness_word_of_mouth=False, awareness_friends=False, awareness_former_students=False, awareness_moocs=False)
def setUp(self): self.academic_year = create_current_academic_year() self.next_academic_year = AcademicYearFactory( year=self.academic_year.year + 1) self.learning_container_year = LearningContainerYearFactory( academic_year=self.academic_year, common_title='common title', ) self.learning_unit_year = _create_learning_unit_year_with_components( self.learning_container_year, create_lecturing_component=True, create_pratical_component=True) an_entity = EntityFactory() self.entity_version = EntityVersionFactory(entity=an_entity, parent=None, end_date=None, acronym="DRT") self.allocation_entity = _create_entity_container_with_entity_components( self.learning_unit_year, entity_container_year_link_type.ALLOCATION_ENTITY, an_entity) self.requirement_entity = _create_entity_container_with_entity_components( self.learning_unit_year, entity_container_year_link_type.REQUIREMENT_ENTITY, an_entity, repartition_lecturing=30, repartition_practical_exercises=10) self.add_requirement_entity_1 = _create_entity_container_with_entity_components( self.learning_unit_year, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1, an_entity, repartition_lecturing=10, repartition_practical_exercises=5)
def test_check_postponement_conflict_on_all_sections(self): # LEARNING CONTAINER YEAR - Title modified another_learning_container_year = _build_copy( self.learning_container_year) another_learning_container_year.academic_year = self.next_academic_year another_learning_container_year.common_title = "Title Modified" another_learning_container_year.save() # LEARNING UNIT YEAR - Modify specific title another_learning_unit_year = _build_copy(self.learning_unit_year) another_learning_unit_year.academic_year = self.next_academic_year another_learning_unit_year.learning_container_year = another_learning_container_year another_learning_unit_year.specific_title = "Specific title modified" another_learning_unit_year.save() # ENTITY - Same allocation but NOT same requirement entity allocation_entity = _build_copy(self.allocation_entity) allocation_entity.learning_container_year = another_learning_container_year allocation_entity.save() an_entity = EntityFactory() EntityVersionFactory(entity=an_entity, parent=None, end_date=None, acronym="AREC") EntityContainerYearFactory( learning_container_year=another_learning_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY, entity=an_entity) error_list = business_edition._check_postponement_conflict( self.learning_unit_year, another_learning_unit_year) self.assertIsInstance(error_list, list) self.assertEqual(len(error_list), 6)
def setUpTestData(cls): cls.user = UserFactory() cls.person = CentralManagerFactory(user=cls.user) cls.academic_year = create_current_academic_year() cls.education_group_yr = EducationGroupYearFactory( acronym='ARKE2A', academic_year=cls.academic_year, education_group_type=EducationGroupTypeFactory( category=education_group_categories.TRAINING), management_entity=EntityFactory()) cls.root_id = cls.education_group_yr.id cls.country_be = CountryFactory() cls.organization_address = OrganizationAddressFactory( country=cls.country_be) cls.organization = cls.organization_address.organization cls.education_group_organization = EducationGroupOrganizationFactory( organization=cls.organization, education_group_year=cls.education_group_yr, diploma=diploma_coorganization.UNIQUE, all_students=True, ) cls.organization_bis = OrganizationFactory() cls.address = OrganizationAddressFactory( organization=cls.organization_bis, is_main=True)
def test_is_not_eligible_for_cancel_of_proposal(self): luy = LearningUnitYearFactory(academic_year=self.academic_yr) an_entity = EntityFactory() luy.learning_container_year.requirement_entity = an_entity luy.learning_container_year.save() a_person = create_person_with_permission_and_group() a_proposal = ProposalLearningUnitFactory( learning_unit_year=luy, type=proposal_type.ProposalType.SUPPRESSION.name, state=proposal_state.ProposalState.CENTRAL.name, initial_data={ "learning_container_year": { "requirement_entity": an_entity.id, } }) self.assertFalse( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person)) a_proposal.state = proposal_state.ProposalState.FACULTY.name a_proposal.save() self.assertFalse( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person)) a_proposal.type = proposal_type.ProposalType.MODIFICATION.name a_proposal.save() self.assertFalse( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person))
def setUpTestData(cls): cls.entity_factory = EntityFactory() cls.entity_version = EntityVersionFactory( entity_type=entity_type.INSTITUTE, end_date=None, entity=cls.entity_factory) cls.reviewer = ReviewerFactory(role=reviewer_role.RESEARCH, entity=cls.entity_version.entity)
def setUp(self): self.entity_factory = EntityFactory() self.entity_version = EntityVersionFactory( entity_type=entity_type.INSTITUTE, end_date=None, entity=self.entity_factory) self.reviewer = ReviewerFactory(role=reviewer_role.RESEARCH, entity=self.entity_version.entity)
def setUp(self): self.factory = RequestFactory() self.client = Client() self.settings = SettingsFactory() today = datetime.date.today() self.current_academic_year = AcademicYearFactory( start_date=today, end_date=today.replace(year=today.year + 1), year=today.year) self.phd_supervisor = PersonFactory() self.assistant = AcademicAssistantFactory( supervisor=self.phd_supervisor) self.assistant_mandate = AssistantMandateFactory( academic_year=self.current_academic_year, assistant=self.assistant) self.assistant_mandate.state = assistant_mandate_state.PHD_SUPERVISOR self.assistant_mandate.save() self.review = ReviewFactory(reviewer=None, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS) self.entity_factory = EntityFactory() self.entity_version = EntityVersionFactory( entity_type=entity_type.INSTITUTE, end_date=None, entity=self.entity_factory) self.entity_factory2 = EntityFactory() self.entity_version2 = EntityVersionFactory( entity_type=entity_type.SCHOOL, end_date=None, entity=self.entity_factory2) self.entity_version2 = EntityVersionFactory( entity_type=entity_type.SECTOR) self.mandate_entity = MandateEntityFactory( assistant_mandate=self.assistant_mandate, entity=self.entity_version.entity) self.reviewer = ReviewerFactory(role=reviewer_role.RESEARCH, entity=self.entity_version.entity) self.reviewer2 = ReviewerFactory(role=reviewer_role.VICE_RECTOR, entity=self.entity_version2.entity) self.entity_version3 = EntityVersionFactory( entity_type=entity_type.FACULTY) self.reviewer3 = ReviewerFactory(role=reviewer_role.SUPERVISION, entity=self.entity_version3.entity) self.delegate = PersonFactory() self.delegate2 = PersonFactory()
def setUp(self): self.person = PersonFactory() an_organization = OrganizationFactory(type=organization_type.MAIN) current_academic_year = create_current_academic_year() learning_container_year = LearningContainerYearFactory( academic_year=current_academic_year, container_type=learning_container_year_types.COURSE, campus=CampusFactory(organization=an_organization, is_administration=True)) self.learning_unit_year = LearningUnitYearFakerFactory( credits=5, subtype=learning_unit_year_subtypes.FULL, academic_year=current_academic_year, learning_container_year=learning_container_year) self.entity_container_year = EntityContainerYearFactory( learning_container_year=self.learning_unit_year. learning_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY) today = datetime.date.today() an_entity = EntityFactory(organization=an_organization) self.entity_version = EntityVersionFactory( entity=an_entity, entity_type=entity_type.SCHOOL, start_date=today, end_date=today.replace(year=today.year + 1)) self.language = LanguageFactory(code="EN") self.campus = CampusFactory( name="OSIS Campus", organization=OrganizationFactory(type=organization_type.MAIN), is_administration=True) self.form_data = { "academic_year": self.learning_unit_year.academic_year.id, "first_letter": "L", "acronym": "OSIS1245", "common_title": "New common title", "common_title_english": "New common title english", "specific_title": "New title", "specific_title_english": "New title english", "container_type": self.learning_unit_year.learning_container_year.container_type, "internship_subtype": "", "credits": "4", "periodicity": learning_unit_periodicity.BIENNIAL_ODD, "status": False, "language": self.language.pk, "quadrimester": learning_unit_year_quadrimesters.Q1, "campus": self.campus.id, "requirement_entity": self.entity_version.id, "allocation_entity": self.entity_version.id, "entity": self.entity_version.id, "folder_id": "1", "state": proposal_state.ProposalState.CENTRAL.name }
def test_find_parent_of_type_first_parent(self): entity = EntityFactory() EntityVersionFactory(entity=entity, entity_type=FACULTY) entity_v = EntityVersionFactory(parent=entity) result = find_parent_of_type_into_entity_structure( entity_v, build_current_entity_version_structure_in_memory( timezone.now().date()), FACULTY) self.assertEqual(entity_v.parent, result)
def setUp(self): requirement_entity = EntityFactory() self.luy = LearningUnitYearFakerFactory( learning_container_year__academic_year=self.current_academic_year, learning_container_year__container_type=COURSE, subtype=FULL, learning_container_year__requirement_entity=requirement_entity) self.person_entity = PersonEntityFactory(person=self.person, entity=requirement_entity)
def test_when_person_not_linked_to_entity(self): proposal = ProposalLearningUnitFactory( state=proposal_state.ProposalState.ACCEPTED.name, learning_unit_year__learning_container_year__requirement_entity= EntityFactory(), ) self.assertFalse( is_eligible_to_consolidate_proposal( proposal, self.person_with_right_to_consolidate))
def test_find_entities_grouped_by_linktype(self): a_learning_container_year = LearningContainerYearFactory() requirement_entity = EntityFactory() EntityContainerYearFactory( learning_container_year=a_learning_container_year, entity=requirement_entity, type=entity_container_year_link_type.REQUIREMENT_ENTITY) allocation_entity = EntityFactory() EntityContainerYearFactory( learning_container_year=a_learning_container_year, entity=allocation_entity, type=entity_container_year_link_type.ALLOCATION_ENTITY) additional_requirement_entity_1 = EntityFactory() EntityContainerYearFactory( learning_container_year=a_learning_container_year, entity=additional_requirement_entity_1, type=entity_container_year_link_type. ADDITIONAL_REQUIREMENT_ENTITY_1) additional_requirement_entity_2 = EntityFactory() EntityContainerYearFactory( learning_container_year=a_learning_container_year, entity=additional_requirement_entity_2, type=entity_container_year_link_type. ADDITIONAL_REQUIREMENT_ENTITY_2) entities_by_linktype = entity_container_year.find_entities_grouped_by_linktype( a_learning_container_year) expected_result = { entity_container_year_link_type.REQUIREMENT_ENTITY: requirement_entity, entity_container_year_link_type.ALLOCATION_ENTITY: allocation_entity, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1: additional_requirement_entity_1, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_2: additional_requirement_entity_2 } self.assertDictEqual(entities_by_linktype, expected_result)
def setUp(self): self.current_academic_year = create_current_academic_year() country = CountryFactory() ssh_entity = EntityFactory(country=country) ssh_entity_v = EntityVersionFactory(acronym="SSH", end_date=None, entity=ssh_entity) agro_entity = EntityFactory(country=country) self.agro_entity_v = EntityVersionFactory(entity=agro_entity, parent=ssh_entity_v.entity, acronym="AGRO", end_date=None) l_container_yr = LearningContainerYearFactory( acronym="LBIR1100", academic_year=self.current_academic_year, container_type=learning_container_year_types.COURSE) EntityContainerYearFactory( learning_container_year=l_container_yr, entity=self.agro_entity_v.entity, type=entity_container_year_link_type.REQUIREMENT_ENTITY) self.learning_unit_1 = LearningUnitYearFactory( acronym="LBIR1100", learning_container_year=l_container_yr, academic_year=self.current_academic_year, subtype=learning_unit_year_subtypes.FULL) self.learning_unit_2 = LearningUnitYearFactory( acronym="LBIR1100B", learning_container_year=l_container_yr, academic_year=self.current_academic_year, subtype=learning_unit_year_subtypes.PARTIM) self.learning_unit_3 = LearningUnitYearFactory( acronym="LBIR1100A", learning_container_year=l_container_yr, academic_year=self.current_academic_year, subtype=learning_unit_year_subtypes.PARTIM) self.learning_unit_4 = LearningUnitYearFactory( acronym="LBIR1100C", learning_container_year=l_container_yr, academic_year=self.current_academic_year, subtype=learning_unit_year_subtypes.PARTIM, status=False)
def setUpTestData(cls): cls.current_academic_year = create_current_academic_year() cls.generated_ac_years = GenerateAcademicYear( cls.current_academic_year.year + 1, cls.current_academic_year.year + 10) cls.parent_education_group_year = EducationGroupYearFactory( academic_year=cls.current_academic_year) cls.test_categories = [ education_group_categories.GROUP, education_group_categories.TRAINING, education_group_categories.MINI_TRAINING, ] cls.education_group_types = [ EducationGroupTypeFactory(category=category) for category in cls.test_categories ] cls.urls_without_parent_by_category = { education_group_type.category: reverse("new_education_group", kwargs={ "category": education_group_type.category, "education_group_type_pk": education_group_type.pk, }) for education_group_type in cls.education_group_types } cls.urls_with_parent_by_category = { education_group_type.category: reverse("new_education_group", kwargs={ "category": education_group_type.category, "education_group_type_pk": education_group_type.pk, "root_id": cls.parent_education_group_year.id, "parent_id": cls.parent_education_group_year.id, }) for education_group_type in cls.education_group_types } cls.expected_templates_by_category = { education_group_categories.GROUP: "education_group/create_groups.html", education_group_categories.TRAINING: "education_group/create_trainings.html", education_group_categories.MINI_TRAINING: "education_group/create_mini_trainings.html", } cls.organization = OrganizationFactory(type=organization_type.MAIN) cls.entity = EntityFactory(organization=cls.organization) cls.entity_version = EntityVersionFactory(entity=cls.entity, entity_type=FACULTY, start_date=datetime.now()) cls.language = LanguageFactory() cls.person = PersonFactory() PersonEntityFactory(person=cls.person, entity=cls.entity)
def test_check_postponement_conflict_entity_container_year_differences_found( self): # Copy the same container + change academic year another_learning_container_year = _build_copy( self.learning_container_year) another_learning_container_year.academic_year = self.next_academic_year another_learning_container_year.save() # Copy same allocation entity allocation_entity = _build_copy(self.allocation_entity) allocation_entity.learning_container_year = another_learning_container_year allocation_entity.save() # Link to another entity for requirement an_entity = EntityFactory() EntityVersionFactory(entity=an_entity, parent=None, end_date=None, acronym="AREC") requirement_entity = EntityContainerYearFactory( learning_container_year=another_learning_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY, entity=an_entity) error_list = business_edition._check_postponement_conflict_on_entity_container_year( self.learning_container_year, another_learning_container_year) self.assertIsInstance(error_list, list) self.assertEqual(len(error_list), 2) generic_error = "The value of field '%(field)s' is different between year %(year)s - %(value)s " \ "and year %(next_year)s - %(next_value)s" # Error : Requirement entity diff error_requirement_entity = _(generic_error) % { 'field': _( entity_container_year_link_type.REQUIREMENT_ENTITY.lower()), 'year': self.learning_container_year.academic_year, 'value': self.requirement_entity.entity.most_recent_acronym, 'next_year': another_learning_container_year.academic_year, 'next_value': requirement_entity.entity.most_recent_acronym } self.assertIn(error_requirement_entity, error_list) # Error : Additional requirement entity diff error_requirement_entity = _(generic_error) % { 'field': _(entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1. lower()), 'year': self.learning_container_year.academic_year, 'value': self.add_requirement_entity_1.entity.most_recent_acronym, 'next_year': another_learning_container_year.academic_year, 'next_value': _('no_data') } self.assertIn(error_requirement_entity, error_list)
def test_find_main_entities_version_filtered_by_person(self): person = PersonFactory() entity_attached = EntityFactory(organization=self.organization) entity_version_attached = EntityVersionFactory( entity=entity_attached, entity_type="SECTOR", parent=None, end_date=None, start_date=datetime.date.today() - datetime.timedelta(days=5)) entity_not_attached = EntityFactory(organization=self.organization) EntityVersionFactory(entity=entity_not_attached, entity_type="SECTOR", parent=None, end_date=None) PersonEntityFactory(person=person, entity=entity_attached) entity_list = list(person.find_main_entities_version) self.assertTrue(entity_list) self.assertEqual(len(entity_list), 1) self.assertEqual(entity_list[0], entity_version_attached)
def test_most_recent_acronym(self): entity_instance = EntityFactory() most_recent_year = 2018 for year in range(2016, most_recent_year + 1): date = datetime.date(year=year, month=1, day=1) EntityVersionFactory(entity_id=entity_instance.id, start_date=date) most_recent_date = datetime.date(year=most_recent_year, month=1, day=1) most_recent_entity_version = EntityVersion.objects.get(start_date=most_recent_date, entity=entity_instance) self.assertEqual(entity_instance.most_recent_acronym, most_recent_entity_version.acronym)