def test_get_volume_form(self): for component, component_values in self.learning_unit_with_context.components.items(): component_values = VolumeEditionBaseFormset._clean_component_keys(component_values) form = VolumeEditionForm(learning_unit_year=self.learning_unit_with_context, initial=component_values, component=component, entities=self.learning_unit_with_context.entities) self.assertEqual(form.initial, component_values)
def test_post_volume_form_empty_field(self): for component, component_values in self.learning_unit_with_context.components.items(): component_values = VolumeEditionBaseFormset._clean_component_keys(component_values) form = VolumeEditionForm( data=_get_wrong_data_empty_field(), learning_unit_year=self.learning_unit_with_context, initial=component_values, component=component, entities=self.learning_unit_with_context.entities) self.assertFalse(form.is_valid())
def test_post_volume_form_wrong_volume_tot_requirement(self): for component, component_values in self.learning_unit_with_context.components.items(): component_values = VolumeEditionBaseFormset._clean_component_keys(component_values) form = VolumeEditionForm( data=_get_wrong_data_volume_tot(), learning_unit_year=self.learning_unit_with_context, initial=component_values, component=component, entities=self.learning_unit_with_context.entities) self.assertTrue(form.is_valid()) # Accept that vol_tot * cp is not equal to vol_global
def test_post_volume_form_partim_q1(self): for component, component_values in self.learning_unit_with_context.components.items(): component_values = VolumeEditionBaseFormset._clean_component_keys(component_values) form = VolumeEditionForm( data=_get_valid_partim_data_alter(), learning_unit_year=self.learning_unit_with_context, initial=component_values, component=component, entities=self.learning_unit_with_context.entities) self.assertTrue(form.is_valid())
def test_post_volume_form_wrong_volume_total(self): for component, component_values in self.learning_unit_with_context.components.items(): component_values = VolumeEditionBaseFormset._clean_component_keys(component_values) form = VolumeEditionForm( data=_get_wrong_data_volume_tot(), learning_unit_year=self.learning_unit_with_context, initial=component_values, component=component, entities=self.learning_unit_with_context.entities) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['volume_total'][0], _('vol_tot_not_equal_to_q1_q2'))
def test_get_entity_fields(self): for component, component_values in self.learning_unit_with_context.components.items(): component_values = VolumeEditionBaseFormset._clean_component_keys(component_values) form = VolumeEditionForm( data=_get_valid_partim_data_alter(), learning_unit_year=self.learning_unit_with_context, initial=component_values, component=component, entities=self.learning_unit_with_context.entities) actual_entity_fields = form.get_entity_fields() self.assertEqual(len(actual_entity_fields), 3)
def test_post_volume_form_wrong_vol_req_entity(self): for component, component_values in self.learning_unit_with_context.components.items( ): component_values = VolumeEditionBaseFormset._clean_component_keys( component_values) form = VolumeEditionForm( data=_get_wrong_data_vol_req_entity(), learning_unit_year=self.learning_unit_with_context, initial=component_values, component=component, entities=self.learning_unit_with_context.entities) self.assertFalse( form.is_valid() ) # Don't accept that vol_global is not equal to sum of volumes of entities
def test_post_volume_form_wrong_vol_req_entity(self): for component, component_values in self.learning_unit_with_context.components.items(): component_values = VolumeEditionBaseFormset._clean_component_keys(component_values) form = VolumeEditionForm( data=_get_wrong_data_vol_req_entity(), learning_unit_year=self.learning_unit_with_context, initial=component_values, component=component, entities=self.learning_unit_with_context.entities) self.assertFalse(form.is_valid()) error_msg = ' + '.join([self.learning_unit_with_context.entities.get(t).acronym for t in ENTITY_TYPES_VOLUME if self.learning_unit_with_context.entities.get(t)]) error_msg += ' = {}'.format(_('vol_charge')) self.assertEqual(form.errors['volume_total_requirement_entities'][0], error_msg)