def test_with_all_entities_set(self): today = datetime.date.today() entity_1 = EntityFactory(organization=OrganizationFactory(type=organization_type.MAIN)) additional_entity_version_1 = EntityVersionFactory(entity_type=entity_type.SCHOOL, start_date=today.replace(year=1900), end_date=today.replace(year=today.year + 1), entity=entity_1) entity_2 = EntityFactory(organization=OrganizationFactory(type=organization_type.MAIN)) additional_entity_version_2 = EntityVersionFactory(entity_type=entity_type.SCHOOL, start_date=today.replace(year=1900), end_date=today.replace(year=today.year + 1), entity=entity_2) self.form_data["allocation_entity"] = self.entity_version.id self.form_data["additional_entity_1"] = additional_entity_version_1.id self.form_data["additional_entity_2"] = additional_entity_version_2.id form = ProposalBaseForm(self.form_data, self.person, self.learning_unit_year) self.assertTrue(form.is_valid(), form.errors) form.save() self.learning_unit_year.learning_container_year.refresh_from_db() entities_by_type = self.learning_unit_year.learning_container_year.get_map_entity_by_type() expected_entities = { entity_container_year_link_type.REQUIREMENT_ENTITY: self.entity_version.entity, entity_container_year_link_type.ALLOCATION_ENTITY: self.entity_version.entity, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1: additional_entity_version_1.entity, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_2: additional_entity_version_2.entity } self.assertDictEqual(entities_by_type, expected_entities)
def test_when_setting_additional_entity_to_none(self): self.form_data['additional_entity_1'] = None form = ProposalBaseForm(self.form_data, self.person, self.learning_unit_year) self.assertTrue(form.is_valid(), form.errors) form.save() self.learning_unit_year.learning_container_year.refresh_from_db() self.assertIsNone(self.learning_unit_year.learning_container_year.additional_entity_1)
def test_requirement_entity(self): form = ProposalBaseForm(self.form_data, self.person, self.learning_unit_year) self.assertTrue(form.is_valid(), form.errors) form.save() container = self.learning_unit_year.learning_container_year container.refresh_from_db() self.assertEqual(container.requirement_entity, self.entity_version.entity)
def test_learning_container_update(self): form = ProposalBaseForm(self.form_data, self.person, self.learning_unit_year) self.assertTrue(form.is_valid(), form.errors) form.save() learning_unit_year = LearningUnitYear.objects.get(pk=self.learning_unit_year.id) learning_container_year = learning_unit_year.learning_container_year self.assertEqual(learning_unit_year.acronym, self.form_data['acronym_0'] + self.form_data['acronym_1']) self.assertEqual(learning_container_year.common_title, self.form_data['common_title']) self.assertEqual(learning_container_year.common_title_english, self.form_data['common_title_english'])
def test_creation_proposal_learning_unit(self): initial_data_expected = { "learning_container_year": { "id": self.learning_unit_year.learning_container_year.id, "acronym": self.learning_unit_year.acronym, "common_title": self.learning_unit_year.learning_container_year.common_title, "container_type": self.learning_unit_year.learning_container_year.container_type, "in_charge": self.learning_unit_year.learning_container_year.in_charge }, "learning_unit_year": { "id": self.learning_unit_year.id, "acronym": self.learning_unit_year.acronym, "specific_title": self.learning_unit_year.specific_title, "internship_subtype": self.learning_unit_year.internship_subtype, "language": self.learning_unit_year.language.pk, "credits": self.learning_unit_year.credits, "campus": self.learning_unit_year.campus.id, "periodicity": self.learning_unit_year.periodicity, }, "learning_unit": { "id": self.learning_unit_year.learning_unit.id, 'end_year': self.learning_unit_year.learning_unit.end_year }, "entities": { entity_container_year_link_type.REQUIREMENT_ENTITY: self.entity_container_year.entity.id, entity_container_year_link_type.ALLOCATION_ENTITY: None, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1: None, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_2: None } } form = ProposalBaseForm(self.form_data, self.person, self.learning_unit_year) self.assertTrue(form.is_valid(), form.errors) form.save() a_proposal_learning_unt = proposal_learning_unit.find_by_learning_unit_year( self.learning_unit_year) self.assertEqual(a_proposal_learning_unt.type, PROPOSAL_TYPE) self.assertEqual(a_proposal_learning_unt.state, PROPOSAL_STATE) self.assertEqual(a_proposal_learning_unt.author, self.person) self.assertDictEqual(a_proposal_learning_unt.initial_data, initial_data_expected)
def test_creation_proposal_learning_unit(self): self.maxDiff = None form = ProposalBaseForm(self.form_data, self.person, self.learning_unit_year) self.assertTrue(form.is_valid(), form.errors) form.save() a_proposal_learning_unt = proposal_learning_unit.find_by_learning_unit_year(self.learning_unit_year) self.assertEqual(a_proposal_learning_unt.type, PROPOSAL_TYPE) self.assertEqual(a_proposal_learning_unt.state, PROPOSAL_STATE) self.assertEqual(a_proposal_learning_unt.author, self.person) self.assertDictEqual(a_proposal_learning_unt.initial_data, self._get_initial_data_expected())
def test_when_setting_additional_entity_to_none(self): self.form_data['additional_requirement_entity_1-entity'] = None form = ProposalBaseForm(self.form_data, self.person, self.learning_unit_year) self.assertTrue(form.is_valid(), form.errors) form.save() 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 test_learning_unit_year_update(self): form = ProposalBaseForm(self.form_data, self.person, self.learning_unit_year) self.assertTrue(form.is_valid(), form.errors) form.save() learning_unit_year = LearningUnitYear.objects.get(pk=self.learning_unit_year.id) self._assert_acronym_has_changed_in_proposal(learning_unit_year) self._assert_common_titles_stored_in_container(learning_unit_year) self.assertFalse(learning_unit_year.status) self.assertEqual(learning_unit_year.credits, Decimal(self.form_data['credits'])) self.assertEqual(learning_unit_year.quadrimester, self.form_data['quadrimester']) self.assertEqual(learning_unit_year.specific_title, self.form_data["specific_title"]) self.assertEqual(learning_unit_year.specific_title_english, self.form_data["specific_title_english"]) self.assertEqual(learning_unit_year.language, self.language) self.assertEqual(learning_unit_year.campus, self.campus)
def _update_or_create_proposal(request, learning_unit_year, proposal=None): person = get_object_or_404(Person, user=request.user) proposal_base_form = ProposalBaseForm(request.POST or None, person, learning_unit_year, proposal) if request.method == 'POST': if proposal_base_form.is_valid(): proposal = proposal_base_form.save() display_success_messages( request, _("You proposed a modification of type %(type)s for the learning unit %(acronym)s." ) % { 'type': proposal.get_type_display(), 'acronym': learning_unit_year.acronym }) return redirect('learning_unit', learning_unit_year_id=learning_unit_year.id) else: show_error_message_for_form_invalid(request) context = proposal_base_form.get_context() if proposal: return render(request, 'learning_unit/proposal/update_modification.html', context) return render(request, 'learning_unit/proposal/create_modification.html', context)
def test_modify_learning_container_subtype(self): self.learning_unit_year.learning_container_year.container_type = learning_container_year_types.INTERNSHIP self.learning_unit_year.internship_subtype = internship_subtypes.CLINICAL_INTERNSHIP self.learning_unit_year.learning_container_year.save() self.learning_unit_year.save() self.form_data["container_type"] = learning_container_year_types.INTERNSHIP self.form_data["internship_subtype"] = internship_subtypes.TEACHING_INTERNSHIP form = ProposalBaseForm(self.form_data, self.person, self.learning_unit_year) self.assertTrue(form.is_valid(), form.errors) form.save() self.learning_unit_year.refresh_from_db() self.assertEqual(self.learning_unit_year.learning_container_year.container_type, learning_container_year_types.INTERNSHIP) self.assertEqual(self.learning_unit_year.internship_subtype, internship_subtypes.TEACHING_INTERNSHIP)
def test_creation_proposal_learning_unit(self): initial_data_expected = build_initial_data(self.learning_unit_year, self.entity_container_year) form = ProposalBaseForm(self.form_data, self.person, self.learning_unit_year) self.assertTrue(form.is_valid(), form.errors) form.save() a_proposal_learning_unt = proposal_learning_unit.find_by_learning_unit_year( self.learning_unit_year) self.assertEqual(a_proposal_learning_unt.type, PROPOSAL_TYPE) self.assertEqual(a_proposal_learning_unt.state, PROPOSAL_STATE) self.assertEqual(a_proposal_learning_unt.author, self.person) self.assertDictEqual(a_proposal_learning_unt.initial_data, initial_data_expected)
def _update_or_create_proposal(request, learning_unit_year, proposal=None): person = get_object_or_404(Person, user=request.user) proposal_base_form = ProposalBaseForm(request.POST or None, person, learning_unit_year, proposal) if proposal_base_form.is_valid(): proposal = proposal_base_form.save() display_success_messages( request, _("You proposed a modification of type {} for the learning unit {}." ).format(_(proposal.type), learning_unit_year.acronym)) return redirect('learning_unit', learning_unit_year_id=learning_unit_year.id) context = proposal_base_form.get_context() if proposal: return render(request, 'learning_unit/proposal/update_modification.html', context) return render(request, 'learning_unit/proposal/create_modification.html', context)
def test_creation_proposal_learning_unit(self): initial_data_expected = { "learning_container_year": { "id": self.learning_unit_year.learning_container_year.id, "acronym": self.learning_unit_year.acronym, "common_title": self.learning_unit_year.learning_container_year.common_title, "container_type": self.learning_unit_year.learning_container_year.container_type, "in_charge": self.learning_unit_year.learning_container_year.in_charge, "team": self.learning_unit_year.learning_container_year.team, "common_title_english": self.learning_unit_year.learning_container_year. common_title_english, "is_vacant": self.learning_unit_year.learning_container_year.is_vacant, "type_declaration_vacant": self.learning_unit_year.learning_container_year. type_declaration_vacant, }, "learning_unit_year": { "id": self.learning_unit_year.id, "acronym": self.learning_unit_year.acronym, "specific_title": self.learning_unit_year.specific_title, "internship_subtype": self.learning_unit_year.internship_subtype, "language": self.learning_unit_year.language.pk, "credits": self.learning_unit_year.credits, "campus": self.learning_unit_year.campus.id, "periodicity": self.learning_unit_year.periodicity, "status": self.learning_unit_year.status, "session": self.learning_unit_year.session, "quadrimester": self.learning_unit_year.quadrimester, "specific_title_english": self.learning_unit_year.specific_title_english, "professional_integration": self.learning_unit_year.professional_integration, "attribution_procedure": self.learning_unit_year.attribution_procedure, }, "learning_unit": { "id": self.learning_unit_year.learning_unit.id, 'end_year': self.learning_unit_year.learning_unit.end_year, "other_remark": self.learning_unit_year.learning_unit.other_remark, "faculty_remark": self.learning_unit_year.learning_unit.faculty_remark, }, "entities": { entity_container_year_link_type.REQUIREMENT_ENTITY: self.entity_container_year.entity.id, entity_container_year_link_type.ALLOCATION_ENTITY: None, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_1: None, entity_container_year_link_type.ADDITIONAL_REQUIREMENT_ENTITY_2: None }, "learning_component_years": [] } form = ProposalBaseForm(self.form_data, self.person, self.learning_unit_year) self.assertTrue(form.is_valid(), form.errors) form.save() a_proposal_learning_unt = proposal_learning_unit.find_by_learning_unit_year( self.learning_unit_year) self.assertEqual(a_proposal_learning_unt.type, PROPOSAL_TYPE) self.assertEqual(a_proposal_learning_unt.state, PROPOSAL_STATE) self.assertEqual(a_proposal_learning_unt.author, self.person) self.assertDictEqual(a_proposal_learning_unt.initial_data, initial_data_expected)