Ejemplo n.º 1
0
    def setUpTestData(cls):
        group_training_manager = GroupFactory(name=TRAINING_MANAGERS_GROUP)
        cls.training_manager = PersonFactory()
        cls.training_manager.user.groups.add(group_training_manager)

        group_manager = GroupFactory(name=MANAGERS_GROUP)
        cls.manager = PersonFactory()
        cls.manager.user.groups.add(group_manager)

        group_student_worker = GroupFactory(name=STUDENT_WORKERS_GROUP)
        cls.student_worker = PersonFactory()
        cls.student_worker.user.groups.add(group_student_worker)
Ejemplo n.º 2
0
 def setUpTestData(cls):
     participant = PersonFactory()
     person_information = ContinuingEducationPersonFactory(
         person=participant)
     cls.admission = AdmissionFactory(person_information=person_information)
     cls.participant_file = AdmissionFileFactory(uploaded_by=participant)
     cls.manager = PersonFactory()
     cls.manager_file = AdmissionFileFactory(uploaded_by=cls.manager)
     other_manager = PersonFactory()
     cls.other_manager_file = AdmissionFileFactory(
         uploaded_by=other_manager)
     cls.context = {'user': cls.manager.user, 'admission': cls.admission}
    def test_get_managers_mail_mail_missing(self):
        ed = EducationGroupFactory()
        EducationGroupYearFactory(education_group=ed)
        manager = PersonFactory(last_name="AAA", email="")
        manager_2 = PersonFactory(last_name="BBB", email="")
        cet = ContinuingEducationTrainingFactory(education_group=ed)
        PersonTrainingFactory(person=manager, training=cet)
        PersonTrainingFactory(person=manager_2, training=cet)
        admission = AdmissionFactory(formation=cet)
        expected_mails = "{}".format(manager_2.email)

        self.assertEqual(_get_managers_mails(admission.formation),
                         expected_mails)
Ejemplo n.º 4
0
 def setUpTestData(cls):
     cls.permission = HasAdmissionAccess()
     cls.user = UserFactory()
     person_information = ContinuingEducationPersonFactory(
         person=PersonFactory(user=cls.user)
     )
     cls.admission = AdmissionFactory(person_information=person_information)
Ejemplo n.º 5
0
    def setUp(self):
        GroupFactory(name='continuing_education_managers')
        self.citizenship = CountryFactory()
        self.user = UserFactory()
        self.academic_year = AcademicYearFactory(year=2018)
        education_group = EducationGroupFactory()
        EducationGroupYearFactory(
            education_group=education_group,
            academic_year=self.academic_year
        )

        self.admission = AdmissionFactory(
            citizenship=self.citizenship,
            person_information=ContinuingEducationPersonFactory(person=PersonFactory(user=self.user)),
            formation=ContinuingEducationTrainingFactory(education_group=education_group),
            state=DRAFT
        )

        self.url = reverse('continuing_education_api_v1:admission-detail-update', kwargs={'uuid': self.admission.uuid})
        self.invalid_url = reverse(
            'continuing_education_api_v1:admission-detail-update',
            kwargs={'uuid':  uuid.uuid4()}
        )

        self.client.force_authenticate(user=self.user)
