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)
 def test_training_manager_can_edit_training(self):
     self.client.force_login(self.training_manager.user)
     PersonTrainingFactory(person=self.training_manager,
                           training=self.continuing_education_training)
     url = reverse('formation_edit',
                   args=[self.continuing_education_training.id])
     response = self.client.get(url)
     self.assertEqual(response.status_code, HttpResponseBase.status_code)
     self.assertTemplateUsed(response, 'formation_form.html')
 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_context_trainer_manager_contents(self):
     training_manager_person_training = PersonTrainingFactory(
         person=self.training_manager,
         training=self.continuing_education_training)
     self.client.force_login(self.training_manager.user)
     response = self.client.get(reverse('formation'))
     self.assertEqual(response.status_code, 200)
     self.assertTrue(
         response.context['continuing_education_training_manager'])
     self.assertCountEqual(response.context['trainings_managing'],
                           [training_manager_person_training.training.id])
    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))
    def setUpTestData(cls):
        academic_year = AcademicYearFactory()
        academic_year_next = AcademicYearFactory(year=academic_year.year + 1)
        cls.ed = EducationGroupFactory()
        cls.education_group_year = EducationGroupYearFactory(
            education_group=cls.ed, academic_year=academic_year)
        cls.education_group_year_next_year = EducationGroupYearFactory(
            education_group=cls.ed, academic_year=academic_year_next)
        cls.active_formation = ContinuingEducationTrainingFactory(
            education_group=cls.ed, active=True)
        cls.person_training = PersonTrainingFactory(
            training=cls.active_formation)

        ed2 = EducationGroupFactory()
        EducationGroupYearFactory(education_group=ed2)
        cls.formation_not_managed = ContinuingEducationTrainingFactory(
            education_group=ed2)
    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
            },
        ])