diff --git a/itou/www/dashboard/views.py b/itou/www/dashboard/views.py index 2174a8d03e1..b1b44dd6957 100644 --- a/itou/www/dashboard/views.py +++ b/itou/www/dashboard/views.py @@ -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) diff --git a/tests/gps/tests.py b/tests/gps/tests.py index 2d9ac691e46..1093573d997 100644 --- a/tests/gps/tests.py +++ b/tests/gps/tests.py @@ -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 @@ -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")) @@ -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") diff --git a/tests/www/dashboard/tests.py b/tests/www/dashboard/tests.py index c81aa8cdecf..422770c74d4 100644 --- a/tests/www/dashboard/tests.py +++ b/tests/www/dashboard/tests.py @@ -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 @@ -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, " @@ -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")) @@ -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")) @@ -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) @@ -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") @@ -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 @@ -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"), diff --git a/tests/www/signup/test_password.py b/tests/www/signup/test_password.py index d5742a56af6..99258fcc243 100644 --- a/tests/www/signup/test_password.py +++ b/tests/www/signup/test_password.py @@ -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 @@ -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.