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 setUp(self): self.person = PersonFactory() self.permission = Permission.objects.get( codename="can_propose_learningunit") self.person.user.user_permissions.add(self.permission) self.permission_2 = Permission.objects.get( codename="can_access_learningunit") self.person.user.user_permissions.add(self.permission_2) an_organization = OrganizationFactory(type=organization_type.MAIN) current_academic_year = create_current_academic_year() learning_container_year = LearningContainerYearFactory( acronym="LOSIS1212", academic_year=current_academic_year, container_type=learning_container_year_types.COURSE, ) self.learning_unit_year = LearningUnitYearFakerFactory( acronym=learning_container_year.acronym, subtype=learning_unit_year_subtypes.FULL, academic_year=current_academic_year, learning_container_year=learning_container_year, quadrimester=None, specific_title_english="title english", campus=CampusFactory(organization=an_organization, is_administration=True)) self.learning_container_year = self.learning_unit_year.learning_container_year an_entity = EntityFactory(organization=an_organization) self.entity_version = EntityVersionFactory( entity=an_entity, entity_type=entity_type.SCHOOL, start_date=current_academic_year.start_date, end_date=current_academic_year.end_date) self.requirement_entity = EntityContainerYearFactory( learning_container_year=self.learning_container_year, entity=self.entity_version.entity, type=entity_container_year_link_type.REQUIREMENT_ENTITY) self.allocation_entity = EntityContainerYearFactory( learning_container_year=self.learning_container_year, entity=self.entity_version.entity, type=entity_container_year_link_type.ALLOCATION_ENTITY) self.additional_requirement_entity_1 = EntityContainerYearFactory( learning_container_year=self.learning_container_year, entity=self.entity_version.entity, type=entity_container_year_link_type. ADDITIONAL_REQUIREMENT_ENTITY_1) self.additional_requirement_entity_2 = EntityContainerYearFactory( learning_container_year=self.learning_container_year, entity=self.entity_version.entity, type=entity_container_year_link_type. ADDITIONAL_REQUIREMENT_ENTITY_2) PersonEntityFactory(person=self.person, entity=self.entity_version.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 test_get_requirement_entities_volumes(self): academic_year = AcademicYearFactory(year=2016) learning_container_year = LearningContainerYearFactory( academic_year=academic_year) learning_component_year = LearningComponentYearFactory( learning_container_year=learning_container_year) entity_types_list = [ entity_types.REQUIREMENT_ENTITY, entity_types.ADDITIONAL_REQUIREMENT_ENTITY_1, entity_types.ADDITIONAL_REQUIREMENT_ENTITY_2 ] entity_containers_year = [ EntityContainerYearFactory( type=entity_types_list[x], learning_container_year=learning_container_year) for x in range(3) ] components = [ EntityComponentYearFactory( entity_container_year=entity_containers_year[x], learning_component_year=learning_component_year, hourly_volume_total=x + 5) for x in range(3) ] wanted_response = { "REQUIREMENT_ENTITY": 5, "ADDITIONAL_REQUIREMENT_ENTITY_1": 6, "ADDITIONAL_REQUIREMENT_ENTITY_2": 7, } self.assertDictEqual( learning_unit_year_with_context._get_requirement_entities_volumes( components), wanted_response)
def test_create_with_untyped_component_multiple_requirements_entities( self): data_dict = self.get_data_dict( learning_container_year_types.OTHER_COLLECTIVE) data_dict['requirement_entity_containers'].append( EntityContainerYearFactory(learning_container_year=data_dict[ 'new_learning_container_year'], type=entity_container_year_link_type. ADDITIONAL_REQUIREMENT_ENTITY_1)) creation.create_with_untyped_component(data_dict) self.assertEqual( mdl_base.learning_component_year.LearningComponentYear.objects.all( ).count(), 1) self.assertEqual( mdl_base.learning_component_year.LearningComponentYear.objects. filter(acronym=creation.UNTYPED_ACRONYM).count(), 1) self.assertEqual( mdl_base.learning_component_year.LearningComponentYear.objects. filter(type__isnull=True).count(), 1) # We should have two entity component year [Requirement + 1 additional] self.assertEqual( mdl_base.entity_component_year.EntityComponentYear.objects.all(). count(), 2) self.assertEqual( mdl_base.learning_unit_year.LearningUnitYear.objects.all().count(), 1) self.assertEqual( mdl_base.learning_unit_component.LearningUnitComponent.objects.all( ).count(), 1)
def setUpTestData(cls): cls.current_academic_year = create_current_academic_year() cls.proposal = ProposalLearningUnitFactory( state=proposal_state.ProposalState.ACCEPTED.name, learning_unit_year__subtype=learning_unit_year_subtypes.FULL, learning_unit_year__academic_year=cls.current_academic_year, learning_unit_year__learning_container_year__academic_year=cls. current_academic_year) cls.learning_unit_year = cls.proposal.learning_unit_year cls.person = PersonFactory() cls.person.user.user_permissions.add( Permission.objects.get(codename="can_access_learningunit")) cls.person.user.user_permissions.add( Permission.objects.get( codename="can_consolidate_learningunit_proposal")) person_entity = PersonEntityFactory( person=cls.person, entity=EntityContainerYearFactory( learning_container_year=cls.learning_unit_year. learning_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY).entity ) EntityVersionFactory(entity=person_entity.entity) cls.url = reverse("learning_unit_consolidate_proposal") cls.post_data = {"learning_unit_year_id": cls.learning_unit_year.id}
def get_data_dict(self, container_type): learning_container = LearningContainerFactory() learning_container_yr = LearningContainerYearFactory( academic_year=self.current_academic_year, learning_container=learning_container) entity_version = EntityVersionFactory() a_learning_unit = LearningUnitFactory() requirement_entity_container_yr = EntityContainerYearFactory( learning_container_year=learning_container_yr, type=entity_container_year_link_type.REQUIREMENT_ENTITY) return { 'new_learning_container_year': learning_container_yr, 'data': { 'quadrimester': '', 'acronym': 'LTATO1200', 'subtype': 'FULL', 'allocation_entity': entity_version, 'additional_requirement_entity_2': None, 'status': True, 'academic_year': self.current_academic_year, 'requirement_entity': entity_version, 'credits': Decimal('15'), 'container_type': container_type, 'session': '', 'additional_requirement_entity_1': None }, 'new_learning_unit': a_learning_unit, 'requirement_entity_containers': [requirement_entity_container_yr], 'status': True, 'academic_year': self.current_academic_year }
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 entityversion = EntityVersionFactory(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=entityversion.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) # invalidate cache del self.requirement_entity.entity.most_recent_acronym 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 setUp(self): self.academic_year = create_current_academic_year() self.learning_unit_year = LearningUnitYearFactory( academic_year=self.academic_year, subtype=learning_unit_year_subtypes.FULL) self.language_fr = LanguageFactory(code="FR") self.language_en = LanguageFactory(code="EN") self.user = UserFactory() self.user.user_permissions.add( Permission.objects.get(codename="can_access_learningunit")) self.user.user_permissions.add( Permission.objects.get(codename="can_create_learningunit")) self.person = PersonFactory(user=self.user) self.a_superuser = SuperUserFactory() self.client.force_login(self.a_superuser) self.superperson = PersonFactory(user=self.a_superuser) self.person_entity = PersonEntityFactory(person=self.superperson) EntityContainerYearFactory( learning_container_year=self.learning_unit_year. learning_container_year, entity=self.person_entity.entity, type=entity_container_year_link_type.REQUIREMENT_ENTITY)
def setUpTestData(cls): cls.current_academic_year = create_current_academic_year() cls.academic_calendar = AcademicCalendarFactory( academic_year=cls.current_academic_year, reference=academic_calendar_type.SUMMARY_COURSE_SUBMISSION, start_date=datetime.date(timezone.now().year - 1, 9, 30), end_date=datetime.date(timezone.now().year + 1, 9, 30)) cls.academic_year_in_future = AcademicYearFactory( year=cls.current_academic_year.year + 1) cls.learning_unit_year = LearningUnitYearFactory( subtype=FULL, academic_year=cls.academic_year_in_future, learning_container_year__academic_year=cls.academic_year_in_future, summary_locked=False) a_valid_entity_version = EntityVersionFactory(entity_type=FACULTY) EntityContainerYearFactory( learning_container_year=cls.learning_unit_year. learning_container_year, entity=a_valid_entity_version.entity, type=entity_container_year_link_type.REQUIREMENT_ENTITY) cls.tutor = _get_tutor() # Add attribution to course [set summary responsible] AttributionFactory( tutor=cls.tutor, summary_responsible=True, learning_unit_year=cls.learning_unit_year, )
def test_find_latest_requirment_entity(self): work_on_year = 2016 # Change version in order to have multiple version during the year self.entity_versions[work_on_year].end_date = datetime.datetime( work_on_year, 3, 30) self.entity_versions[work_on_year].save() lastest_entity_version = EntityVersionFactory( entity=self.entity, parent=None, acronym="Entity V_{}_3".format(work_on_year), start_date=datetime.datetime(work_on_year, 8, 1), end_date=None) EntityVersionFactory(entity=self.entity, parent=None, acronym="Entity V_{}_2".format(work_on_year), start_date=datetime.datetime(work_on_year, 4, 1), end_date=datetime.datetime(work_on_year, 7, 30)) l_container_year = LearningContainerYearFactory( academic_year=self.academic_years[work_on_year]) # Create a link between entity and container # Requirement entity EntityContainerYearFactory( entity=self.entity, learning_container_year=l_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY) # Find requirement entity requirement_entity_found = entity_container_year.find_requirement_entity( learning_container_year=l_container_year) self.assertEqual(lastest_entity_version, requirement_entity_found)
def create_learning_unit_years_and_dependencies(self): acronym = "LDROI1004" l1 = LearningUnitFactory( start_year=settings.YEAR_LIMIT_LUE_MODIFICATION) learning_unit_years = [] for year in range(4): ac_year = AcademicYearFactory( year=settings.YEAR_LIMIT_LUE_MODIFICATION + 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( acronym=acronym, 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) return learning_unit_years
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 setUp(self): today = datetime.date.today() self.current_academic_year = AcademicYearFactory( start_date=today, end_date=today.replace(year=today.year + 1), year=today.year) self.learning_container_yr = LearningContainerYearFactory( academic_year=self.current_academic_year) self.organization = OrganizationFactory(type=organization_type.MAIN) self.country = CountryFactory() self.entity = EntityFactory(country=self.country, organization=self.organization) self.entity_container_yr = EntityContainerYearFactory( learning_container_year=self.learning_container_yr, type=entity_container_year_link_type.REQUIREMENT_ENTITY, entity=self.entity) self.learning_component_yr = LearningComponentYearFactory( learning_container_year=self.learning_container_yr, hourly_volume_partial=-1, planned_classes=1) self.entity_component_yr = EntityComponentYearFactory( learning_component_year=self.learning_component_yr, entity_container_year=self.entity_container_yr, hourly_volume_total=None) self.entity_components_yr = [ self.entity_component_yr, ]
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 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) entity_container_year = EntityContainerYearFactory( learning_container_year=luy.learning_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY) entity_version = EntityVersionFactory(entity=entity_container_year.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 test_is_not_eligible_for_cancel_of_proposal(self): luy = LearningUnitYearFactory(academic_year=self.academic_yr) an_entity_container_year = EntityContainerYearFactory( learning_container_year=luy.learning_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY) a_person = self.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={ "entities": { entity_container_year_link_type.REQUIREMENT_ENTITY: an_entity_container_year.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 setUp(self): self.luy = LearningUnitYearFakerFactory(learning_container_year__academic_year=self.current_academic_year, learning_container_year__container_type=COURSE, subtype=FULL) self.entity_container_year = EntityContainerYearFactory( learning_container_year=self.luy.learning_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY) self.person_entity = PersonEntityFactory(person=self.person, entity=self.entity_container_year.entity)
def _set_entities(self): today = datetime.date.today() an_entity = EntityFactory(organization=OrganizationFactory(type=MAIN)) self.entity_version = EntityVersionFactory( entity=an_entity, entity_type=entity_type.SCHOOL, start_date=today.replace(year=1900), end_date=None) self.entity_container_year = EntityContainerYearFactory( learning_container_year=self.l_unit_yr_1.learning_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY, entity=self.entity_version.entity) self.entity_container_year = EntityContainerYearFactory( learning_container_year=self.l_unit_yr_1.learning_container_year, type=entity_container_year_link_type.ALLOCATION_ENTITY, entity=self.entity_version.entity) append_latest_entities(self.proposal_1.learning_unit_year)
def test_find_entities(self): work_on_year = 2015 l_container_year = LearningContainerYearFactory( academic_year=self.academic_years[work_on_year]) # Create a link between entity and container # Requirement entity EntityContainerYearFactory( entity=self.entity, learning_container_year=l_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY) # Allocation entity EntityContainerYearFactory( entity=self.entity, learning_container_year=l_container_year, type=entity_container_year_link_type.ALLOCATION_ENTITY) # Find all entities entities = entity_container_year.find_last_entity_version_grouped_by_linktypes( learning_container_year=l_container_year) self.assertIsInstance(entities, dict) self.assertTrue( entity_container_year_link_type.REQUIREMENT_ENTITY in entities) self.assertTrue( entity_container_year_link_type.ALLOCATION_ENTITY in entities) self.assertFalse(entity_container_year_link_type. ADDITIONAL_REQUIREMENT_ENTITY_1 in entities) self.assertFalse(entity_container_year_link_type. ADDITIONAL_REQUIREMENT_ENTITY_2 in entities) # Find requirement entity self.assertEqual( self.entity_versions[work_on_year], entity_container_year.find_requirement_entity( learning_container_year=l_container_year)) # Find allocation entity self.assertEqual( self.entity_versions[work_on_year], entity_container_year.find_allocation_entity( learning_container_year=l_container_year)) # No additional allocation entity self.assertFalse( entity_container_year.find_all_additional_requirement_entities( learning_container_year=l_container_year))
def _assign_volume(container_year, component_year, map_entity_type_and_volume): for entity_type, volume in map_entity_type_and_volume.items(): entity_cont = EntityContainerYearFactory( type=entity_type, learning_container_year=container_year) EntityComponentYearFactory( entity_container_year=entity_cont, learning_component_year=component_year, hourly_volume_total=volume.get('vol_tot'), hourly_volume_partial=volume.get('vol_partial'))
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 test_when_setting_additional_entity_to_none(self): EntityContainerYearFactory( learning_container_year=self.learning_unit_year. learning_container_year, type=entity_container_year_link_type.ALLOCATION_ENTITY) EntityContainerYearFactory(learning_container_year=self. learning_unit_year.learning_container_year, type=entity_container_year_link_type. ADDITIONAL_REQUIREMENT_ENTITY_1) form = LearningUnitProposalModificationForm(self.form_data, self.person) form.save(self.learning_unit_year, PROPOSAL_TYPE, PROPOSAL_STATE) with self.assertRaises(ObjectDoesNotExist): EntityContainerYear.objects.get( learning_container_year=self.learning_unit_year. learning_container_year, type=entity_container_year_link_type. ADDITIONAL_REQUIREMENT_ENTITY_1)
def setUp(self): self.author = PersonFactory() self.proposals = [ProposalLearningUnitFactory() for _ in range(2)] person_entity = PersonEntityFactory(person=self.author) for proposal in self.proposals: EntityContainerYearFactory( learning_container_year=proposal.learning_unit_year. learning_container_year, entity=person_entity.entity, type=entity_container_year_link_type.REQUIREMENT_ENTITY)
def test_find_last_entity_version_by_learning_unit_year_id(self): an_entity_version = EntityVersionFactory() learning_unit_year = LearningUnitYearFactory() EntityContainerYearFactory( entity=an_entity_version.entity, learning_container_year=learning_unit_year.learning_container_year, type=REQUIREMENT_ENTITY) actual_entity_version = find_last_entity_version_by_learning_unit_year_id( learning_unit_year.id) self.assertEqual(an_entity_version, actual_entity_version)
def test_find_by_learning_container_year_and_linktype(self): a_learning_container_year = LearningContainerYearFactory() expected_container = EntityContainerYearFactory( learning_container_year=a_learning_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY) returned_container = entity_container_year.find_by_learning_container_year_and_linktype( a_learning_container_year, entity_container_year_link_type.REQUIREMENT_ENTITY) self.assertEqual(expected_container, returned_container)
def build_allocation_entity_not_in_fac_tree(self): entity_allocation = EntityFactory() EntityVersionFactory(entity=entity_allocation, parent=None, acronym="Entity_allo", start_date=self.start_date, end_date=self.end_date) EntityContainerYearFactory( entity=entity_allocation, learning_container_year=self.l_container_year, type=entity_container_year_link_type.ALLOCATION_ENTITY)
def test_can_delete_learning_unit_year_with_faculty_manager_role(self): # Faculty manager can only delete other type than COURSE/INTERNSHIP/DISSERTATION person = PersonFactory() add_to_group(person.user, FACULTY_MANAGER_GROUP) entity_version = EntityVersionFactory(entity_type=entity_type.FACULTY, acronym="SST", start_date=datetime.date( year=1990, month=1, day=1), end_date=None) PersonEntityFactory(person=person, entity=entity_version.entity, with_child=True) # Creation UE learning_unit = LearningUnitFactory() l_containeryear = LearningContainerYearFactory( academic_year=self.academic_year, container_type=learning_container_year_types.COURSE) EntityContainerYearFactory( learning_container_year=l_containeryear, entity=entity_version.entity, type=entity_container_year_link_type.REQUIREMENT_ENTITY) learning_unit_year = LearningUnitYearFactory( learning_unit=learning_unit, academic_year=self.academic_year, learning_container_year=l_containeryear, subtype=learning_unit_year_subtypes.FULL) # Cannot remove FULL COURSE self.assertFalse( base.business.learning_units.perms. is_eligible_to_delete_learning_unit_year(learning_unit_year, person)) # Can remove PARTIM COURSE learning_unit_year.subtype = learning_unit_year_subtypes.PARTIM learning_unit_year.save() self.assertTrue( base.business.learning_units.perms. is_eligible_to_delete_learning_unit_year(learning_unit_year, person)) # Invalidate cache_property del person.is_central_manager del person.is_faculty_manager # With both role, greatest is taken add_to_group(person.user, CENTRAL_MANAGER_GROUP) learning_unit_year.subtype = learning_unit_year_subtypes.FULL learning_unit_year.save() self.assertTrue( base.business.learning_units.perms. is_eligible_to_delete_learning_unit_year(learning_unit_year, person))
def test_find_entities_with_empty_link_type(self): l_container_year = LearningContainerYearFactory( academic_year=self.academic_years[2015]) # Requirement entity EntityContainerYearFactory( entity=self.entity, learning_container_year=l_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY) # No link between an entity/learning_container_year, so no result no_entity = entity_container_year.find_last_entity_version_grouped_by_linktypes( learning_container_year=l_container_year, link_type=[]) self.assertFalse(no_entity)
def create_learning_unit_with_context(academic_year, structure, entity, acronym): learning_container_year = LearningContainerYearFactory(academic_year=academic_year, acronym=acronym) learning_unit_year = LearningUnitYearFactory(structure=structure, acronym=acronym, learning_container_year=learning_container_year, academic_year=academic_year) EntityContainerYearFactory(type=entity_container_year_link_type.ALLOCATION_ENTITY, learning_container_year=learning_container_year, entity=entity) return learning_unit_year