def test_get_admissions_by_free_text_country(self): admission_accent = self._build_admission_with_accent(SUBMITTED, False) country_free_text = "Country - e" form = AdmissionFilterForm({"free_text": country_free_text}) form.is_valid() results = form.get_admissions() self.assertEqual(results.first(), admission_accent)
def test_get_admission_by_states(self): form = AdmissionFilterForm({"state": [REJECTED, DRAFT]}) self.assertTrue(form.is_valid()) results = form.get_admissions() self.assertCountEqual(results, [ self.admissions_fac_1_version[1], self.admissions_fac_1_version[3] ])
def test_generate_xls_data_with_an_admission(self): a_form = AdmissionFilterForm({"faculty": self.entity_version.id}) self.assertTrue(a_form.is_valid()) found_admissions = a_form.get_admissions() create_xls(self.user, found_admissions, None) xls_data = [[ self.admission.person_information.person.first_name, self.admission.person_information.person.last_name, self.admission.email, self.admission.formation, self.entity_version.entity, _(SUBMITTED) ]] expected_argument = _generate_xls_build_parameter(xls_data, self.user) self.assertEqual(expected_argument['list_description'], _('Admissions list')) self.assertEqual(expected_argument['filename'], _('Admissions_list')) self.assertEqual(expected_argument['username'], self.user.username) self.assertEqual(expected_argument['data'][0]['content'], xls_data) self.assertEqual(expected_argument['data'][0]['header_titles'], get_titles_admission()) self.assertEqual(expected_argument['data'][0]['worksheet_title'], _('Admissions list'))
def test_get_admission_by_no_registration_required(self): admission = AdmissionFactory( formation=self.formation_no_registration_required, state=ACCEPTED_NO_REGISTRATION_REQUIRED) form = AdmissionFilterForm({"registration_required": False}) self.assertTrue(form.is_valid()) results = form.get_admissions() self.assertCountEqual(results, [admission])
def test_get_admission_by_registration_required(self): formations_registration_required = ContinuingEducationTraining.objects.filter( registration_required=True) admissions_expected = Admission.objects.filter( archived=False, formation__in=formations_registration_required, state__in=[ele for key in ADMISSION_STATE_CHOICES for ele in key]) form = AdmissionFilterForm({"registration_required": True}) self.assertTrue(form.is_valid()) results = form.get_admissions() self.assertCountEqual(results, admissions_expected)
def test_get_admissions_by_faculty_criteria_get_child_too(self): an_admission_submitted_1 = AdmissionFactory( formation=ContinuingEducationTrainingFactory( education_group=self.education_group_on_faculty), state=SUBMITTED) an_admission_submitted_2 = AdmissionFactory( formation=ContinuingEducationTrainingFactory( education_group=self.education_group_on_faculty_child), state=SUBMITTED) form = AdmissionFilterForm( {"faculty": self.fac_3_version_with_child.id}) self.assertTrue(form.is_valid()) results = form.get_admissions() self.assertCountEqual( results, [an_admission_submitted_1, an_admission_submitted_2])
def list_admissions(request): search_form = AdmissionFilterForm(request.GET) admission_list = [] if search_form.is_valid(): admission_list = search_form.get_admissions() admission_list = filter_authorized_admissions(request.user, admission_list) if request.GET.get('xls_status') == "xls_admissions": return create_xls(request.user, admission_list, search_form) return render(request, "admissions.html", { 'admissions': get_object_list(request, admission_list), 'admissions_number': len(admission_list), 'search_form': search_form, })
def list_admissions(request): search_form = AdmissionFilterForm(request.GET) if search_form.is_valid(): admission_list = search_form.get_admissions() admission_list = filter_authorized_admissions(request.user, admission_list) else: admission_list = Admission.objects.none() if request.GET.get('xls_status') == "xls_admissions": return export_admissions(request, admission_list, search_form) return render( request, "admissions.html", { 'admissions': get_object_list(request, admission_list), 'admissions_number': admission_list.count(), 'search_form': search_form, })
def test_get_admissions_by_faculty_and_formation_criteria(self): form = AdmissionFilterForm({ "faculty": self.fac_1_version.id, "formation": self.admissions_fac_1_version[0].formation.id }) self.assertTrue(form.is_valid()) results = form.get_admissions() self.assertCountEqual(results, [self.admissions_fac_1_version[0]]) formation_other = ContinuingEducationTrainingFactory() formation_other.save() adm = AdmissionFactory(state=random.choice(STATE_TO_DISPLAY)) form = AdmissionFilterForm({ "faculty": self.fac_1_version.id, "formation": adm.formation.id }) self.assertTrue(form.is_valid()) results = form.get_admissions() self.assertCountEqual(results, [])
def setUpTestData(cls): cls.current_academic_yr = create_current_academic_year() cls.next_academic_yr = AcademicYearFactory( year=cls.current_academic_yr.year + 1) cls.start_date = date.today().replace(year=2010) cls.fac_1_older_version = EntityVersionFactory( acronym="DRT", entity_type=FACULTY, start_date=date.today().replace(year=2000), end_date=cls.start_date - timezone.timedelta(days=1)) cls.fac_1_version = EntityVersionFactory( acronym="DRT_NEW", entity_type=FACULTY, start_date=cls.start_date, end_date=None, ) cls.fac_2_version = EntityVersionFactory( acronym="AGRO", entity_type=FACULTY, start_date=cls.start_date, end_date=None, ) cls.fac_3_version_with_child = EntityVersionFactory( acronym="ESPO", entity_type=FACULTY, end_date=None, start_date=cls.start_date) cls.fac_3_child_version = EntityVersionFactory( acronym="ESPO_child", entity_type=SCHOOL, end_date=None, start_date=cls.start_date, parent=cls.fac_3_version_with_child.entity) cls.fac_4_version = EntityVersionFactory( acronym="ILV", entity_type=FACULTY, start_date=cls.start_date, end_date=None, ) letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'] cls.education_groups_fac_1_version = [ EducationGroupFactory(start_year=cls.current_academic_yr) for _ in range(0, len(letters)) ] cls.education_group_yrs = [ EducationGroupYearFactory( academic_year=cls.next_academic_yr, acronym='{}_FORM'.format(letters[index]), management_entity=cls.fac_1_version.entity, education_group=education_group) for index, education_group in enumerate(cls.education_groups_fac_1_version) ] cls.education_group_on_faculty = EducationGroupFactory( start_year=cls.current_academic_yr) cls.education_group_yr_on_faculty = EducationGroupYearFactory( academic_year=cls.next_academic_yr, acronym='E_FORM_FAC', management_entity=cls.fac_3_version_with_child.entity, education_group=cls.education_group_on_faculty) cls.education_group_on_faculty_child = EducationGroupFactory( start_year=cls.current_academic_yr) cls.education_group_yr_on_faculty_child = EducationGroupYearFactory( academic_year=cls.next_academic_yr, acronym='E_FORM_Child', management_entity=cls.fac_3_child_version.entity, education_group=cls.education_group_on_faculty_child) cls.admissions_fac_1_version = [ AdmissionFactory(formation=ContinuingEducationTrainingFactory( education_group=cls.education_groups_fac_1_version[index]), state=state, academic_year=cls.current_academic_yr) for index, state in enumerate( [SUBMITTED, REJECTED, WAITING, DRAFT, SUBMITTED]) ] cls.registrations = [ AdmissionFactory(formation=ContinuingEducationTrainingFactory( education_group=cls.education_groups_fac_1_version[ len(cls.admissions_fac_1_version) + index], ), state=state, ucl_registration_complete=index == 0, payment_complete=index != 0, academic_year=cls.current_academic_yr) for index, state in enumerate([ACCEPTED, REGISTRATION_SUBMITTED]) ] cls.education_group_on_fac4 = EducationGroupFactory( start_year=cls.current_academic_yr) cls.education_group_yr_on_faculty_child = EducationGroupYearFactory( academic_year=cls.next_academic_yr, acronym='E_FORM_fac_Child', management_entity=cls.fac_4_version.entity, education_group=cls.education_group_on_fac4) cls.registration_validated = AdmissionFactory( formation=ContinuingEducationTrainingFactory( education_group=cls.education_group_on_fac4), state=VALIDATED, payment_complete=False, ucl_registration_complete=False, academic_year=cls.current_academic_yr) cls.all_registrations_expected = cls.registrations.copy() cls.all_registrations_expected.append(cls.registration_validated) cls.archived_submitted = AdmissionFactory( formation=ContinuingEducationTrainingFactory( education_group=cls.education_groups_fac_1_version[7], ), state=SUBMITTED, archived=True, academic_year=cls.current_academic_yr) ed_free_text_acronym = EducationGroupFactory( start_year=cls.current_academic_yr) EducationGroupYearFactory(acronym="TestText", academic_year=cls.next_academic_yr, education_group=ed_free_text_acronym) ed_free_text_title = EducationGroupFactory( start_year=cls.current_academic_yr) EducationGroupYearFactory(academic_year=cls.next_academic_yr, education_group=ed_free_text_title, title="bla TestText bla") ed = EducationGroupFactory(start_year=cls.current_academic_yr) EducationGroupYearFactory(academic_year=cls.next_academic_yr, education_group=ed) cls.formation_no_registration_required = ContinuingEducationTrainingFactory( education_group=ed, registration_required=False, ) cls.persons = [ PersonFactory(first_name="TestText"), PersonFactory(last_name="TestText"), PersonFactory(email="*****@*****.**") ] cls.eds = [ed_free_text_title, ed_free_text_acronym] cls.admissions_free_text = [] cls.country_accent = CountryFactory(name=COUNTRY_NAME_WITH_ACCENT) cls.country_without_accent = CountryFactory( name=COUNTRY_NAME_WITHOUT_ACCENT) cls.form = AdmissionFilterForm() cls.registration_form = RegistrationFilterForm()
def test_get_admissions_by_free_text(self): self._create_admissions_for_free_text_search() form = AdmissionFilterForm({"free_text": "testtext"}) self.assertTrue(form.is_valid()) results = form.get_admissions() self.assertCountEqual(results, self.admissions_free_text)
def test_get_admissions_by_faculty_criteria(self): form = AdmissionFilterForm({"faculty": self.fac_1_version.id}) self.assertTrue(form.is_valid()) results = form.get_admissions() self.assertCountEqual(results, self.admissions_fac_1_version)
def test_get_admissions_by_formation_criteria(self): form = AdmissionFilterForm( {"formation": self.admissions_fac_1_version[4].formation.id}) self.assertTrue(form.is_valid()) results = form.get_admissions() self.assertListEqual(list(results), [self.admissions_fac_1_version[4]])