Skip to content

Commit

Permalink
Force job seekers to fill their profile
Browse files Browse the repository at this point in the history
The first_name, last_name, and address are required fields.
  • Loading branch information
francoisfreitag committed May 15, 2024
1 parent b0c79a1 commit 26e9f6d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
8 changes: 5 additions & 3 deletions itou/www/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,11 @@ def dashboard(request, template_name="dashboard/dashboard.html"):
else:
context["closed_campaigns"].append(campaign)
elif request.user.is_job_seeker:
# Force the job seeker to fill its title to use the site
if not request.user.title:
return HttpResponseRedirect(reverse("dashboard:edit_user_info"))
# Force job seekers to complete their profile.
required_attributes = ["title", "first_name", "last_name", "address_line_1", "post_code", "city"]
for attr in required_attributes:
if not getattr(request.user, attr):
return HttpResponseRedirect(reverse("dashboard:edit_user_info"))

return render(request, template_name, context)

Expand Down
10 changes: 7 additions & 3 deletions tests/gps/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from itou.users.enums import UserKind
from itou.users.models import User
from tests.gps.factories import FollowUpGroupFactory
from tests.users.factories import JobSeekerFactory, PrescriberFactory
from tests.users.factories import (
JobSeekerFactory,
JobSeekerWithAddressFactory,
PrescriberFactory,
)
from tests.utils.test import parse_response_to_soup


Expand Down Expand Up @@ -137,7 +141,7 @@ def test_navigation(snapshot, client):


def test_access_as_jobseeker(client):
user = JobSeekerFactory()
user = JobSeekerWithAddressFactory()
client.force_login(user)

response = client.get(reverse("gps:my_groups"))
Expand All @@ -161,7 +165,7 @@ def test_access_gps_enabled(client, snapshot):
response = client.get(reverse("dashboard:index"))
assert str(parse_response_to_soup(response, "#gps-card")) == snapshot

user = JobSeekerFactory()
user = JobSeekerWithAddressFactory()
client.force_login(user)
response = client.get(reverse("dashboard:index"))
assertNotContains(response, "gps-card")
Expand Down
36 changes: 25 additions & 11 deletions tests/www/dashboard/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from freezegun import freeze_time
from pytest_django.asserts import assertContains, assertNotContains, assertRedirects
from rest_framework.authtoken.models import Token
from unittest_parametrize import ParametrizedTestCase, param, parametrize

from itou.cities.models import City
from itou.communications import registry as notifications_registry
Expand Down Expand Up @@ -77,7 +78,7 @@


@pytest.mark.usefixtures("unittest_compatibility")
class DashboardViewTest(TestCase):
class DashboardViewTest(ParametrizedTestCase, TestCase):
NO_PRESCRIBER_ORG_MSG = "Votre compte utilisateur n’est rattaché à aucune organisation."
NO_PRESCRIBER_ORG_FOR_PE_MSG = (
"Votre compte utilisateur n’est rattaché à aucune agence France Travail, "
Expand Down Expand Up @@ -568,7 +569,7 @@ def test_dashboard_siae_evaluations_siae_access(self):
self.assertNotContains(response, TODO_BADGE, html=True)

def test_dora_card_is_not_shown_for_job_seeker(self):
user = JobSeekerFactory()
user = JobSeekerWithAddressFactory()
self.client.force_login(user)

response = self.client.get(reverse("dashboard:index"))
Expand All @@ -595,7 +596,7 @@ def test_dora_card_is_shown_for_prescriber(self):
self.assertContains(response, "Suggérer un service partenaire")

def test_diagoriente_info_is_shown_in_sidebar_for_job_seeker(self):
user = JobSeekerFactory()
user = JobSeekerWithAddressFactory()
self.client.force_login(user)

response = self.client.get(reverse("dashboard:index"))
Expand Down Expand Up @@ -663,7 +664,7 @@ def test_dashboard_delete_one_of_multiple_prescriber_orgs_while_logged_in(self):
self.assertNotContains(response, self.NO_PRESCRIBER_ORG_MSG)

def test_dashboard_prescriber_suspend_link(self):
user = JobSeekerFactory()
user = JobSeekerWithAddressFactory()
self.client.force_login(user)
response = self.client.get(reverse("dashboard:index"))
self.assertNotContains(response, self.SUSPEND_TEXT)
Expand Down Expand Up @@ -699,8 +700,9 @@ def test_dashboard_prescriber_suspend_link(self):
@pytest.mark.ignore_unknown_variable_template_error("hiring_pending", "job_application")
@freeze_time("2022-09-15")
def test_dashboard_access_by_a_jobseeker(self):
approval = ApprovalFactory(start_at=datetime(2022, 6, 21), end_at=datetime(2022, 12, 6))
self.client.force_login(approval.user)
user = JobSeekerWithAddressFactory()
approval = ApprovalFactory(user=user, start_at=datetime(2022, 6, 21), end_at=datetime(2022, 12, 6))
self.client.force_login(user)
url = reverse("dashboard:index")
response = self.client.get(url)
self.assertContains(response, "Numéro de PASS IAE")
Expand Down Expand Up @@ -728,15 +730,27 @@ def test_prescriber_with_authorization_pending_dashboard_must_contain_tally_link
f"&source={settings.ITOU_ENVIRONMENT}",
)

def test_job_seeker_without_title_redirected(self):
user = JobSeekerFactory(title="")
@parametrize(
"field,data",
[
param("title", Title.M, id="title"),
param("first_name", "John", id="first_name"),
param("last_name", "Doe", id="last_name"),
param("address_line_1", "1 rue du bac", id="address_line_1"),
param("post_code", "59140", id="post_code"),
param("city", "Dunkerque", id="city"),
],
)
def test_job_seeker_without_required_field_redirected(self, field, data):
empty_field = {field: ""}
user = JobSeekerWithAddressFactory(**empty_field)
self.client.force_login(user)

response = self.client.get(reverse("dashboard:index"))
self.assertRedirects(response, reverse("dashboard:edit_user_info"))

user.title = Title.M
user.save(update_fields=("title",))
setattr(user, field, data)
user.save(update_fields=(field,))

response = self.client.get(reverse("dashboard:index"))
assert response.status_code == 200
Expand Down Expand Up @@ -2474,7 +2488,7 @@ def test_employer_using_django_has_to_activate_ic_account(client):
@pytest.mark.parametrize(
"factory,expected",
[
pytest.param(JobSeekerFactory, assertNotContains, id="JobSeeker"),
pytest.param(JobSeekerWithAddressFactory, assertNotContains, id="JobSeeker"),
pytest.param(partial(EmployerFactory, with_company=True), assertNotContains, id="Employer"),
pytest.param(partial(LaborInspectorFactory, membership=True), assertNotContains, id="LaborInspector"),
pytest.param(PrescriberFactory, assertNotContains, id="PrescriberWithoutOrganization"),
Expand Down
4 changes: 2 additions & 2 deletions tests/www/signup/test_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.urls import reverse
from django.utils.http import urlencode

from tests.users.factories import DEFAULT_PASSWORD, JobSeekerFactory
from tests.users.factories import DEFAULT_PASSWORD, JobSeekerFactory, JobSeekerWithAddressFactory
from tests.utils.test import TestCase


Expand Down Expand Up @@ -71,7 +71,7 @@ def test_password_change_flow(self):
and redirects to the right place.
"""

user = JobSeekerFactory()
user = JobSeekerWithAddressFactory()
self.client.force_login(user)

# Change password.
Expand Down

0 comments on commit 26e9f6d

Please sign in to comment.