Ejemplo n.º 6
0
    def test_create_valid_admission_with_new_person_and_person_info(self):
        self.assertEqual(3, Admission.admission_objects.all().count())
        self.assertEqual(1, ContinuingEducationPerson.objects.all().count())
        self.assertEqual(1, Person.objects.all().count())

        p = PersonFactory(email='*****@*****.**')
        ContinuingEducationPersonFactory(person=p)
        data = {
            'person_information': {
                'birth_date': datetime.date.today(),
                'birth_country':  'NL',
                'birth_location': 'Turlututu',
                'person': {
                    'first_name': 'Benjamin',
                    'last_name': 'Dau',
                    'gender': 'M',
                    'email': '*****@*****.**'
                },
            },
            'email': '*****@*****.**',
            'formation': self.formation.uuid
        }

        response = self.client.post(self.url, data=data, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(4, Admission.admission_objects.all().count())
        self.assertEqual(2, ContinuingEducationPerson.objects.all().count())
        self.assertEqual(2, Person.objects.all().count())
Ejemplo n.º 7
0
    def test_get_managers_mail(self):
        ed = EducationGroupFactory()
        EducationGroupYearFactory(education_group=ed,
                                  academic_year=create_current_academic_year())
        manager = PersonFactory(last_name="AAA")
        manager_2 = PersonFactory(last_name="BBB")
        cet = ContinuingEducationTrainingFactory(education_group=ed)
        ContinuingEducationTrainingManagerFactory(person=manager, training=cet)
        ContinuingEducationTrainingManagerFactory(person=manager_2,
                                                  training=cet)
        admission = AdmissionFactory(formation=cet)
        expected_mails = "{}{}{}".format(manager.email, _(" or "),
                                         manager_2.email)

        self.assertEqual(_get_managers_mails(admission.formation),
                         expected_mails)
Ejemplo n.º 8
0
    def test_assign_manager_to_training(self):
        employee = PersonFactory(employee=True)
        self.assertEqual(
            ContinuingEducationTrainingManager.objects.filter(
                training=self.formation).count(), 1)
        data = {'training': self.formation.pk, 'person': employee.pk}
        response = self.client.post(
            reverse('add_continuing_education_training_manager'), data=data)
        self.assertEqual(
            ContinuingEducationTrainingManager.objects.filter(
                training=self.formation).count(), 2)
        self.assertEqual(response.status_code,
                         HttpResponseRedirect.status_code)

        messages_list = list(messages.get_messages(response.wsgi_request))
        success_msg = gettext(
            'Successfully assigned %(manager)s to the training %(training)s'
        ) % {
            "manager": employee,
            "training": self.formation.acronym
        }
        self.assertIn(success_msg, str(messages_list[0]))
        self.assertEqual(
            list(employee.user.groups.values_list('name', flat=True)),
            [self.training_manager.group_name])
    def setUpTestData(cls):
        cls.birth_country = CountryFactory()
        fr = CountryFactory(iso_code='FR')

        cls.user = UserFactory()
        p = PersonFactory(user=cls.user)
        cls.person = ContinuingEducationPersonFactory(
            person=p, birth_country=cls.birth_country)
        cls.url = reverse('continuing_education_api_v1:person-detail')
    def setUpTestData(cls):
        cls.user = UserFactory()
        cls.url = reverse('continuing_education_api_v1:person-list-create')

        cls.birth_country = CountryFactory()
        cls.country = CountryFactory(iso_code='FR')
        cls.person = PersonFactory()
        for x in range(3):
            ContinuingEducationPersonFactory(birth_country=cls.birth_country)
 def setUpTestData(cls):
     ed = EducationGroupFactory()
     EducationGroupYearFactory(education_group=ed)
     cls.manager = PersonFactory(last_name="AAA")
     cls.manager.user.groups.add(
         GroupFactory(name=CONTINUING_EDUCATION_MANAGERS_GROUP))
     cls.cet = ContinuingEducationTrainingFactory(education_group=ed)
     PersonTrainingFactory(person=cls.manager, training=cls.cet)
     cls.admission = AdmissionFactory(formation=cls.cet)
    def setUp(self):
        ed = EducationGroupFactory()
        EducationGroupYearFactory(education_group=ed)
        self.manager = PersonFactory(last_name="AAA")
        self.manager.user.groups.add(GroupFactory(name=MANAGERS_GROUP))
        cet = ContinuingEducationTrainingFactory(education_group=ed)
        PersonTrainingFactory(person=self.manager, training=cet)
        PersonTrainingFactory(person=PersonFactory(last_name="BBB"),
                              training=cet)
        self.admission = AdmissionFactory(formation=cet)
        uploaded_file = SimpleUploadedFile(name='upload_test.pdf',
                                           content=str.encode('content'),
                                           content_type="application/pdf")

        self.admission_file = AdmissionFileFactory(
            admission=self.admission,
            path=uploaded_file,
        )
 def test_add_employee_to_training_managers_group(self):
     employee = PersonFactory(employee=True)
     self.assertEqual(list(employee.user.groups.all()), [])
     data = {
         'training': self.formation.pk,
         'person': employee.pk
     }
     response = self.client.post(reverse('list_managers'), data=data)
     self.assertEqual(list(employee.user.groups.all()), [self.training_manager_group])
     self.assertEqual(response.status_code, HttpResponse.status_code)
Ejemplo n.º 14
0
 def test_add_employee_to_training_managers_group(self):
     employee = PersonFactory(employee=True)
     self.assertEqual(list(employee.user.groups.all()), [])
     data = {'training': self.formation.pk, 'person': employee.pk}
     response = self.client.post(
         reverse('add_continuing_education_training_manager'), data=data)
     self.assertEqual(
         list(employee.user.groups.values_list('name', flat=True)),
         [self.training_manager.group_name])
     self.assertEqual(response.status_code,
                      HttpResponseRedirect.status_code)
    def test_formation_administrators(self):
        academic_year = AcademicYearFactory(year=2018)
        EducationGroupYearFactory(
            education_group=self.education_group,
            academic_year=academic_year,
        )
        a_training = ContinuingEducationTraining(
            education_group=self.education_group)
        a_training.save()
        person_1 = PersonFactory(first_name="Louis", last_name="Lesquoy")
        person_2 = PersonFactory(first_name="Arnaud", last_name="Jadoulle")

        PersonTrainingFactory(person=person_1, training=a_training)
        PersonTrainingFactory(person=person_2, training=a_training)

        self.assertEqual(
            a_training.formation_administrators,
            "{}, {} - {}, {}".format(person_2.last_name.upper(),
                                     person_2.first_name,
                                     person_1.last_name.upper(),
                                     person_1.first_name))
Ejemplo n.º 16
0
 def setUpTestData(cls):
     cls.user = UserFactory()
     cls.url = reverse(
         'continuing_education_api_v1:continuing-education-training-list-create'
     )
     cls.academic_year = AcademicYearFactory(year=2018)
     cls.education_group = EducationGroupFactory()
     EducationGroupYearFactory(education_group=cls.education_group,
                               academic_year=cls.academic_year)
     cls.continuing_education_training = ContinuingEducationTrainingFactory(
         education_group=cls.education_group)
     cls.training_manager = PersonFactory()
     PersonTraining(person=cls.training_manager,
                    training=cls.continuing_education_training).save()
 def test_manager_person_with_no_user(self):
     employee = PersonFactory(employee=True, user=None)
     self.assertEqual(PersonTraining.objects.count(), 0)
     data = {
         'training': self.formation.pk,
         'person': employee.pk
     }
     response = self.client.post(reverse('list_managers'), data)
     self.assertEqual(response.status_code, HttpResponse.status_code)
     self.assertEqual(PersonTraining.objects.count(), 0)
     messages_list = list(messages.get_messages(response.wsgi_request))
     self.assertIn(
         gettext("Manager person has no user"),
         str(messages_list[0])
     )
Ejemplo n.º 18
0
    def setUp(self):
        ed = EducationGroupFactory()
        EducationGroupYearFactory(education_group=ed,
                                  academic_year=create_current_academic_year())
        cet = ContinuingEducationTrainingFactory(education_group=ed)
        self.manager = ContinuingEducationTrainingManagerFactory(training=cet)
        self.other_manager = ContinuingEducationTrainingManagerFactory(
            person=PersonFactory(last_name="BBB"), training=cet)
        self.admission = AdmissionFactory(formation=cet)
        uploaded_file = SimpleUploadedFile(name='upload_test.pdf',
                                           content=str.encode('content'),
                                           content_type="application/pdf")

        self.admission_file = AdmissionFileFactory(
            admission=self.admission,
            path=uploaded_file,
        )
Ejemplo n.º 19
0
 def test_manager_person_with_no_user(self):
     employee = PersonFactory(employee=True, user=None)
     training = ContinuingEducationTrainingFactory()
     self.assertEqual(
         ContinuingEducationTrainingManager.objects.filter(
             training=training).count(), 0)
     data = {'training': self.formation.pk, 'person': employee.pk}
     response = self.client.post(
         reverse('add_continuing_education_training_manager'), data)
     self.assertEqual(response.status_code,
                      HttpResponseRedirect.status_code)
     self.assertEqual(
         ContinuingEducationTrainingManager.objects.filter(
             training=training).count(), 0)
     messages_list = list(messages.get_messages(response.wsgi_request))
     self.assertIn(gettext("Manager person has no user"),
                   str(messages_list[0]))
Ejemplo n.º 20
0
    def test_send_email_email_missing(self, mock_send_mail):
        self.manager_without_email = ContinuingEducationTrainingManagerFactory(
            person=PersonFactory(last_name="AAA", email=""), training=self.cet)

        self.cet.send_notification_emails = True
        self.cet.save()

        admission.send_submission_email_to_admission_managers(
            self.admission, None)
        receivers = mock_send_mail.call_args[1].get('receivers')

        self.assertCountEqual(receivers, [
            {
                'receiver_person_id': self.manager.person.id,
                'receiver_email': self.manager.person.email,
                'receiver_lang': self.manager.person.language
            },
        ])
    def test_assign_manager_to_training(self):
        employee = PersonFactory(employee=True)
        self.assertEqual(PersonTraining.objects.count(), 0)
        data = {
            'training': self.formation.pk,
            'person': employee.pk
        }
        response = self.client.post(reverse('list_managers'), data=data)
        self.assertEqual(PersonTraining.objects.count(), 1)
        self.assertEqual(response.status_code, HttpResponse.status_code)

        messages_list = list(messages.get_messages(response.wsgi_request))
        success_msg = gettext('Successfully assigned %(manager)s to the training %(training)s') % {
            "manager": employee,
            "training": self.formation.acronym
        }
        self.assertIn(success_msg, str(messages_list[0]))
        self.assertEqual(list(employee.user.groups.all()), [self.training_manager_group])
 def test_create_valid_person_with_new_user(self):
     self.assertEqual(3, ContinuingEducationPerson.objects.all().count())
     self.assertEqual(4, Person.objects.all().count())
     PersonFactory(email="*****@*****.**")
     data = {
         "person": {
             'first_name': "Ben",
             'last_name': "Total",
             'gender': "H",
             'email': "*****@*****.**"
         },
         'birth_date': datetime.date.today(),
         'birth_location': 'Hilo',
         'birth_country': 'FR',
     }
     response = self.client.post(self.url, data=data, format='json')
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     self.assertEqual(4, ContinuingEducationPerson.objects.all().count())
     self.assertEqual(5, Person.objects.all().count())
Ejemplo n.º 23
0
    def setUpTestData(cls):
        cls.academic_year = create_current_academic_year()
        cls.education_group = EducationGroupFactory()
        EducationGroupYearFactory(education_group=cls.education_group,
                                  academic_year=cls.academic_year)
        cls.formation = ContinuingEducationTrainingFactory(
            education_group=cls.education_group)
        group = GroupFactory(name=STUDENT_WORKERS_GROUP)
        cls.student_worker = PersonFactory()
        cls.student_worker.user.groups.add(group)

        cls.admission_diploma_to_produce = AdmissionFactory(
            formation=cls.formation,
            state=VALIDATED,
        )
        cls.registration_to_validate = AdmissionFactory(
            formation=cls.formation,
            state=REGISTRATION_SUBMITTED,
        )
    def setUpTestData(cls):
        GroupFactory(name='continuing_education_managers')
        cls.academic_year = create_current_academic_year()
        cls.education_group = EducationGroupFactory()
        cls.user = UserFactory()
        EducationGroupYearFactory(education_group=cls.education_group,
                                  academic_year=cls.academic_year)
        cls.admission = AdmissionFactory(
            person_information=ContinuingEducationPersonFactory(
                person=PersonFactory(user=cls.user)),
            formation=ContinuingEducationTrainingFactory(
                education_group=cls.education_group),
            state=random.choice([ACCEPTED, REGISTRATION_SUBMITTED, VALIDATED]))

        cls.url = reverse(
            'continuing_education_api_v1:registration-detail-update',
            kwargs={'uuid': cls.admission.uuid})
        cls.invalid_url = reverse(
            'continuing_education_api_v1:registration-detail-update',
            kwargs={'uuid': uuid.uuid4()})
    def test_send_email_email_missing(self, mock_send_mail):
        self.manager_without_email = PersonFactory(last_name="AAA", email="")
        self.manager_without_email.user.groups.add(
            GroupFactory(name=CONTINUING_EDUCATION_MANAGERS_GROUP))
        PersonTrainingFactory(person=self.manager_without_email,
                              training=self.cet)

        self.cet.send_notification_emails = True
        self.cet.save()

        admission.send_submission_email_to_admission_managers(
            self.admission, None)
        receivers = mock_send_mail.call_args[1].get('receivers')

        self.assertCountEqual(receivers, [
            {
                'receiver_person_id': self.manager.id,
                'receiver_email': self.manager.email,
                'receiver_lang': self.manager.language
            },
        ])
 def test_admission_ordering(self):
     ed = EducationGroupFactory()
     EducationGroupYearFactory(education_group=ed,
                               academic_year=self.academic_year,
                               acronym='M')
     cet = ContinuingEducationTrainingFactory(education_group=ed)
     ed_next = EducationGroupFactory()
     EducationGroupYearFactory(education_group=ed_next,
                               academic_year=self.academic_year,
                               acronym='O')
     cet_next = ContinuingEducationTrainingFactory(education_group=ed_next)
     persons_data = [('A', 'I', cet), ('D', 'J', cet), ('C', 'J', cet),
                     ('B', 'I', cet), ('E', 'K', cet_next),
                     ('H', 'L', cet_next), ('G', 'L', cet_next),
                     ('F', 'K', cet_next)]
     for first_name, name, formation in persons_data:
         a_person = ContinuingEducationPersonFactory(
             person=PersonFactory(first_name=first_name, last_name=name))
         AdmissionFactory(person_information=a_person, formation=formation)
     expected_order = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
     result = Admission.objects.all().values_list(
         'person_information__person__first_name', flat=True)
     self.assertEqual(list(result), expected_order)
Ejemplo n.º 27
0
    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()
Ejemplo n.º 28
0
 def test_process_admissions_denied(self):
     person = PersonFactory()
     self.client.force_login(person.user)
     response = self.client.post(reverse('process_admissions'), data={})
     self.assertEqual(response.status_code,
                      HttpResponseForbidden.status_code)