Skip to content

Commit

Permalink
Set select_job back_url to accessible views
Browse files Browse the repository at this point in the history
- Job seeker: must pass through the check_job_seeker_infos view, so
  their profile is complete. Direct them back to the company.
- Employer/prescriber who cannot edit personal information: return to
  the company.
- Employer/prescriber who can edit personal information: direct them to
  the update_job_seeker_info process
  • Loading branch information
francoisfreitag committed Apr 8, 2024
1 parent 1e90935 commit 31002a0
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 23 deletions.
24 changes: 15 additions & 9 deletions itou/www/apply/views/submit_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from itou.utils.apis.exceptions import AddressLookupError
from itou.utils.emails import redact_email_address, send_email_messages
from itou.utils.session import SessionNamespace, SessionNamespaceRequiredMixin
from itou.utils.urls import add_url_params
from itou.www.apply.forms import (
ApplicationJobsForm,
CheckJobSeekerInfoForm,
Expand Down Expand Up @@ -867,15 +868,20 @@ def get_context_data(self, **kwargs):
}

def get_back_url(self):
if self.get_previous_applications_queryset().exists():
return reverse(
"apply:step_check_prev_applications",
kwargs={"company_pk": self.company.pk, "job_seeker_pk": self.job_seeker.pk},
)

