def test_check_postponement_conflict_on_volumes_case_no_diff(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() # Create LUY with components LECTURING / PRACTICAL EXERCICES + link to the same learning unit another_learning_unit_year = _create_learning_unit_year_with_components(another_learning_container_year, create_pratical_component=True, create_lecturing_component=True) another_learning_unit_year.learning_unit = self.learning_unit_year.learning_unit another_learning_unit_year.save() _create_entity_container_with_entity_components(another_learning_unit_year, entity_container_year_link_type.ALLOCATION_ENTITY, self.allocation_entity.entity) _create_entity_container_with_entity_components(another_learning_unit_year, entity_container_year_link_type.REQUIREMENT_ENTITY, self.requirement_entity.entity, repartition_lecturing=30, repartition_practical_exercises=10) _create_entity_container_with_entity_components(another_learning_unit_year, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1, self.add_requirement_entity_1.entity, repartition_lecturing=10, repartition_practical_exercises=5) error_list = business_edition._check_postponement_conflict_on_volumes(self.learning_container_year, another_learning_container_year) self.assertIsInstance(error_list, list) self.assertFalse(error_list)
def test_check_postponement_conflict_on_volumes_case_no_practical_exercise_component_current_year( self): """ The goal of this test is to ensure that there is an error IF the learning unit year on next year have component PRACTICAL EXERCISES that the learning unit year on the current year doesn't have """ # 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() # Create LUY with components LECTURING / PRACTICAL EXERCISES + link to the same learning unit another_learning_unit_year = _create_learning_unit_year_with_components( another_learning_container_year, create_pratical_component=True, create_lecturing_component=True) another_learning_unit_year.learning_unit = self.learning_unit_year.learning_unit another_learning_unit_year.save() _create_entity_container_with_entity_components( another_learning_unit_year, entity_container_year_link_type.ALLOCATION_ENTITY, self.allocation_entity.entity) _create_entity_container_with_entity_components( another_learning_unit_year, entity_container_year_link_type.REQUIREMENT_ENTITY, self.requirement_entity.entity, repartition_lecturing=30, repartition_practical_exercises=10) _create_entity_container_with_entity_components( another_learning_unit_year, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1, self.add_requirement_entity_1.entity, repartition_lecturing=10, repartition_practical_exercises=5) # REMOVE PRATICAL_EXERCICE component for current learning unit year _delete_components(self.learning_unit_year, learning_component_year_type.PRACTICAL_EXERCISES) error_list = business_edition._check_postponement_conflict_on_volumes( self.learning_container_year, another_learning_container_year) self.assertIsInstance(error_list, list) self.assertEqual(len(error_list), 1) error_expected = _( "There is not %(component_type)s for the learning unit %(acronym)s - %(year)s but exist " "in %(existing_year)s") % { 'component_type': _( learning_component_year_type.PRACTICAL_EXERCISES), 'acronym': self.learning_container_year.acronym, 'year': self.learning_container_year.academic_year, 'existing_year': self.next_academic_year } self.assertIn(error_expected, error_list)
def test_check_postponement_conflict_on_volumes_case_additional_entity_lecturing_diff(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() # Create LUY with components LECTURING / PRACTICAL EXERCICES + link to the same learning unit another_learning_unit_year = _create_learning_unit_year_with_components(another_learning_container_year, create_pratical_component=True, create_lecturing_component=True) another_learning_unit_year.learning_unit = self.learning_unit_year.learning_unit another_learning_unit_year.save() _create_entity_container_with_entity_components(another_learning_unit_year, entity_container_year_link_type.ALLOCATION_ENTITY, self.allocation_entity.entity) _create_entity_container_with_entity_components(another_learning_unit_year, entity_container_year_link_type.REQUIREMENT_ENTITY, self.requirement_entity.entity, repartition_lecturing=30, repartition_practical_exercises=10) _create_entity_container_with_entity_components(another_learning_unit_year, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1, self.add_requirement_entity_1.entity, repartition_lecturing=20, repartition_practical_exercises=10) error_list = business_edition._check_postponement_conflict_on_volumes(self.learning_container_year, another_learning_container_year) self.assertIsInstance(error_list, list) self.assertEqual(len(error_list), 8) error_expected = (_("The value of field '%(field)s' for the learning unit %(acronym)s (%(component_type)s) " "is different between year %(year)s - %(value)s and year %(next_year)s - %(next_value)s") % { 'field': _('volume_q2'), 'acronym': another_learning_container_year.acronym, 'component_type': _(learning_component_year_type.LECTURING), 'year': self.learning_container_year.academic_year, 'value': 40.0, 'next_year': another_learning_container_year.academic_year, 'next_value': 50.0, }) self.assertIn(error_expected, error_list)
def test_check_postponement_conflict_on_volumes_multiples_differences( 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() # Create LUY with components LECTURING / PRACTICAL EXERCICES + link to the same learning unit another_learning_unit_year = _create_learning_unit_year_with_components( another_learning_container_year, create_pratical_component=True, create_lecturing_component=True) another_learning_unit_year.learning_unit = self.learning_unit_year.learning_unit LearningComponentYear.objects.filter( learningunitcomponent__learning_unit_year=self.learning_unit_year ).update(hourly_volume_total_annual=60, hourly_volume_partial_q1=40, hourly_volume_partial_q2=20) LearningComponentYear.objects.filter( learningunitcomponent__learning_unit_year=another_learning_unit_year ).update(hourly_volume_total_annual=50, hourly_volume_partial_q1=35, hourly_volume_partial_q2=15) another_learning_unit_year.save() _create_entity_container_with_entity_components( another_learning_unit_year, entity_container_year_link_type.ALLOCATION_ENTITY, self.allocation_entity.entity) _create_entity_container_with_entity_components( another_learning_unit_year, entity_container_year_link_type.REQUIREMENT_ENTITY, self.requirement_entity.entity, repartition_lecturing=30, repartition_practical_exercises=10) _create_entity_container_with_entity_components( another_learning_unit_year, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1, self.add_requirement_entity_1.entity, repartition_lecturing=20, repartition_practical_exercises=10) error_list = business_edition._check_postponement_conflict_on_volumes( self.learning_container_year, another_learning_container_year) self.assertIsInstance(error_list, list) self.assertEqual(len(error_list), 10) tests_cases = [{ 'field': 'volume_additional_requirement_entity_1', 'value': 10.0, 'next_value': 20.0 }, { 'field': 'volume_total', 'value': 60.0, 'next_value': 50.0 }, { 'field': 'volume_q1', 'value': 40.0, 'next_value': 35.0 }, { 'field': 'volume_q2', 'value': 20.0, 'next_value': 15.0 }] for test in tests_cases: with self.subTest(test=test): error_expected = (_( "The value of field '%(field)s' for the learning unit %(acronym)s " "(%(component_type)s) is different between year %(year)s - %(value)s and year " "%(next_year)s - %(next_value)s") % { 'field': _(test.get('field')), 'acronym': another_learning_container_year.acronym, 'component_type': _(learning_component_year_type.LECTURING), 'year': self.learning_container_year.academic_year, 'value': test.get('value'), 'next_year': another_learning_container_year.academic_year, 'next_value': test.get('next_value'), }) self.assertIn(error_expected, error_list)
def test_check_postponement_conflict_on_volumes_multiples_differences( 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() # Create LUY with components LECTURING / PRACTICAL EXERCICES + link to the same learning unit another_learning_unit_year = _create_learning_unit_year_with_components( another_learning_container_year, create_pratical_component=True, create_lecturing_component=True) another_learning_unit_year.learning_unit = self.learning_unit_year.learning_unit LearningComponentYear.objects.filter( learning_unit_year=self.learning_unit_year).update( hourly_volume_total_annual=Decimal(60), hourly_volume_partial_q1=Decimal(40), hourly_volume_partial_q2=Decimal(20)) LearningComponentYear.objects.filter( learning_unit_year=another_learning_unit_year).update( hourly_volume_total_annual=Decimal(50), hourly_volume_partial_q1=Decimal(35), hourly_volume_partial_q2=Decimal(15)) another_learning_unit_year.save() _create_entity_container_with_components( another_learning_unit_year, entity_container_year_link_type.ALLOCATION_ENTITY, self.allocation_entity) _create_entity_container_with_components( another_learning_unit_year, entity_container_year_link_type.REQUIREMENT_ENTITY, self.requirement_entity, repartition_lecturing=Decimal(30), repartition_practical_exercises=Decimal(10)) _create_entity_container_with_components( another_learning_unit_year, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1, self.add_requirement_entity_1, repartition_lecturing=Decimal(20), repartition_practical_exercises=Decimal(10)) error_list = business_edition._check_postponement_conflict_on_volumes( self.learning_container_year, another_learning_container_year) self.assertIsInstance(error_list, list) self.assertEqual(len(error_list), 10) tests_cases = [{ 'field': VOLUME_ADDITIONAL_REQUIREMENT_ENTITY_1, 'value': Decimal(10), 'next_value': Decimal(20) }, { 'field': VOLUME_TOTAL, 'value': Decimal(60), 'next_value': Decimal(50) }, { 'field': VOLUME_Q1, 'value': Decimal(40), 'next_value': Decimal(35) }, { 'field': VOLUME_Q2, 'value': Decimal(20), 'next_value': Decimal(15) }] for test in tests_cases: with self.subTest(test=test): error_expected = (_( "The value of field '%(field)s' for the learning unit %(acronym)s " "(%(component_type)s) is different between year %(year)s - %(value)s and year " "%(next_year)s - %(next_value)s") % { 'field': COMPONENT_DETAILS[test.get('field')].lower(), 'acronym': another_learning_container_year.acronym, 'component_type': _( dict(COMPONENT_TYPES)[ learning_component_year_type.LECTURING]), 'year': self.learning_container_year.academic_year, 'value': test.get('value'), 'next_year': another_learning_container_year.academic_year, 'next_value': test.get('next_value'), }) self.assertIn(error_expected, error_list)