From fae8ac08151ef66da0bf67d1aff61f7f51286229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Blondon?= Date: Fri, 20 Oct 2023 14:06:36 +0200 Subject: [PATCH] =?UTF-8?q?redirection=20d'un=20utilisateur=20connect?= =?UTF-8?q?=C3=A9=20vers=20ses=20r=C3=A9glementations=20lorsqu'il=20tente?= =?UTF-8?q?=20d'acc=C3=A9der=20=C3=A0=20l'index=20du=20site?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- impact/public/tests.py | 16 +++++++++++++++- impact/public/views.py | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/impact/public/tests.py b/impact/public/tests.py index cea52b98d..c32e841f8 100644 --- a/impact/public/tests.py +++ b/impact/public/tests.py @@ -1,12 +1,13 @@ import html import pytest +from django.urls import reverse import api.exceptions from entreprises.models import CaracteristiquesAnnuelles -def test_page_index(client): +def test_page_index_pour_un_visiteur_anonyme(client): response = client.get("/") assert response.status_code == 200 @@ -14,6 +15,19 @@ def test_page_index(client): assert "" in content +def test_redirection_de_la_page_index_vers_ses_reglementations_si_l_utilisateur_est_connecte( + client, alice +): + client.force_login(alice) + + response = client.get("/", follow=True) + + assert response.status_code == 200 + assert response.redirect_chain == [ + (reverse("reglementations:reglementations"), 302), + ] + + def test_page_simulation(client): response = client.get("/simulation") diff --git a/impact/public/views.py b/impact/public/views.py index 8b708d198..7370953e6 100644 --- a/impact/public/views.py +++ b/impact/public/views.py @@ -3,6 +3,7 @@ from django.core.mail import EmailMessage from django.shortcuts import redirect from django.shortcuts import render +from django.urls import reverse import api.exceptions import api.recherche_entreprises @@ -12,6 +13,8 @@ def index(request): + if request.user.is_authenticated: + return redirect(reverse("reglementations:reglementations")) return render(request, "public/index.html")