def test_accept_trigger_manual_approval(self): job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( state=JobApplicationWorkflow.STATE_ACCEPTED, hiring_start_at=datetime.date.today(), ) accepted_by = job_application.to_siae.members.first() email = job_application.email_accept_trigger_manual_approval(accepted_by) # To. self.assertIn(settings.ITOU_EMAIL_CONTACT, email.to) self.assertEqual(len(email.to), 1) # Body. self.assertIn(job_application.job_seeker.first_name, email.body) self.assertIn(job_application.job_seeker.last_name, email.body) self.assertIn(job_application.job_seeker.email, email.body) self.assertIn( job_application.job_seeker.birthdate.strftime("%d/%m/%Y"), email.body ) self.assertIn(job_application.to_siae.siret, email.body) self.assertIn(job_application.to_siae.kind, email.body) self.assertIn(job_application.to_siae.get_kind_display(), email.body) self.assertIn(job_application.to_siae.get_department_display(), email.body) self.assertIn(job_application.to_siae.display_name, email.body) self.assertIn(job_application.hiring_start_at.strftime("%d/%m/%Y"), email.body) self.assertIn(job_application.hiring_end_at.strftime("%d/%m/%Y"), email.body) self.assertIn(accepted_by.get_full_name(), email.body) self.assertIn(accepted_by.email, email.body) self.assertIn( reverse( "admin:approvals_approval_manually_add_approval", args=[job_application.pk], ), email.body, )
def test_archive(self, *args, **kwargs): """Ensure that when an SIAE archives a job_application, the hidden_for_siae flag is updated.""" job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( state=JobApplicationWorkflow.STATE_CANCELLED ) self.assertTrue(job_application.state.is_cancelled) siae_user = job_application.to_siae.members.first() self.client.login(username=siae_user.email, password=DEFAULT_PASSWORD) url = reverse("apply:archive", kwargs={"job_application_id": job_application.pk}) cancelled_states = [ JobApplicationWorkflow.STATE_REFUSED, JobApplicationWorkflow.STATE_CANCELLED, JobApplicationWorkflow.STATE_OBSOLETE, ] response = self.client.post(url) args = {"states": [c for c in cancelled_states]} qs = urlencode(args, doseq=True) url = reverse("apply:list_for_siae") next_url = f"{url}?{qs}" self.assertRedirects(response, next_url) job_application.refresh_from_db() self.assertTrue(job_application.hidden_for_siae)
def test_accepted_by(self): job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( state=JobApplicationWorkflow.STATE_PROCESSING ) user = job_application.to_siae.members.first() job_application.accept(user=user) self.assertEqual(job_application.accepted_by, user)
def test_email_approval_number(self): job_seeker = JobSeekerFactory() approval = ApprovalFactory(user=job_seeker) job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( job_seeker=job_seeker, state=JobApplicationWorkflow.STATE_ACCEPTED, approval=approval, ) accepted_by = job_application.to_siae.members.first() email = job_application.email_approval_number(accepted_by) # To. self.assertIn(accepted_by.email, email.to) self.assertEqual(len(email.to), 1) # Body. self.assertIn(approval.user.get_full_name(), email.subject) self.assertIn(approval.number_with_spaces, email.body) self.assertIn(approval.user.last_name, email.body) self.assertIn(approval.user.first_name, email.body) self.assertIn(approval.user.birthdate.strftime("%d/%m/%Y"), email.body) self.assertIn(job_application.hiring_start_at.strftime("%d/%m/%Y"), email.body) self.assertIn(job_application.hiring_end_at.strftime("%d/%m/%Y"), email.body) self.assertIn(job_application.to_siae.display_name, email.body) self.assertIn(job_application.to_siae.get_kind_display(), email.body) self.assertIn(job_application.to_siae.address_line_1, email.body) self.assertIn(job_application.to_siae.address_line_2, email.body) self.assertIn(job_application.to_siae.post_code, email.body) self.assertIn(job_application.to_siae.city, email.body) self.assertIn(settings.ITOU_EMAIL_CONTACT, email.body)
def test_accept_job_application_sent_by_authorized_prescriber_with_approval_in_waiting_period( self ): user = JobSeekerFactory() # Ended 1 year ago. end_at = datetime.date.today() - relativedelta(years=1) start_at = end_at - relativedelta(years=2) approval = PoleEmploiApprovalFactory( pole_emploi_id=user.pole_emploi_id, birthdate=user.birthdate, start_at=start_at, end_at=end_at, ) self.assertTrue(approval.is_in_waiting_period) job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( job_seeker=user, state=JobApplicationWorkflow.STATE_PROCESSING ) # A valid Pôle emploi ID should trigger an automatic approval delivery. self.assertNotEqual(job_application.job_seeker.pole_emploi_id, "") job_application.accept(user=job_application.to_siae.members.first()) self.assertIsNotNone(job_application.approval) self.assertTrue(job_application.approval_number_sent_by_email) self.assertEqual( job_application.approval_delivery_mode, job_application.APPROVAL_DELIVERY_MODE_AUTOMATIC, ) # Check sent email. self.assertEqual(len(mail.outbox), 2) self.assertIn("Candidature acceptée", mail.outbox[0].subject) self.assertIn("Délivrance d'un PASS IAE pour", mail.outbox[1].subject)
def test_accept_for_siae_not_subject_to_eligibility_rules(self): job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( state=JobApplicationWorkflow.STATE_PROCESSING, to_siae__kind=Siae.KIND_GEIQ ) job_application.accept(user=job_application.to_siae.members.first()) # Check sent email. self.assertEqual(len(mail.outbox), 1) self.assertIn("Candidature acceptée", mail.outbox[0].subject)
def test_eligibility(self, *args, **kwargs): """Test eligibility.""" job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( state=JobApplicationWorkflow.STATE_PROCESSING ) self.assertTrue(job_application.state.is_processing) siae_user = job_application.to_siae.members.first() self.client.login(username=siae_user.email, password=DEFAULT_PASSWORD) has_considered_valid_diagnoses = EligibilityDiagnosis.objects.has_considered_valid( job_application.job_seeker, for_siae=job_application.to_siae ) self.assertFalse(has_considered_valid_diagnoses) criterion1 = AdministrativeCriteria.objects.level1().get(pk=1) criterion2 = AdministrativeCriteria.objects.level2().get(pk=5) criterion3 = AdministrativeCriteria.objects.level2().get(pk=15) url = reverse("apply:eligibility", kwargs={"job_application_id": job_application.pk}) response = self.client.get(url) self.assertEqual(response.status_code, 200) # Ensure that a manual confirmation is mandatory. post_data = {"confirm": "false"} response = self.client.post(url, data=post_data) self.assertEqual(response.status_code, 200) post_data = { # Administrative criteria level 1. f"{AdministrativeCriteriaForm.LEVEL_1_PREFIX}{criterion1.pk}": "true", # Administrative criteria level 2. f"{AdministrativeCriteriaForm.LEVEL_2_PREFIX}{criterion2.pk}": "true", f"{AdministrativeCriteriaForm.LEVEL_2_PREFIX}{criterion3.pk}": "true", # Confirm. "confirm": "true", } response = self.client.post(url, data=post_data) next_url = reverse("apply:details_for_siae", kwargs={"job_application_id": job_application.pk}) self.assertRedirects(response, next_url) has_considered_valid_diagnoses = EligibilityDiagnosis.objects.has_considered_valid( job_application.job_seeker, for_siae=job_application.to_siae ) self.assertTrue(has_considered_valid_diagnoses) # Check diagnosis. eligibility_diagnosis = job_application.get_eligibility_diagnosis() self.assertEqual(eligibility_diagnosis.author, siae_user) self.assertEqual(eligibility_diagnosis.author_kind, EligibilityDiagnosis.AUTHOR_KIND_SIAE_STAFF) self.assertEqual(eligibility_diagnosis.author_siae, job_application.to_siae) # Check administrative criteria. administrative_criteria = eligibility_diagnosis.administrative_criteria.all() self.assertEqual(3, administrative_criteria.count()) self.assertIn(criterion1, administrative_criteria) self.assertIn(criterion2, administrative_criteria) self.assertIn(criterion3, administrative_criteria)
def test_accept_job_application_sent_by_authorized_prescriber(self): job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( state=JobApplicationWorkflow.STATE_PROCESSING) # A valid Pôle emploi ID should trigger an automatic approval delivery. self.assertNotEqual(job_application.job_seeker.pole_emploi_id, "") job_application.accept(user=job_application.to_siae.members.first()) self.assertIsNotNone(job_application.approval) self.assertTrue(job_application.approval_number_sent_by_email) self.assertEqual(job_application.approval_delivery_mode, job_application.APPROVAL_DELIVERY_MODE_AUTOMATIC) # Check sent email. self.assertEqual(len(mail.outbox), 2) self.assertIn("Candidature acceptée", mail.outbox[0].subject) self.assertIn("Délivrance d'un PASS IAE pour", mail.outbox[1].subject)
def test_eligibility(self): """Test eligibility.""" job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( state=JobApplicationWorkflow.STATE_PROCESSING) self.assertTrue(job_application.state.is_processing) siae_user = job_application.to_siae.members.first() self.client.login(username=siae_user.email, password=DEFAULT_PASSWORD) self.assertFalse(job_application.job_seeker.has_eligibility_diagnosis) url = reverse("apply:eligibility", kwargs={"job_application_id": job_application.pk}) response = self.client.get(url) self.assertEqual(response.status_code, 200) post_data = {"confirm-eligibility": "1"} response = self.client.post(url, data=post_data) self.assertEqual(response.status_code, 302) next_url = reverse("apply:details_for_siae", kwargs={"job_application_id": job_application.pk}) self.assertEqual(response.url, next_url) self.assertTrue(job_application.job_seeker.has_eligibility_diagnosis)
def test_new_for_siae(self): job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( selected_jobs=Appellation.objects.all() ) email = job_application.email_new_for_siae # To. self.assertIn(job_application.to_siae.members.first().email, email.to) self.assertEqual(len(email.to), 1) # Body. self.assertIn(job_application.job_seeker.first_name, email.body) self.assertIn(job_application.job_seeker.last_name, email.body) self.assertIn( job_application.job_seeker.birthdate.strftime("%d/%m/%Y"), email.body ) self.assertIn(job_application.job_seeker.email, email.body) self.assertIn( format_filters.format_phone(job_application.job_seeker.phone), email.body ) self.assertIn(job_application.message, email.body) for job in job_application.selected_jobs.all(): self.assertIn(job.display_name, email.body) self.assertIn(job_application.sender.get_full_name(), email.body) self.assertIn(job_application.sender.email, email.body) self.assertIn( format_filters.format_phone(job_application.sender.phone), email.body )
def test_accept(self): # When sent by authorized prescriber. job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory() email = job_application.email_accept # To. self.assertIn(job_application.job_seeker.email, email.to) self.assertIn(job_application.sender.email, email.to) self.assertEqual(len(email.to), 2) # Body. self.assertIn(job_application.sender.first_name, email.body) self.assertIn(job_application.sender.last_name, email.body) self.assertIn(job_application.job_seeker.first_name, email.body) self.assertIn(job_application.job_seeker.last_name, email.body) self.assertIn(job_application.to_siae.display_name, email.body) self.assertIn(job_application.answer, email.body) # When sent by jobseeker. job_application = JobApplicationSentByJobSeekerFactory() email = job_application.email_accept # To. self.assertEqual(job_application.job_seeker.email, job_application.sender.email) self.assertIn(job_application.job_seeker.email, email.to) self.assertEqual(len(email.to), 1) # Body. self.assertIn(job_application.to_siae.display_name, email.body) self.assertIn(job_application.answer, email.body)
def test_refuse(self): # When sent by authorized prescriber. job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( refusal_reason=JobApplication.REFUSAL_REASON_DID_NOT_COME ) email = job_application.email_refuse # To. self.assertIn(job_application.job_seeker.email, email.to) self.assertIn(job_application.sender.email, email.to) self.assertEqual(len(email.to), 2) # Body. self.assertIn(job_application.sender.first_name, email.body) self.assertIn(job_application.sender.last_name, email.body) self.assertIn(job_application.job_seeker.first_name, email.body) self.assertIn(job_application.job_seeker.last_name, email.body) self.assertIn(job_application.to_siae.display_name, email.body) self.assertIn(job_application.answer, email.body) # When sent by jobseeker. job_application = JobApplicationSentByJobSeekerFactory( refusal_reason=JobApplication.REFUSAL_REASON_DID_NOT_COME ) email = job_application.email_refuse # To. self.assertEqual(job_application.job_seeker.email, job_application.sender.email) self.assertIn(job_application.job_seeker.email, email.to) self.assertEqual(len(email.to), 1) # Body. self.assertIn(job_application.to_siae.display_name, email.body) self.assertIn(job_application.answer, email.body)
def test_refuse(self, *args, **kwargs): """Ensure that the `refuse` transition is triggered.""" job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( state=JobApplicationWorkflow.STATE_PROCESSING ) self.assertTrue(job_application.state.is_processing) siae_user = job_application.to_siae.members.first() self.client.login(username=siae_user.email, password=DEFAULT_PASSWORD) url = reverse("apply:refuse", kwargs={"job_application_id": job_application.pk}) response = self.client.get(url) self.assertEqual(response.status_code, 200) post_data = {"refusal_reason": job_application.REFUSAL_REASON_OTHER, "answer": ""} response = self.client.post(url, data=post_data) self.assertEqual(response.status_code, 200) self.assertIn("answer", response.context["form"].errors, "Answer is mandatory with REFUSAL_REASON_OTHER.") post_data = { "refusal_reason": job_application.REFUSAL_REASON_OTHER, "answer": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", } response = self.client.post(url, data=post_data) next_url = reverse("apply:details_for_siae", kwargs={"job_application_id": job_application.pk}) self.assertRedirects(response, next_url) job_application = JobApplication.objects.get(pk=job_application.pk) self.assertTrue(job_application.state.is_refused)
def test_accept(self): """Test the `accept` transition.""" job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( state=JobApplicationWorkflow.STATE_PROCESSING) self.assertTrue(job_application.state.is_processing) siae_user = job_application.to_siae.members.first() self.client.login(username=siae_user.email, password=DEFAULT_PASSWORD) url = reverse("apply:accept", kwargs={"job_application_id": job_application.pk}) response = self.client.get(url) self.assertEqual(response.status_code, 200) today = datetime.date.today() post_data = { "date_of_hiring": today.strftime("%d/%m/%Y"), "answer": "" } response = self.client.post(url, data=post_data) self.assertEqual(response.status_code, 302) next_url = reverse("apply:details_for_siae", kwargs={"job_application_id": job_application.pk}) self.assertEqual(response.url, next_url) job_application = JobApplication.objects.get(pk=job_application.pk) self.assertEqual(job_application.date_of_hiring, today) self.assertTrue(job_application.state.is_accepted)
def test_send_number_by_email(self): job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( state=JobApplicationWorkflow.STATE_PROCESSING) job_application.accept(user=job_application.to_siae.members.first()) approval = ApprovalFactory(job_application=job_application) # Delete `accept` and `accept_trigger_manual_approval` emails. mail.outbox = [] approval.send_number_by_email() self.assertEqual(len(mail.outbox), 1) email = mail.outbox[0] self.assertIn(approval.user.get_full_name(), email.subject) self.assertIn(approval.user.get_full_name(), email.body) self.assertIn(approval.number, email.body)
def test_new_for_prescriber(self): job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( selected_jobs=Appellation.objects.all()) email = job_application.email_new_for_prescriber # To. self.assertIn(job_application.sender.email, email.to) self.assertEqual(len(email.to), 1) self.assertEqual(job_application.sender_kind, JobApplication.SENDER_KIND_PRESCRIBER) # Subject self.assertIn(job_application.job_seeker.get_full_name(), email.subject) # Body. self.assertIn(job_application.job_seeker.first_name, email.body) self.assertIn(job_application.job_seeker.last_name, email.body) self.assertIn( job_application.job_seeker.birthdate.strftime("%d/%m/%Y"), email.body) self.assertIn(job_application.job_seeker.email, email.body) self.assertIn( format_filters.format_phone(job_application.job_seeker.phone), email.body) self.assertIn(job_application.message, email.body) for job in job_application.selected_jobs.all(): self.assertIn(job.display_name, email.body) self.assertIn(job_application.sender.get_full_name(), email.body) self.assertIn(job_application.sender.email, email.body) self.assertIn( format_filters.format_phone(job_application.sender.phone), email.body) # Assert the Job Seeker does not have access to confidential information. email = job_application.email_new_for_job_seeker( base_url="http://testserver") self.assertIn(job_application.sender.get_full_name(), email.body) self.assertIn( job_application.sender_prescriber_organization.display_name, email.body) self.assertNotIn(job_application.sender.email, email.body) self.assertNotIn( format_filters.format_phone(job_application.sender.phone), email.body)
def test_job_application_sent_by_authorized_prescriber_organization_factory(self): job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory() self.assertEqual( job_application.sender_kind, JobApplication.SENDER_KIND_PRESCRIBER ) self.assertNotEqual(job_application.job_seeker, job_application.sender) sender = job_application.sender sender_prescriber_organization = job_application.sender_prescriber_organization self.assertIn(sender, sender_prescriber_organization.members.all()) self.assertTrue(sender_prescriber_organization.is_authorized)
def test_details_for_prescriber_as_siae(self, *args, **kwargs): """As a SIAE user, I cannot access the job_applications details for prescribers.""" job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory() siae_user = job_application.to_siae.members.first() self.client.login(username=siae_user.email, password=DEFAULT_PASSWORD) url = reverse("apply:details_for_prescriber", kwargs={"job_application_id": job_application.pk}) response = self.client.get(url) self.assertEqual(response.status_code, 302)
def test_eligibility_for_siae_not_subject_to_eligibility_rules(self, *args, **kwargs): """Test eligibility for an Siae not subject to eligibility rules.""" job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( state=JobApplicationWorkflow.STATE_PROCESSING, to_siae__kind=Siae.KIND_GEIQ ) siae_user = job_application.to_siae.members.first() self.client.login(username=siae_user.email, password=DEFAULT_PASSWORD) url = reverse("apply:eligibility", kwargs={"job_application_id": job_application.pk}) response = self.client.get(url) self.assertEqual(response.status_code, 404)
def test_details_for_siae_hidden(self, *args, **kwargs): """A hidden job_application is not displayed.""" job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( job_seeker__is_job_seeker=True, hidden_for_siae=True ) siae_user = job_application.to_siae.members.first() self.client.login(username=siae_user.email, password=DEFAULT_PASSWORD) url = reverse("apply:details_for_siae", kwargs={"job_application_id": job_application.pk}) response = self.client.get(url) self.assertEqual(404, response.status_code)
def setUpTestData(cls): """Set up data for the whole TestCase.""" cls.job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory() cls.siae_user = cls.job_application.to_siae.members.first() kwargs = {"job_application_id": cls.job_application.pk} cls.url_details = reverse("apply:details_for_siae", kwargs=kwargs) cls.url_process = reverse("apply:process", kwargs=kwargs) cls.url_eligibility = reverse("apply:eligibility", kwargs=kwargs) cls.url_refuse = reverse("apply:refuse", kwargs=kwargs) cls.url_postpone = reverse("apply:postpone", kwargs=kwargs) cls.url_accept = reverse("apply:accept", kwargs=kwargs)
def test_details_for_siae(self): """Display the details of a job application.""" job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( ) siae_user = job_application.to_siae.members.first() self.client.login(username=siae_user.email, password=DEFAULT_PASSWORD) url = reverse("apply:details_for_siae", kwargs={"job_application_id": job_application.pk}) response = self.client.get(url) self.assertEqual(response.status_code, 200)
def test_accept_trigger_manual_approval(self): job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( state=JobApplicationWorkflow.STATE_ACCEPTED, date_of_hiring=datetime.date.today(), ) accepted_by = job_application.to_siae.members.first() email = job_application.email_accept_trigger_manual_approval(accepted_by) # To. self.assertIn(settings.ITOU_EMAIL_CONTACT, email.to) self.assertEqual(len(email.to), 1) # Body. self.assertIn(job_application.job_seeker.first_name, email.body) self.assertIn(job_application.job_seeker.last_name, email.body) self.assertIn(job_application.job_seeker.email, email.body) self.assertIn( job_application.job_seeker.birthdate.strftime("%d/%m/%Y"), email.body ) self.assertIn(job_application.to_siae.siret, email.body) self.assertIn(job_application.to_siae.get_kind_display(), email.body) self.assertIn(job_application.to_siae.get_department_display(), email.body) self.assertIn(job_application.to_siae.display_name, email.body) self.assertIn(job_application.date_of_hiring.strftime("%d/%m/%Y"), email.body) self.assertIn(accepted_by.get_full_name(), email.body) self.assertIn(accepted_by.email, email.body) self.assertIn( reverse( "admin:job_applications_jobapplication_change", args=[job_application.id], ), email.body, ) self.assertIn(reverse("admin:approvals_approval_add"), email.body) approvals_admin_query_string = urlencode( { "user": job_application.job_seeker.pk, "start_at": job_application.date_of_hiring.strftime("%d/%m/%Y"), "job_application": job_application.pk, } ) self.assertIn(approvals_admin_query_string, email.body)
def test_process(self, *args, **kwargs): """Ensure that the `process` transition is triggered.""" job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory() siae_user = job_application.to_siae.members.first() self.client.login(username=siae_user.email, password=DEFAULT_PASSWORD) url = reverse("apply:process", kwargs={"job_application_id": job_application.pk}) response = self.client.post(url) next_url = reverse("apply:details_for_siae", kwargs={"job_application_id": job_application.pk}) self.assertRedirects(response, next_url) job_application = JobApplication.objects.get(pk=job_application.pk) self.assertTrue(job_application.state.is_processing)
def test_edit_by_prescriber(self): job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( ) user = job_application.sender # Ensure that the job seeker is not autonomous (i.e. he did not register by himself). job_application.job_seeker.created_by = user job_application.job_seeker.save() self.client.login(username=user.email, password=DEFAULT_PASSWORD) url = reverse("dashboard:edit_job_seeker_info", kwargs={"job_application_id": job_application.pk}) response = self.client.get(url) self.assertEqual(response.status_code, 200)
def test_is_sent_by_authorized_prescriber(self): job_application = JobApplicationSentByJobSeekerFactory() self.assertFalse(job_application.is_sent_by_authorized_prescriber) job_application = JobApplicationSentByPrescriberFactory() self.assertFalse(job_application.is_sent_by_authorized_prescriber) job_application = JobApplicationSentByPrescriberOrganizationFactory() self.assertFalse(job_application.is_sent_by_authorized_prescriber) job_application = JobApplicationSentBySiaeFactory() self.assertFalse(job_application.is_sent_by_authorized_prescriber) job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory() self.assertTrue(job_application.is_sent_by_authorized_prescriber)
def test_cancel(self): job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( state=JobApplicationWorkflow.STATE_ACCEPTED) cancellation_user = job_application.to_siae.active_members.first() email = job_application.email_cancel(cancelled_by=cancellation_user) # To. self.assertIn(cancellation_user.email, email.to) self.assertIn(job_application.sender.email, email.bcc) self.assertEqual(len(email.to), 1) self.assertEqual(len(email.bcc), 1) # Body. self.assertIn("annulée", email.body) self.assertIn(job_application.sender.first_name, email.body) self.assertIn(job_application.sender.last_name, email.body) self.assertIn(job_application.job_seeker.first_name, email.body) self.assertIn(job_application.job_seeker.last_name, email.body) # When sent by jobseeker. job_application = JobApplicationSentByJobSeekerFactory( state=JobApplicationWorkflow.STATE_ACCEPTED) email = job_application.email_cancel(cancelled_by=cancellation_user) # To. self.assertFalse(email.bcc)
def test_postpone(self, *args, **kwargs): """Ensure that the `postpone` transition is triggered.""" job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( state=JobApplicationWorkflow.STATE_PROCESSING ) self.assertTrue(job_application.state.is_processing) siae_user = job_application.to_siae.members.first() self.client.login(username=siae_user.email, password=DEFAULT_PASSWORD) url = reverse("apply:postpone", kwargs={"job_application_id": job_application.pk}) response = self.client.get(url) self.assertEqual(response.status_code, 200) post_data = {"answer": ""} response = self.client.post(url, data=post_data) next_url = reverse("apply:details_for_siae", kwargs={"job_application_id": job_application.pk}) self.assertRedirects(response, next_url) job_application = JobApplication.objects.get(pk=job_application.pk) self.assertTrue(job_application.state.is_postponed)
def test_details_for_siae(self, *args, **kwargs): """Display the details of a job application.""" job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory() siae = job_application.to_siae siae_user = siae.members.first() self.client.login(username=siae_user.email, password=DEFAULT_PASSWORD) url = reverse("apply:details_for_siae", kwargs={"job_application_id": job_application.pk}) response = self.client.get(url) self.assertFalse(job_application.has_editable_job_seeker) self.assertContains(response, "Ce candidat a pris le contrôle de son compte utilisateur.") job_application.job_seeker.created_by = siae_user job_application.job_seeker.save() url = reverse("apply:details_for_siae", kwargs={"job_application_id": job_application.pk}) response = self.client.get(url) self.assertTrue(job_application.has_editable_job_seeker) self.assertContains(response, "Modifier les informations") # Test resume presence: # 1/ Job seeker has a personal resume (technical debt). resume_link = "https://server.com/rockie-balboa.pdf" job_application = JobApplicationSentByJobSeekerFactory( job_seeker__resume_link=resume_link, resume_link="", to_siae=siae ) url = reverse("apply:details_for_siae", kwargs={"job_application_id": job_application.pk}) response = self.client.get(url) self.assertContains(response, resume_link) # 2/ Job application was sent with an attached resume resume_link = "https://server.com/rockie-balboa.pdf" job_application = JobApplicationSentByJobSeekerFactory(to_siae=siae) url = reverse("apply:details_for_siae", kwargs={"job_application_id": job_application.pk}) response = self.client.get(url) self.assertContains(response, resume_link)
def test_send_approval_number_by_email_manually(self): staff_member = UserFactory(is_staff=True) job_seeker = JobSeekerFactory() approval = ApprovalFactory(user=job_seeker) job_application = JobApplicationSentByAuthorizedPrescriberOrganizationFactory( job_seeker=job_seeker, state=JobApplicationWorkflow.STATE_PROCESSING, approval=approval) job_application.accept(user=job_application.to_siae.members.first()) mail.outbox = [] # Delete previous emails. job_application.send_approval_number_by_email_manually( deliverer=staff_member) self.assertTrue(job_application.approval_number_sent_by_email) self.assertIsNotNone(job_application.approval_number_sent_at) self.assertEqual(job_application.approval_delivery_mode, job_application.APPROVAL_DELIVERY_MODE_MANUAL) self.assertEqual(job_application.approval_number_delivered_by, staff_member) self.assertEqual(len(mail.outbox), 1)