def test_case_update_internship_subtype_is_disabled(self): container = LearningContainerYearFactory(container_type=learning_container_year_types.COURSE) self.form = LearningUnitYearModelForm( data=None, person=self.central_manager, subtype=PARTIM, instance=LearningUnitYearFactory(learning_container_year=container) ) self.assertTrue(self.form.fields['internship_subtype'].disabled) container.container_type = learning_container_year_types.INTERNSHIP container.save() self.form = LearningUnitYearModelForm( data=None, person=self.central_manager, subtype=PARTIM, instance=LearningUnitYearFactory(learning_container_year=container) ) self.assertFalse(self.form.fields['internship_subtype'].disabled)
def test_can_central_manager_modify_end_date_full(self): a_person = create_person_with_permission_and_group( CENTRAL_MANAGER_GROUP, 'can_edit_learningunit') a_person.user.user_permissions.add( Permission.objects.get(codename='can_edit_learningunit_date')) generated_container = GenerateContainer(start_year=self.academic_yr, end_year=self.academic_yr) generated_container_first_year = generated_container.generated_container_years[ 0] luy = generated_container_first_year.learning_unit_year_full requirement_entity = generated_container_first_year.requirement_entity_container_year PersonEntityFactory(entity=requirement_entity, person=a_person) lunit_container_yr = LearningContainerYearFactory( academic_year=self.academic_yr) for proposal_needed_container_type in ALL_TYPES: lunit_container_yr.container_type = proposal_needed_container_type lunit_container_yr.save() self.assertTrue( perms.is_eligible_for_modification_end_date(luy, a_person))
class PermsTestCase(TestCase): def setUp(self): today = datetime.date.today() self.academic_yr = AcademicYearFactory( start_date=today, end_date=today.replace(year=today.year + 1), year=today.year) self.academic_yr_1 = 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_yr_1).save() self.academic_year_6 = AcademicYearFactory.build( start_date=today.replace(year=today.year + 6), end_date=today.replace(year=today.year + 7), year=today.year + 6) super(AcademicYear, self.academic_year_6).save() self.lunit_container_yr = LearningContainerYearFactory( academic_year=self.academic_yr) lu = LearningUnitFactory(end_year=self.academic_yr.year) self.luy = LearningUnitYearFactory( academic_year=self.academic_yr, learning_container_year=self.lunit_container_yr, subtype=FULL, learning_unit=lu) def test_can_faculty_manager_modify_end_date_partim(self): for container_type in ALL_TYPES: lunit_container_yr = LearningContainerYearFactory( academic_year=self.academic_yr, container_type=container_type) luy = LearningUnitYearFactory( academic_year=self.academic_yr, learning_container_year=lunit_container_yr, subtype=PARTIM) self.assertTrue(luy.can_update_by_faculty_manager()) def test_can_faculty_manager_modify_end_date_full(self): for direct_edit_permitted_container_type in TYPES_DIRECT_EDIT_PERMITTED: lunit_container_yr = LearningContainerYearFactory( academic_year=self.academic_yr, container_type=direct_edit_permitted_container_type) luy = LearningUnitYearFactory( academic_year=self.academic_yr, learning_container_year=lunit_container_yr, subtype=FULL) self.assertTrue(luy.can_update_by_faculty_manager()) def test_cannot_faculty_manager_modify_end_date_full(self): for proposal_needed_container_type in TYPES_PROPOSAL_NEEDED_TO_EDIT: lunit_container_yr = LearningContainerYearFactory( academic_year=self.academic_yr, container_type=proposal_needed_container_type) luy = LearningUnitYearFactory( academic_year=self.academic_yr, learning_container_year=lunit_container_yr, subtype=FULL) self.assertFalse( perms.is_eligible_for_modification_end_date( luy, self.create_person_with_permission_and_group( FACULTY_MANAGER_GROUP))) def test_cannot_faculty_manager_modify_full(self): for proposal_needed_container_type in TYPES_PROPOSAL_NEEDED_TO_EDIT: lunit_container_yr = LearningContainerYearFactory( academic_year=self.academic_year_6, container_type=proposal_needed_container_type) luy = LearningUnitYearFactory( academic_year=self.academic_year_6, learning_container_year=lunit_container_yr, subtype=FULL) self.assertFalse( perms.is_eligible_for_modification( luy, self.create_person_with_permission_and_group( FACULTY_MANAGER_GROUP))) def test_when_existing_proposal_in_epc(self): luy = LearningUnitYearFactory( academic_year=self.academic_yr, learning_unit__existing_proposal_in_epc=True) self.assertFalse(perms.is_eligible_for_modification(luy, None)) self.assertFalse(perms.is_eligible_for_modification_end_date( luy, None)) self.assertFalse(perms.is_eligible_to_create_partim(luy, None)) self.assertFalse( perms.is_eligible_to_create_modification_proposal(luy, None)) self.assertFalse( perms.is_eligible_to_delete_learning_unit_year(luy, None)) def test_cannot_faculty_manager_modify_end_date_no_container(self): luy = LearningUnitYearFactory(academic_year=self.academic_yr, learning_container_year=None) self.assertFalse(luy.can_update_by_faculty_manager()) def test_can_central_manager_modify_end_date_full(self): a_person = self.create_person_with_permission_and_group( CENTRAL_MANAGER_GROUP) generated_container = GenerateContainer( start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[ 0] luy = generated_container_first_year.learning_unit_year_full requirement_entity = generated_container_first_year.requirement_entity_container_year.entity PersonEntityFactory(entity=requirement_entity, person=a_person) for proposal_needed_container_type in ALL_TYPES: self.lunit_container_yr.container_type = proposal_needed_container_type self.lunit_container_yr.save() self.assertTrue( perms.is_eligible_for_modification_end_date(luy, a_person)) def test_access_edit_learning_unit_proposal_as_central_manager(self): a_person = self.create_person_with_permission_and_group( CENTRAL_MANAGER_GROUP) generated_container = GenerateContainer( start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[ 0] luy = generated_container_first_year.learning_unit_year_full requirement_entity = generated_container_first_year.requirement_entity_container_year.entity PersonEntityFactory(entity=requirement_entity, person=a_person) self.assertFalse(perms.is_eligible_to_edit_proposal(None, a_person)) a_proposal = ProposalLearningUnitFactory(learning_unit_year=luy) self.assertTrue( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) def test_access_edit_learning_unit_proposal_of_current_academic_year_as_faculty_manager( self): a_person = self.create_person_with_permission_and_group( FACULTY_MANAGER_GROUP) generated_container = GenerateContainer( start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[ 0] luy = generated_container_first_year.learning_unit_year_full an_requirement_entity = generated_container_first_year.requirement_entity_container_year.entity PersonEntityFactory(entity=an_requirement_entity, person=a_person) a_proposal = ProposalLearningUnitFactory( learning_unit_year=luy, type=proposal_type.ProposalType.MODIFICATION.name, state=proposal_state.ProposalState.FACULTY.name) self.assertFalse( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) def test_access_edit_learning_unit_proposal_as_faculty_manager(self): generated_container = GenerateContainer( start_year=self.academic_yr_1.year, end_year=self.academic_yr_1.year) generated_container_first_year = generated_container.generated_container_years[ 0] an_requirement_entity = generated_container_first_year.requirement_entity_container_year.entity luy = generated_container_first_year.learning_unit_year_full a_person = self.create_person_with_permission_and_group( FACULTY_MANAGER_GROUP) self.assertFalse(perms.is_eligible_to_edit_proposal(None, a_person)) a_proposal = ProposalLearningUnitFactory( state=proposal_state.ProposalState.CENTRAL.name, type=proposal_type.ProposalType.SUPPRESSION.name, learning_unit_year=luy) self.assertFalse( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) PersonEntityFactory(entity=an_requirement_entity, person=a_person) self.assertFalse( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) a_proposal.state = proposal_state.ProposalState.CENTRAL.name a_proposal.save() self.assertFalse( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) a_proposal.state = proposal_state.ProposalState.FACULTY.name a_proposal.save() self.assertTrue( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) for a_type, _ in proposal_type.CHOICES: a_proposal.type = a_type a_proposal.save() if a_proposal.type != ProposalType.MODIFICATION: self.assertTrue( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) else: self.assertFalse( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) 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 test_is_eligible_for_cancel_of_proposal_for_creation(self): generated_container = GenerateContainer( start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[ 0] an_requirement_entity = generated_container_first_year.requirement_entity_container_year.entity luy = generated_container_first_year.learning_unit_year_full a_person = self.create_person_with_permission_and_group( FACULTY_MANAGER_GROUP, 'can_propose_learningunit') a_proposal = ProposalLearningUnitFactory( learning_unit_year=luy, type=proposal_type.ProposalType.CREATION.name, state=proposal_state.ProposalState.FACULTY.name) PersonEntityFactory(person=a_person, entity=an_requirement_entity) self.assertTrue( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person)) def test_is_eligible_for_cancel_of_proposal(self): generated_container = GenerateContainer( start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[ 0] an_requirement_entity = generated_container_first_year.requirement_entity_container_year.entity luy = generated_container_first_year.learning_unit_year_full a_person = self.create_person_with_permission_and_group( FACULTY_MANAGER_GROUP, 'can_propose_learningunit') a_proposal = ProposalLearningUnitFactory( learning_unit_year=luy, type=proposal_type.ProposalType.MODIFICATION.name, state=proposal_state.ProposalState.FACULTY.name, initial_data={ "entities": { entity_container_year_link_type.REQUIREMENT_ENTITY: an_requirement_entity.id, } }) PersonEntityFactory(person=a_person, entity=an_requirement_entity) self.assertTrue( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person)) def test_is_eligible_for_cancel_of_proposal_wrong_state(self): generated_container = GenerateContainer( start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[ 0] an_requirement_entity = generated_container_first_year.requirement_entity_container_year.entity luy = generated_container_first_year.learning_unit_year_full a_person = self.create_person_with_permission_and_group( FACULTY_MANAGER_GROUP, 'can_propose_learningunit') a_proposal = ProposalLearningUnitFactory( learning_unit_year=luy, type=proposal_type.ProposalType.MODIFICATION.name, state=proposal_state.ProposalState.CENTRAL.name, initial_data={ "entities": { entity_container_year_link_type.REQUIREMENT_ENTITY: an_requirement_entity.id, } }) PersonEntityFactory(person=a_person, entity=an_requirement_entity) self.assertFalse( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person)) def test_is_eligible_for_cancel_of_proposal_as_central_manager(self): generated_container = GenerateContainer( start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[ 0] an_requirement_entity = generated_container_first_year.requirement_entity_container_year.entity luy = generated_container_first_year.learning_unit_year_full a_person = self.create_person_with_permission_and_group( CENTRAL_MANAGER_GROUP, 'can_propose_learningunit') a_proposal = ProposalLearningUnitFactory( learning_unit_year=luy, type=proposal_type.ProposalType.MODIFICATION.name, state=proposal_state.ProposalState.CENTRAL.name, initial_data={ "entities": { entity_container_year_link_type.REQUIREMENT_ENTITY: an_requirement_entity.id, } }) PersonEntityFactory(person=a_person, entity=an_requirement_entity) self.assertTrue( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person)) @staticmethod def create_person_with_permission_and_group( group_name=None, permission_name='can_edit_learning_unit_proposal'): a_user = UserFactory() permission, created = Permission.objects.get_or_create( codename=permission_name, content_type=ContentType.objects.get_for_model( ProposalLearningUnit)) a_user.user_permissions.add(permission) a_person = PersonFactory(user=a_user) if group_name: a_person.user.groups.add(Group.objects.get(name=group_name)) return a_person
class PermsTestCase(TestCase): def setUp(self): today = datetime.date.today() self.academic_yr = AcademicYearFactory( start_date=today, end_date=today.replace(year=today.year + 1), year=today.year) self.academic_yr_1 = 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_yr_1).save() self.academic_year_6 = AcademicYearFactory.build( start_date=today.replace(year=today.year + 6), end_date=today.replace(year=today.year + 7), year=today.year + 6) super(AcademicYear, self.academic_year_6).save() self.lunit_container_yr = LearningContainerYearFactory( academic_year=self.academic_yr) lu = LearningUnitFactory(end_year=self.academic_yr.year) self.luy = LearningUnitYearFactory( academic_year=self.academic_yr, learning_container_year=self.lunit_container_yr, subtype=FULL, learning_unit=lu) def test_can_faculty_manager_modify_end_date_partim(self): for container_type in ALL_TYPES: lunit_container_yr = LearningContainerYearFactory( academic_year=self.academic_yr, container_type=container_type) luy = LearningUnitYearFactory( academic_year=self.academic_yr, learning_container_year=lunit_container_yr, subtype=PARTIM) self.assertTrue(luy.can_update_by_faculty_manager()) def test_can_faculty_manager_modify_end_date_full(self): for direct_edit_permitted_container_type in TYPES_DIRECT_EDIT_PERMITTED: lunit_container_yr = LearningContainerYearFactory( academic_year=self.academic_yr, container_type=direct_edit_permitted_container_type) luy = LearningUnitYearFactory( academic_year=self.academic_yr, learning_container_year=lunit_container_yr, subtype=FULL) self.assertTrue(luy.can_update_by_faculty_manager()) def test_cannot_faculty_manager_modify_end_date_full(self): for proposal_needed_container_type in TYPES_PROPOSAL_NEEDED_TO_EDIT: lunit_container_yr = LearningContainerYearFactory( academic_year=self.academic_yr, container_type=proposal_needed_container_type) luy = LearningUnitYearFactory( academic_year=self.academic_yr, learning_container_year=lunit_container_yr, subtype=FULL) self.assertFalse( perms.is_eligible_for_modification_end_date( luy, create_person_with_permission_and_group( FACULTY_MANAGER_GROUP))) def test_cannot_faculty_manager_modify_full(self): for proposal_needed_container_type in TYPES_PROPOSAL_NEEDED_TO_EDIT: lunit_container_yr = LearningContainerYearFactory( academic_year=self.academic_year_6, container_type=proposal_needed_container_type) luy = LearningUnitYearFactory( academic_year=self.academic_year_6, learning_container_year=lunit_container_yr, subtype=FULL) self.assertFalse( perms.is_eligible_for_modification( luy, create_person_with_permission_and_group( FACULTY_MANAGER_GROUP))) def test_when_existing_proposal_in_epc(self): a_person = create_person_with_permission_and_group( CENTRAL_MANAGER_GROUP) luy = LearningUnitYearFactory( academic_year=self.academic_yr, learning_unit__existing_proposal_in_epc=True) self.assertFalse(perms.is_eligible_for_modification(luy, a_person)) self.assertFalse( perms.is_eligible_for_modification_end_date(luy, a_person)) self.assertFalse(perms.is_eligible_to_create_partim(luy, a_person)) self.assertFalse( perms.is_eligible_to_create_modification_proposal(luy, a_person)) self.assertFalse( perms.is_eligible_to_delete_learning_unit_year(luy, a_person)) @mock.patch('base.business.learning_units.perms.is_year_editable') @mock.patch( 'base.business.learning_units.perms._any_existing_proposal_in_epc') @mock.patch( 'base.business.learning_units.perms._is_learning_unit_year_in_range_to_be_modified' ) @mock.patch( 'base.business.learning_units.perms.is_person_linked_to_entity_in_charge_of_lu' ) def test_when_external_learning_unit_is_not_co_graduation( self, mock_is_person_linked_to_entity_in_charge_of_lu, mock_is_learning_unit_year_in_range_to_be_modified, mock_any_existing_proposal_in_epc, mock_is_year_editable): mock_is_person_linked_to_entity_in_charge_of_lu.return_value = True mock_is_learning_unit_year_in_range_to_be_modified.return_value = True mock_any_existing_proposal_in_epc.return_value = True mock_is_year_editable.return_value = True a_person = CentralManagerFactory() luy = LearningUnitYearFactory( academic_year=self.academic_yr, learning_unit__existing_proposal_in_epc=False) ExternalLearningUnitYearFactory(learning_unit_year=luy, co_graduation=False) self.assertFalse( perms.is_external_learning_unit_cograduation(luy, a_person, False)) def test_when_learning_unit_is_not_external(self): learning_unit_year = LearningUnitYearFactory() person = PersonFactory() self.assertTrue( perms.is_external_learning_unit_cograduation( learning_unit_year, person, False)) def test_cannot_faculty_manager_modify_end_date_no_container(self): luy = LearningUnitYearFactory(academic_year=self.academic_yr, learning_container_year=None) self.assertFalse(luy.can_update_by_faculty_manager()) def test_can_central_manager_modify_end_date_full(self): a_person = create_person_with_permission_and_group( CENTRAL_MANAGER_GROUP) generated_container = GenerateContainer( start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[ 0] luy = generated_container_first_year.learning_unit_year_full requirement_entity = generated_container_first_year.requirement_entity_container_year.entity PersonEntityFactory(entity=requirement_entity, person=a_person) for proposal_needed_container_type in ALL_TYPES: self.lunit_container_yr.container_type = proposal_needed_container_type self.lunit_container_yr.save() self.assertTrue( perms.is_eligible_for_modification_end_date(luy, a_person)) def test_access_edit_learning_unit_proposal_as_central_manager(self): a_person = create_person_with_permission_and_group( CENTRAL_MANAGER_GROUP) generated_container = GenerateContainer( start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[ 0] luy = generated_container_first_year.learning_unit_year_full requirement_entity = generated_container_first_year.requirement_entity_container_year.entity PersonEntityFactory(entity=requirement_entity, person=a_person) self.assertFalse(perms.is_eligible_to_edit_proposal(None, a_person)) a_proposal = ProposalLearningUnitFactory(learning_unit_year=luy) self.assertTrue( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) def test_access_edit_learning_unit_proposal_of_current_academic_year_as_faculty_manager( self): a_person = create_person_with_permission_and_group( FACULTY_MANAGER_GROUP) generated_container = GenerateContainer( start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[ 0] luy = generated_container_first_year.learning_unit_year_full an_requirement_entity = generated_container_first_year.requirement_entity_container_year.entity PersonEntityFactory(entity=an_requirement_entity, person=a_person) a_proposal = ProposalLearningUnitFactory( learning_unit_year=luy, type=proposal_type.ProposalType.MODIFICATION.name, state=proposal_state.ProposalState.FACULTY.name) self.assertFalse( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) def test_access_edit_learning_unit_proposal_as_faculty_manager(self): generated_container = GenerateContainer( start_year=self.academic_yr_1.year, end_year=self.academic_yr_1.year) generated_container_first_year = generated_container.generated_container_years[ 0] an_requirement_entity = generated_container_first_year.requirement_entity_container_year.entity luy = generated_container_first_year.learning_unit_year_full a_person = create_person_with_permission_and_group( FACULTY_MANAGER_GROUP) a_proposal = ProposalLearningUnitFactory( state=proposal_state.ProposalState.CENTRAL.name, type=proposal_type.ProposalType.SUPPRESSION.name, learning_unit_year=luy) PersonEntityFactory(entity=an_requirement_entity, person=a_person) self.assertFalse(perms.is_eligible_to_edit_proposal(None, a_person)) self.assertFalse( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) self.assertFalse( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) a_proposal.state = proposal_state.ProposalState.CENTRAL.name a_proposal.save() self.assertFalse( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) a_proposal.state = proposal_state.ProposalState.FACULTY.name a_proposal.save() self.assertTrue( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) for tag in ProposalType.choices(): a_proposal.type = tag[0] a_proposal.save() if a_proposal.type != ProposalType.MODIFICATION: self.assertTrue( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) else: self.assertFalse( perms.is_eligible_to_edit_proposal(a_proposal, a_person)) 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 = 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 test_is_eligible_for_cancel_of_proposal_for_creation(self): generated_container = GenerateContainer( start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[ 0] an_requirement_entity = generated_container_first_year.requirement_entity_container_year.entity luy = generated_container_first_year.learning_unit_year_full a_person = create_person_with_permission_and_group( FACULTY_MANAGER_GROUP, 'can_propose_learningunit') a_proposal = ProposalLearningUnitFactory( learning_unit_year=luy, type=proposal_type.ProposalType.CREATION.name, state=proposal_state.ProposalState.FACULTY.name) PersonEntityFactory(person=a_person, entity=an_requirement_entity) self.assertTrue( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person)) def test_is_eligible_for_cancel_of_proposal(self): generated_container = GenerateContainer( start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[ 0] an_requirement_entity = generated_container_first_year.requirement_entity_container_year.entity luy = generated_container_first_year.learning_unit_year_full a_person = create_person_with_permission_and_group( FACULTY_MANAGER_GROUP, 'can_propose_learningunit') a_proposal = ProposalLearningUnitFactory( learning_unit_year=luy, type=proposal_type.ProposalType.MODIFICATION.name, state=proposal_state.ProposalState.FACULTY.name, initial_data={ "entities": { entity_container_year_link_type.REQUIREMENT_ENTITY: an_requirement_entity.id, } }) PersonEntityFactory(person=a_person, entity=an_requirement_entity) self.assertTrue( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person)) def test_is_eligible_for_cancel_of_proposal_wrong_state(self): generated_container = GenerateContainer( start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[ 0] an_requirement_entity = generated_container_first_year.requirement_entity_container_year.entity luy = generated_container_first_year.learning_unit_year_full a_person = create_person_with_permission_and_group( FACULTY_MANAGER_GROUP, 'can_propose_learningunit') a_proposal = ProposalLearningUnitFactory( learning_unit_year=luy, type=proposal_type.ProposalType.MODIFICATION.name, state=proposal_state.ProposalState.CENTRAL.name, initial_data={ "entities": { entity_container_year_link_type.REQUIREMENT_ENTITY: an_requirement_entity.id, } }) PersonEntityFactory(person=a_person, entity=an_requirement_entity) self.assertFalse( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person)) def test_is_eligible_for_cancel_of_proposal_as_central_manager(self): generated_container = GenerateContainer( start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[ 0] an_requirement_entity = generated_container_first_year.requirement_entity_container_year.entity luy = generated_container_first_year.learning_unit_year_full a_person = create_person_with_permission_and_group( CENTRAL_MANAGER_GROUP, 'can_propose_learningunit') a_proposal = ProposalLearningUnitFactory( learning_unit_year=luy, type=proposal_type.ProposalType.MODIFICATION.name, state=proposal_state.ProposalState.CENTRAL.name, initial_data={ "entities": { entity_container_year_link_type.REQUIREMENT_ENTITY: an_requirement_entity.id, } }) PersonEntityFactory(person=a_person, entity=an_requirement_entity) self.assertTrue( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person))
class AttributionJsonTest(TestCase): def setUp(self): today = date.today() self.academic_year = AcademicYearFactory(year=today.year, start_date=today) # Creation Container / UE and components related self.l_container = LearningContainerYearFactory(academic_year=self.academic_year, acronym="LBIR1210", in_charge=True) self.learning_unit_yr = _create_learning_unit_year_with_components( academic_year=self.academic_year, l_container=self.l_container, acronym="LBIR1210", subtype=learning_unit_year_subtypes.FULL ) _create_learning_unit_year_with_components(academic_year=self.academic_year, l_container=self.l_container, acronym="LBIR1210A", subtype=learning_unit_year_subtypes.PARTIM) _create_learning_unit_year_with_components(academic_year=self.academic_year, l_container=self.l_container, acronym="LBIR1210B", subtype=learning_unit_year_subtypes.PARTIM) # Creation Tutors self.tutor_1 = TutorFactory(person=PersonFactory(first_name="Tom", last_name="Dupont", global_id='00012345')) self.tutor_2 = TutorFactory(person=PersonFactory(first_name="Paul", last_name="Durant", global_id='08923545')) # Creation Attribution and Attributions Charges - Tutor 1 - Holder attribution_tutor_1 = AttributionNewFactory(learning_container_year=self.l_container, tutor=self.tutor_1, function=function.HOLDER) _create_attribution_charge(self.academic_year, attribution_tutor_1, "LBIR1210", Decimal(15.5), Decimal(10)) _create_attribution_charge(self.academic_year, attribution_tutor_1, "LBIR1210A", None, Decimal(5)) # Creation Attribution and Attributions Charges - Tutor 2 - Co-holder attribution_tutor_2 = AttributionNewFactory(learning_container_year=self.l_container, tutor=self.tutor_2, function=function.CO_HOLDER) _create_attribution_charge(self.academic_year, attribution_tutor_2, "LBIR1210B", Decimal(7.5)) def test_build_attributions_json(self): attrib_list = attribution_json._compute_list() self.assertIsInstance(attrib_list, list) self.assertEqual(len(attrib_list), 2) attrib_tutor_1 = next( (attrib for attrib in attrib_list if attrib['global_id'] == self.tutor_1.person.global_id), None) self.assertTrue(attrib_tutor_1) self.assertEqual(len(attrib_tutor_1['attributions']), 2) #Check if attribution is correct attrib_tutor_2 = next( (attrib for attrib in attrib_list if attrib['global_id'] == self.tutor_2.person.global_id), None) self.assertTrue(attrib_tutor_2) self.assertEqual(len(attrib_tutor_2['attributions']), 1) self.assertEqual(attrib_tutor_2['attributions'][0]['acronym'], "LBIR1210B") self.assertEqual(attrib_tutor_2['attributions'][0]['function'], function.CO_HOLDER) self.assertEqual(attrib_tutor_2['attributions'][0][learning_component_year_type.LECTURING], "7.5") self.assertRaises(KeyError, lambda: attrib_tutor_2['attributions'][0][learning_component_year_type.PRACTICAL_EXERCISES + '_CHARGE']) def test_learning_unit_in_charge_false(self): self.l_container.in_charge = False self.l_container.save() attrib_list = attribution_json._compute_list() self.assertIsInstance(attrib_list, list) self.assertEqual(len(attrib_list), 2) attrib_tutor_1 = next( (attrib for attrib in attrib_list if attrib['global_id'] == self.tutor_1.person.global_id), None) self.assertTrue(attrib_tutor_1) self.assertEqual(len(attrib_tutor_1['attributions']), 0) def test_two_attribution_function_to_same_learning_unit(self): new_attrib = AttributionNewFactory(learning_container_year=self.l_container, tutor=self.tutor_1, function=function.COORDINATOR) _create_attribution_charge(self.academic_year, new_attrib, "LBIR1210", Decimal(0), Decimal(0)) attrib_list = attribution_json._compute_list() self.assertIsInstance(attrib_list, list) self.assertEqual(len(attrib_list), 2) attrib_tutor_1 = next( (attrib for attrib in attrib_list if attrib['global_id'] == self.tutor_1.person.global_id), None ) self.assertEqual(len(attrib_tutor_1['attributions']), 3) def test_with_specific_global_id(self): global_id = self.tutor_2.person.global_id attrib_list = attribution_json._compute_list(global_ids=[global_id]) self.assertIsInstance(attrib_list, list) self.assertEqual(len(attrib_list), 1) attrib_tutor_2 = next( (attrib for attrib in attrib_list if attrib['global_id'] == global_id), None ) self.assertEqual(len(attrib_tutor_2['attributions']), 1) def test_with_multiple_global_id(self): global_id = self.tutor_2.person.global_id global_id_with_no_attributions = "4598989898" attrib_list = attribution_json._compute_list(global_ids=[global_id, global_id_with_no_attributions]) self.assertIsInstance(attrib_list, list) self.assertEqual(len(attrib_list), 2) attribution_data = next( (attrib for attrib in attrib_list if attrib['global_id'] == global_id_with_no_attributions), None ) self.assertFalse(attribution_data['attributions']) def test_get_title_next_luyr(self): self.assertIsNone(attribution_json._get_title_next_luyr(self.learning_unit_yr)) next_academic_year = AcademicYearFactory(year=self.academic_year.year+1) self.assertIsNone(attribution_json._get_title_next_luyr(self.learning_unit_yr)) next_luy = LearningUnitYearFactory(learning_unit=self.learning_unit_yr.learning_unit, academic_year=next_academic_year) self.assertEqual(attribution_json._get_title_next_luyr(self.learning_unit_yr), next_luy.complete_title)
class TestTutorApplicationEpc(TestCase): def setUp(self): self.academic_year = AcademicYearFactory(year=2017) external_id = tutor_application_epc.LEARNING_CONTAINER_YEAR_PREFIX_EXTERNAL_ID + '35654987_2017' self.lbir1200 = LearningContainerYearFactory(academic_year=self.academic_year, acronym="LBIR1200", external_id=external_id) self.lagro2630 = LearningContainerYearFactory(academic_year=self.academic_year, acronym="LAGRO2630") # Creation Person/Tutor Group.objects.create(name="tutors") person = PersonFactory(global_id="98363454") external_id = tutor_application_epc.TUTOR_PREFIX_EXTERNAL_ID + '2089590559' self.tutor = TutorFactory(external_id=external_id, person=person) # Create two tutor applications applications = [_get_application_example(self.lbir1200, '30.5', '40.5'), _get_application_example(self.lagro2630, '12.5', '0')] self.attribution = AttributionNewFactory( global_id=person.global_id, applications=applications ) def test_extract_learning_container_year_epc_info(self): learning_container_info = tutor_application_epc._extract_learning_container_year_epc_info('LBIR1200', 2017) self.assertIsInstance(learning_container_info, dict) self.assertEqual(learning_container_info['reference'], '35654987') self.assertEqual(learning_container_info['year'], 2017) def test_extract_learning_container_year_epc_info_empty(self): learning_container_info = tutor_application_epc._extract_learning_container_year_epc_info('LBIR1250', 2017) self.assertIsInstance(learning_container_info, dict) self.assertFalse(learning_container_info) def test_extract_learning_container_year_epc_info_with_external_id_empty(self): self.lbir1200.external_id = None self.lbir1200.save() learning_container_info = tutor_application_epc._extract_learning_container_year_epc_info('LBIR1200', 2017) self.assertIsInstance(learning_container_info, dict) self.assertFalse(learning_container_info) def test_convert_to_epc_application(self): person = self.tutor.person application = _get_application_example(self.lbir1200, '30.5', '40.5') epc_message = tutor_application_epc._convert_to_epc_application(application=application) self.assertTrue(epc_message) self.assertEqual(epc_message['remark'], application['remark']) self.assertEqual(epc_message['course_summary'], application['course_summary']) self.assertEqual(epc_message['lecturing_allocation'], application['charge_lecturing_asked']) self.assertEqual(epc_message['practical_allocation'], application['charge_practical_asked']) self.assertIsInstance(epc_message['learning_container_year'], dict) self.assertEqual(epc_message['learning_container_year']['reference'], '35654987') self.assertEqual(epc_message['learning_container_year']['year'], 2017) def test_process_message_delete_operation(self): person = self.tutor.person self.assertEqual(len(self.attribution.applications), 2) body = { 'operation': tutor_application_epc.DELETE_OPERATION, 'global_id': person.global_id, 'learning_container_year': { 'acronym': 'LBIR1200', 'year': 2017 } } body_encoded = bytearray(json.dumps(body), "utf-8") tutor_application_epc.process_message(body_encoded) # Check if the application is removed self.attribution.refresh_from_db() self.assertEqual(len(self.attribution.applications), 1) attribution_left = self.attribution.applications[0] self.assertEqual(attribution_left['acronym'], self.lagro2630.acronym) def test_process_message_update_operation(self): person = self.tutor.person _set_all_application_in_pending_state(self.attribution.applications) self.attribution.save() ## Check if all are in pending self.assertEqual(len(self.attribution.applications), 2) self.assertEqual(self.attribution.applications[0]['pending'], tutor_application_epc.UPDATE_OPERATION) self.assertEqual(self.attribution.applications[1]['pending'], tutor_application_epc.UPDATE_OPERATION) body = { 'operation': tutor_application_epc.UPDATE_OPERATION, 'global_id': person.global_id, 'learning_container_year': { 'acronym': 'LBIR1200', 'year': 2017 } } body_encoded = bytearray(json.dumps(body), "utf-8") tutor_application_epc.process_message(body_encoded) # Check if the application is removed self.attribution.refresh_from_db() applications_not_pending = [application for application in self.attribution.applications if not "pending" in application] self.assertEqual(len(applications_not_pending), 1) def test_process_message_with_error_operation(self): person = self.tutor.person _set_all_application_in_pending_state(self.attribution.applications) self.attribution.save() ## Check if all are in pending self.assertEqual(len(self.attribution.applications), 2) self.assertEqual(self.attribution.applications[0]['pending'], tutor_application_epc.UPDATE_OPERATION) self.assertEqual(self.attribution.applications[1]['pending'], tutor_application_epc.UPDATE_OPERATION) body = { 'operation': tutor_application_epc.UPDATE_OPERATION, 'global_id': person.global_id, 'learning_container_year': { 'acronym': 'LBIR1200', 'year': 2017 }, tutor_application_epc.ERROR_EPC_FIELD: 'An error occured in EPC' } body_encoded = bytearray(json.dumps(body), "utf-8") tutor_application_epc.process_message(body_encoded) # Check if the application is removed self.attribution.refresh_from_db() applications_not_pending = [application for application in self.attribution.applications if not "pending" in application] self.assertEqual(len(applications_not_pending), 0) # No changed
class AttributionJsonTest(TestCase): def setUp(self): today = date.today() self.academic_year = AcademicYearFactory(year=today.year, start_date=today) # Creation Container / UE and components related self.l_container = LearningContainerYearFactory(academic_year=self.academic_year, acronym="LBIR1210", in_charge=True) _create_learning_unit_year_with_components(academic_year=self.academic_year, l_container=self.l_container, acronym="LBIR1210",subtype=learning_unit_year_subtypes.FULL) _create_learning_unit_year_with_components(academic_year=self.academic_year, l_container=self.l_container, acronym="LBIR1210A", subtype=learning_unit_year_subtypes.PARTIM) _create_learning_unit_year_with_components(academic_year=self.academic_year, l_container=self.l_container, acronym="LBIR1210B", subtype=learning_unit_year_subtypes.PARTIM) # Creation Tutors self.tutor_1 = TutorFactory(person=PersonFactory(first_name="Tom", last_name="Dupont", global_id='00012345')) self.tutor_2 = TutorFactory(person=PersonFactory(first_name="Paul", last_name="Durant", global_id='08923545')) # Creation Attribution and Attributions Charges - Tutor 1 - Holder attribution_tutor_1 = AttributionNewFactory(learning_container_year=self.l_container, tutor=self.tutor_1, function=function.HOLDER) _create_attribution_charge(self.academic_year, attribution_tutor_1, "LBIR1210", Decimal(15.5), Decimal(10)) _create_attribution_charge(self.academic_year, attribution_tutor_1, "LBIR1210A", None, Decimal(5)) # Creation Attribution and Attributions Charges - Tutor 2 - Co-holder attribution_tutor_2 = AttributionNewFactory(learning_container_year=self.l_container, tutor=self.tutor_2, function=function.CO_HOLDER) _create_attribution_charge(self.academic_year, attribution_tutor_2, "LBIR1210B", Decimal(7.5)) def test_build_attributions_json(self): attrib_list = attribution_json._compute_list() self.assertIsInstance(attrib_list, list) self.assertEqual(len(attrib_list), 2) attrib_tutor_1 = next( (attrib for attrib in attrib_list if attrib['global_id'] == self.tutor_1.person.global_id), None) self.assertTrue(attrib_tutor_1) self.assertEqual(len(attrib_tutor_1['attributions']), 2) #Check if attribution is correct attrib_tutor_2 = next( (attrib for attrib in attrib_list if attrib['global_id'] == self.tutor_2.person.global_id), None) self.assertTrue(attrib_tutor_2) self.assertEqual(len(attrib_tutor_2['attributions']), 1) self.assertEqual(attrib_tutor_2['attributions'][0]['acronym'], "LBIR1210B") self.assertEqual(attrib_tutor_2['attributions'][0]['function'], function.CO_HOLDER) self.assertEqual(attrib_tutor_2['attributions'][0][learning_component_year_type.LECTURING], "7.5") self.assertRaises(KeyError, lambda: attrib_tutor_2['attributions'][0][learning_component_year_type.PRACTICAL_EXERCISES + '_CHARGE']) def test_learning_unit_in_charge_false(self): self.l_container.in_charge = False self.l_container.save() attrib_list = attribution_json._compute_list() self.assertIsInstance(attrib_list, list) self.assertEqual(len(attrib_list), 2) attrib_tutor_1 = next( (attrib for attrib in attrib_list if attrib['global_id'] == self.tutor_1.person.global_id), None) self.assertTrue(attrib_tutor_1) self.assertEqual(len(attrib_tutor_1['attributions']), 0) def test_two_attribution_function_to_same_learning_unit(self): new_attrib = AttributionNewFactory(learning_container_year=self.l_container, tutor=self.tutor_1, function=function.COORDINATOR) _create_attribution_charge(self.academic_year, new_attrib, "LBIR1210", Decimal(0), Decimal(0)) attrib_list = attribution_json._compute_list() self.assertIsInstance(attrib_list, list) self.assertEqual(len(attrib_list), 2) attrib_tutor_1 = next( (attrib for attrib in attrib_list if attrib['global_id'] == self.tutor_1.person.global_id), None ) self.assertEqual(len(attrib_tutor_1['attributions']), 3) def test_with_specific_global_id(self): global_id = self.tutor_2.person.global_id attrib_list = attribution_json._compute_list(global_ids=[global_id]) self.assertIsInstance(attrib_list, list) self.assertEqual(len(attrib_list), 1) attrib_tutor_2 = next( (attrib for attrib in attrib_list if attrib['global_id'] == global_id), None ) self.assertEqual(len(attrib_tutor_2['attributions']), 1) def test_with_multiple_global_id(self): global_id = self.tutor_2.person.global_id global_id_with_no_attributions = "4598989898" attrib_list = attribution_json._compute_list(global_ids=[global_id, global_id_with_no_attributions]) self.assertIsInstance(attrib_list, list) self.assertEqual(len(attrib_list), 2) attribution_data = next( (attrib for attrib in attrib_list if attrib['global_id'] == global_id_with_no_attributions), None ) self.assertFalse(attribution_data['attributions'])
class TestLearningUnitModificationForm(TestCase): @classmethod def setUpTestData(cls): cls.current_academic_year = create_current_academic_year() cls.organization = OrganizationFactory(type=organization_type.MAIN) a_campus = CampusFactory(organization=cls.organization) an_entity = EntityFactory(organization=cls.organization) cls.an_entity_version = EntityVersionFactory( entity=an_entity, entity_type=entity_type.SCHOOL, parent=None, end_date=None, start_date=datetime.date.today() - datetime.timedelta(days=5)) cls.person = PersonEntityFactory(entity=an_entity).person language = LanguageFactory() cls.form_data = { "academic_year": str(cls.current_academic_year.id), "container_type": str(learning_container_year_types.COURSE), "subtype": str(learning_unit_year_subtypes.FULL), "acronym": "OSIS1452", "credits": "45", "specific_title": "OSIS", "first_letter": "L", "periodicity": learning_unit_periodicity.ANNUAL, "campus": str(a_campus.id), "requirement_entity": str(cls.an_entity_version.id), "allocation_entity": str(cls.an_entity_version.id), "language": language.pk } cls.initial_data = { "academic_year": str(cls.current_academic_year.id), "container_type": str(learning_container_year_types.COURSE), "subtype": str(learning_unit_year_subtypes.FULL), "acronym": "OSIS1452", "first_letter": "L", "status": True } cls.faculty_user = UserFactory() cls.faculty_user.groups.add( Group.objects.get(name=FACULTY_MANAGER_GROUP)) cls.faculty_person = PersonFactory(user=cls.faculty_user) cls.faculty_user.user_permissions.add( Permission.objects.get(codename='can_propose_learningunit')) PersonEntityFactory(entity=an_entity, person=cls.faculty_person) def setUp(self): self.learning_container_year = LearningContainerYearFactory( academic_year=self.current_academic_year, container_type=COURSE) self.learning_unit_year = LearningUnitYearFactory( academic_year=self.current_academic_year, learning_container_year=self.learning_container_year, learning_unit__periodicity=ANNUAL, subtype=FULL, credits=25, status=False) self.learning_unit_year_partim_1 = LearningUnitYearFactory( academic_year=self.current_academic_year, learning_container_year=self.learning_container_year, learning_unit__periodicity=ANNUAL, subtype=PARTIM, credits=20, status=False) self.learning_unit_year_partim_2 = LearningUnitYearFactory( academic_year=self.current_academic_year, learning_container_year=self.learning_container_year, learning_unit__periodicity=ANNUAL, subtype=PARTIM, credits=18, status=False) def test_disabled_fields_in_case_of_learning_unit_of_type_full(self): form = LearningUnitModificationForm( person=self.person, learning_unit_year_instance=self.learning_unit_year) disabled_fields = ("first_letter", "acronym", "academic_year", "container_type", "subtype") for field in disabled_fields: self.assertTrue(form.fields[field].disabled) def test_disabled_fields_in_case_of_learning_unit_of_type_partim(self): form = LearningUnitModificationForm( person=self.person, learning_unit_year_instance=self.learning_unit_year_partim_1) disabled_fields = ('first_letter', 'acronym', 'common_title', 'common_title_english', 'requirement_entity', 'allocation_entity', 'language', 'campus', 'container_type', "academic_year", 'internship_subtype', 'additional_requirement_entity_1', 'additional_requirement_entity_2', 'is_vacant', 'team', 'type_declaration_vacant', 'attribution_procedure', "subtype", "status") for field in form.fields: if field in disabled_fields: self.assertTrue(form.fields[field].disabled, field) else: self.assertFalse(form.fields[field].disabled, field) def test_disabled_internship_subtype_in_case_of_container_type_different_than_internship( self): form = LearningUnitModificationForm( person=self.person, learning_unit_year_instance=self.learning_unit_year) self.assertTrue(form.fields["internship_subtype"].disabled) self.learning_unit_year.learning_container_year.container_type = learning_container_year_types.INTERNSHIP form = LearningUnitModificationForm( person=self.person, learning_unit_year_instance=self.learning_unit_year) self.assertFalse(form.fields["internship_subtype"].disabled) def test_entity_does_not_exist_for_lifetime_of_learning_unit(self): an_other_entity = EntityFactory(organization=self.organization) an_other_entity_version = EntityVersionFactory( entity=an_other_entity, entity_type=entity_type.SCHOOL, parent=None, end_date=self.current_academic_year.end_date - datetime.timedelta(days=5), start_date=datetime.date.today() - datetime.timedelta(days=5)) PersonEntityFactory(person=self.person, entity=an_other_entity) form_data_with_invalid_requirement_entity = self.form_data.copy() form_data_with_invalid_requirement_entity["requirement_entity"] = str( an_other_entity_version.id) form = LearningUnitModificationForm( form_data_with_invalid_requirement_entity, person=self.person, end_date=self.current_academic_year.end_date, learning_unit_year_instance=self.learning_unit_year) self.assertFalse(form.is_valid()) def test_set_status_value(self): form = LearningUnitModificationForm( learning_unit_year_instance=self.learning_unit_year_partim_1, person=self.person) self.assertEqual(form.fields["status"].initial, False) self.assertTrue(form.fields["status"].disabled) def test_partim_can_modify_periodicity(self): initial_data_with_subtype_partim = self.initial_data.copy() initial_data_with_subtype_partim[ "subtype"] = learning_unit_year_subtypes.PARTIM form = LearningUnitModificationForm( learning_unit_year_instance=self.learning_unit_year_partim_1, person=self.person) self.assertFalse(form.fields["periodicity"].disabled) def test_do_not_set_minimum_credits_for_full_learning_unit_year_if_no_partims( self): learning_unit_year_with_no_partims = LearningUnitYearFactory( academic_year=self.current_academic_year, learning_unit__periodicity=ANNUAL, subtype=FULL) form = LearningUnitModificationForm( person=self.person, learning_unit_year_instance=learning_unit_year_with_no_partims) self.assertEqual(form.fields["credits"].min_value, None) def test_entity_does_not_exist_for_lifetime_of_learning_unit_with_no_planned_end( self): an_other_entity = EntityFactory(organization=self.organization) an_other_entity_version = EntityVersionFactory( entity=an_other_entity, entity_type=entity_type.SCHOOL, parent=None, end_date=self.current_academic_year.end_date - datetime.timedelta(days=5), start_date=datetime.date.today() - datetime.timedelta(days=5)) PersonEntityFactory(person=self.person, entity=an_other_entity) form_data_with_invalid_requirement_entity = self.form_data.copy() form_data_with_invalid_requirement_entity["requirement_entity"] = str( an_other_entity_version.id) form = LearningUnitModificationForm( form_data_with_invalid_requirement_entity, person=self.person, learning_unit_year_instance=self.learning_unit_year) self.assertFalse(form.is_valid()) def test_when_requirement_and_attribution_entities_are_different_for_disseration_and_internship_subtype( self): an_other_entity_version = EntityVersionFactory( entity__organization=self.organization, entity_type=entity_type.SCHOOL, parent=None, end_date=None, start_date=datetime.date.today() - datetime.timedelta(days=5)) form_data_with_different_allocation_entity = self.form_data.copy() form_data_with_different_allocation_entity["allocation_entity"] = str( an_other_entity_version.id) for container_type in (learning_container_year_types.DISSERTATION, learning_container_year_types.INTERNSHIP): self.learning_container_year.container_type = container_type self.learning_container_year.save() form = LearningUnitModificationForm( form_data_with_different_allocation_entity, person=self.person, learning_unit_year_instance=self.learning_unit_year) self.assertFalse(form.is_valid(), container_type) def test_when_partim_active_but_modify_parent_to_inactive(self): # Set status to parent inactive form_data_parent_with_status_inactive = self.form_data.copy() form_data_parent_with_status_inactive['status'] = False # Set status to partim active self.learning_unit_year_partim_1.status = True self.learning_unit_year_partim_1.save() form = LearningUnitModificationForm( form_data_parent_with_status_inactive, person=self.person, end_date=self.current_academic_year.end_date, learning_unit_year_instance=self.learning_unit_year) self.assertFalse(form.is_valid()) self.assertEqual( form.errors['status'], [_('The parent must be active because there are partim active')]) def test_valid_form(self): form = LearningUnitModificationForm( self.form_data, person=self.person, learning_unit_year_instance=self.learning_unit_year) self.assertTrue(form.is_valid(), form.errors) def test_valid_form_with_faculty_manager(self): form = LearningUnitModificationForm( self.form_data, person=self.person, learning_unit_year_instance=self.learning_unit_year) self.assertTrue(form.is_valid(), form.errors) def test_deactivated_fields_in_learning_unit_modification_form(self): form = LearningUnitModificationForm( person=self.person, learning_unit_year_instance=self.learning_unit_year) self.assertFalse(form.fields["common_title"].disabled) self.assertFalse(form.fields["common_title_english"].disabled) self.assertFalse(form.fields["specific_title"].disabled) self.assertFalse(form.fields["specific_title_english"].disabled) self.assertFalse(form.fields["faculty_remark"].disabled) self.assertFalse(form.fields["other_remark"].disabled) self.assertFalse(form.fields["campus"].disabled) self.assertFalse(form.fields["status"].disabled) self.assertFalse(form.fields["credits"].disabled) self.assertFalse(form.fields["language"].disabled) self.assertFalse(form.fields["requirement_entity"].disabled) self.assertFalse(form.fields["allocation_entity"].disabled) self.assertFalse( form.fields["additional_requirement_entity_2"].disabled) self.assertFalse(form.fields["is_vacant"].disabled) self.assertFalse(form.fields["type_declaration_vacant"].disabled) self.assertFalse(form.fields["attribution_procedure"].disabled) self.assertTrue(form.fields["subtype"].disabled) def test_deactivated_fields_in_learning_unit_modification_form_with_faculty_manager( self): form = LearningUnitModificationForm( person=self.faculty_person, learning_unit_year_instance=self.learning_unit_year) self.assertTrue(form.fields["common_title"].disabled) self.assertTrue(form.fields["common_title_english"].disabled) self.assertTrue(form.fields["specific_title"].disabled) self.assertTrue(form.fields["specific_title_english"].disabled) self.assertFalse(form.fields["faculty_remark"].disabled) self.assertFalse(form.fields["other_remark"].disabled) self.assertTrue(form.fields["campus"].disabled) self.assertTrue(form.fields["status"].disabled) self.assertTrue(form.fields["credits"].disabled) self.assertTrue(form.fields["language"].disabled) self.assertTrue(form.fields["requirement_entity"].disabled) self.assertTrue(form.fields["allocation_entity"].disabled) self.assertTrue( form.fields["additional_requirement_entity_2"].disabled) self.assertTrue(form.fields["is_vacant"].disabled) self.assertTrue(form.fields["type_declaration_vacant"].disabled) self.assertTrue(form.fields["attribution_procedure"].disabled) self.assertTrue(form.fields["subtype"].disabled)