return reverse(
"apply:step_check_job_seeker_info",
kwargs={"company_pk": self.company.pk, "job_seeker_pk": self.job_seeker.pk},
if self.request.user.is_job_seeker or not self.request.user.can_edit_personal_information(self.job_seeker):
# Job seekers may come from a job description card. Directing them
# back to the company is good enough: it’s easy to find job
# descriptions from there.
return reverse("companies_views:card", kwargs={"siae_id": self.company.pk})
return add_url_params(
reverse(
"apply:update_job_seeker_step_1",
kwargs={
"company_pk": self.company.pk,
"job_seeker_pk": self.job_seeker.pk,
},
),
{"back_url": self.request.get_full_path()},
)


Expand Down
144 changes: 130 additions & 14 deletions tests/www/apply/test_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.test import override_settings
from django.urls import resolve, reverse
from django.utils import timezone
from django.utils.http import urlencode
from pytest_django.asserts import assertContains, assertRedirects

from itou.asp.models import AllocationDuration, EducationLevel, RSAAllocation
Expand Down Expand Up @@ -407,9 +408,21 @@ def test_apply_as_jobseeker(self):

response = self.client.get(next_url)
# Check back_url is present
company_card_url = reverse("companies_views:card", kwargs={"siae_id": company.pk})
self.assertContains(
response,
reverse("apply:step_check_job_seeker_info", kwargs={"company_pk": company.pk, "job_seeker_pk": user.pk}),
f"""
<div class="form-group col col-lg-auto order-1 order-lg-2">
<a href="{company_card_url}"
class="btn btn-block btn-outline-primary"
aria-label="Retourner à l'étape précédente"
>
<span>Retour</span>
</a>
</div>
""",
html=True,
count=1,
)

response = self.client.post(next_url, data={"selected_jobs": [company.job_description_through.first().pk]})
Expand Down Expand Up @@ -1164,7 +1177,26 @@ def test_apply_as_authorized_prescriber(self, _mock):
# ----------------------------------------------------------------------

response = self.client.get(next_url)
assert response.status_code == 200
back_url = reverse(
"apply:update_job_seeker_step_1",
kwargs={"company_pk": company.pk, "job_seeker_pk": new_job_seeker.pk},
)
return_url = urlencode({"back_url": next_url})
self.assertContains(
response,
f"""
<div class="form-group col col-lg-auto order-1 order-lg-2">
<a href="{back_url}?{return_url}"
class="btn btn-block btn-outline-primary"
aria-label="Retourner à l'étape précédente"
>
<span>Retour</span>
</a>
</div>
""",
html=True,
count=1,
)

response = self.client.post(next_url, data={"selected_jobs": [company.job_description_through.first().pk]})
assert response.status_code == 302
Expand Down Expand Up @@ -3797,8 +3829,22 @@ def test_no_previous_as_job_seeker(self):
self.assertRedirects(response, self.application_jobs_url)

response = self.client.get(self.application_jobs_url)
self.assertContains(response, self.check_infos_url)
self.assertNotContains(response, self.check_prev_applications_url)
company_card_url = reverse("companies_views:card", kwargs={"siae_id": self.company.pk})
self.assertContains(
response,
f"""
<div class="form-group col col-lg-auto order-1 order-lg-2">
<a href="{company_card_url}"
class="btn btn-block btn-outline-primary"
aria-label="Retourner à l'étape précédente"
>
<span>Retour</span>
</a>
</div>
""",
html=True,
count=1,
)

def test_with_previous_as_job_seeker(self):
self._login_and_setup_session(self.job_seeker)
Expand All @@ -3820,8 +3866,22 @@ def test_with_previous_as_job_seeker(self):

# Check that the back URL is correct
response = self.client.get(self.application_jobs_url)
self.assertNotContains(response, self.check_infos_url)
self.assertContains(response, self.check_prev_applications_url)
company_card_url = reverse("companies_views:card", kwargs={"siae_id": self.company.pk})
self.assertContains(
response,
f"""
<div class="form-group col col-lg-auto order-1 order-lg-2">
<a href="{company_card_url}"
class="btn btn-block btn-outline-primary"
aria-label="Retourner à l'étape précédente"
>
<span>Retour</span>
</a>
</div>
""",
html=True,
count=1,
)

def test_no_previous_as_authorized_prescriber(self):
authorized_prescriber = PrescriberOrganizationWithMembershipFactory(authorized=True).members.first()
Expand All @@ -3830,8 +3890,22 @@ def test_no_previous_as_authorized_prescriber(self):
self.assertRedirects(response, self.application_jobs_url)

response = self.client.get(self.application_jobs_url)
self.assertContains(response, self.check_infos_url)
self.assertNotContains(response, self.check_prev_applications_url)
company_card_url = reverse("companies_views:card", kwargs={"siae_id": self.company.pk})
self.assertContains(
response,
f"""
<div class="form-group col col-lg-auto order-1 order-lg-2">
<a href="{company_card_url}"
class="btn btn-block btn-outline-primary"
aria-label="Retourner à l'étape précédente"
>
<span>Retour</span>
</a>
</div>
""",
html=True,
count=1,
)

def test_with_previous_as_authorized_prescriber(self):
authorized_prescriber = PrescriberOrganizationWithMembershipFactory(authorized=True).members.first()
Expand All @@ -3853,8 +3927,22 @@ def test_with_previous_as_authorized_prescriber(self):

# Check that the back URL is correct
response = self.client.get(self.application_jobs_url)
self.assertNotContains(response, self.check_infos_url)
self.assertContains(response, self.check_prev_applications_url)
company_card_url = reverse("companies_views:card", kwargs={"siae_id": self.company.pk})
self.assertContains(
response,
f"""
<div class="form-group col col-lg-auto order-1 order-lg-2">
<a href="{company_card_url}"
class="btn btn-block btn-outline-primary"
aria-label="Retourner à l'étape précédente"
>
<span>Retour</span>
</a>
</div>
""",
html=True,
count=1,
)

def test_no_previous_as_employer(self):
self._login_and_setup_session(self.company.members.first())
Expand All @@ -3863,8 +3951,22 @@ def test_no_previous_as_employer(self):
self.assertRedirects(response, self.application_jobs_url)

response = self.client.get(self.application_jobs_url)
self.assertContains(response, self.check_infos_url)
self.assertNotContains(response, self.check_prev_applications_url)
company_card_url = reverse("companies_views:card", kwargs={"siae_id": self.company.pk})
self.assertContains(
response,
f"""
<div class="form-group col col-lg-auto order-1 order-lg-2">
<a href="{company_card_url}"
class="btn btn-block btn-outline-primary"
aria-label="Retourner à l'étape précédente"
>
<span>Retour</span>
</a>
</div>
""",
html=True,
count=1,
)

def test_with_previous_as_employer(self):
JobApplicationFactory(job_seeker=self.job_seeker, to_company=self.company)
Expand All @@ -3877,8 +3979,22 @@ def test_with_previous_as_employer(self):

# Check that the back URL is correct
response = self.client.get(self.application_jobs_url)
self.assertNotContains(response, self.check_infos_url)
self.assertContains(response, self.check_prev_applications_url)
company_card_url = reverse("companies_views:card", kwargs={"siae_id": self.company.pk})
self.assertContains(
response,
f"""
<div class="form-group col col-lg-auto order-1 order-lg-2">
<a href="{company_card_url}"
class="btn btn-block btn-outline-primary"
aria-label="Retourner à l'étape précédente"
>
<span>Retour</span>
</a>
</div>
""",
html=True,
count=1,
)


class FindJobSeekerForHireViewTestCase(TestCase):
Expand Down

0 comments on commit 31002a0

Please sign in to comment.