Skip to content

Commit

Permalink
redirection d'un utilisateur connecté vers ses réglementations lorsqu…
Browse files Browse the repository at this point in the history
…'il tente d'accéder à l'index du site
  • Loading branch information
sblondon committed Oct 20, 2023
1 parent f512fc1 commit fae8ac0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 15 additions & 1 deletion impact/public/tests.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
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
content = response.content.decode("utf-8")
assert "<!-- page index -->" 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")

Expand Down
3 changes: 3 additions & 0 deletions impact/public/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,6 +13,8 @@


def index(request):
if request.user.is_authenticated:
return redirect(reverse("reglementations:reglementations"))
return render(request, "public/index.html")


Expand Down

0 comments on commit fae8ac0

Please sign in to comment.