mirror of
https://github.com/ae-utbm/sith.git
synced 2026-10-04 01:44:15 +00:00
Merge pull request #1488 from ae-utbm/cgu-approve
Force CGU/ToS approval on account creation
This commit is contained in:
13 files changed
+404
-186
No files matched your search
+38
-2
@@ -27,6 +27,7 @@ from django.core.exceptions import ValidationError
|
||||
from django.core.mail import EmailMessage
|
||||
from django.test import Client, RequestFactory, TestCase
|
||||
from django.urls import reverse
|
||||
from django.utils.timezone import now
|
||||
from django.views.generic import View
|
||||
from django.views.generic.base import ContextMixin
|
||||
from model_bakery import baker
|
||||
@@ -55,6 +56,7 @@ class TestUserRegistration:
|
||||
"password2": "plop",
|
||||
"captcha_0": "dummy-value",
|
||||
"captcha_1": "PASSED",
|
||||
"cgu_approved_at": now(),
|
||||
}
|
||||
|
||||
@pytest.fixture()
|
||||
@@ -92,6 +94,10 @@ class TestUserRegistration:
|
||||
({"first_name": ""}, "Ce champ est obligatoire."),
|
||||
({"last_name": ""}, "Ce champ est obligatoire."),
|
||||
({"captcha_1": "WRONG_CAPTCHA"}, "CAPTCHA invalide"),
|
||||
(
|
||||
{"cgu_approved_at": False},
|
||||
"Vous devez approuver les conditions générales d'utilisation",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_register_user_form_fail(
|
||||
@@ -150,7 +156,7 @@ class TestUserRegistration:
|
||||
class TestUserLogin:
|
||||
@pytest.fixture()
|
||||
def user(self) -> User:
|
||||
return baker.make(User, password=make_password("plop"))
|
||||
return baker.make(User, password=make_password("plop"), cgu_approved_at=now())
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"identifier_getter",
|
||||
@@ -191,10 +197,40 @@ class TestUserLogin:
|
||||
reverse("core:login"),
|
||||
{"username": identifier_getter(user), "password": "plop"},
|
||||
)
|
||||
assertRedirects(response, reverse("core:index"))
|
||||
assertRedirects(response, settings.LOGIN_REDIRECT_URL)
|
||||
assert response.wsgi_request.user == user
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestCGU:
|
||||
def test_cgu_approval(self, client: Client):
|
||||
user = baker.make(User, password=make_password("plop"), cgu_approved_at=None)
|
||||
user_url = user.get_absolute_url()
|
||||
res = client.post(
|
||||
reverse("core:login"),
|
||||
{"username": user.username, "password": "plop", "next": user_url},
|
||||
)
|
||||
assertRedirects(res, reverse("core:approve_cgu", query={"next": user_url}))
|
||||
res = client.post(
|
||||
reverse("core:approve_cgu"), {"cgu_approved_at": now(), "next": user_url}
|
||||
)
|
||||
assertRedirects(res, user_url)
|
||||
user.refresh_from_db()
|
||||
assert user.cgu_approved_at is not None
|
||||
|
||||
def test_access_cgu_when_already_approved(self, client: Client):
|
||||
url = reverse("core:approve_cgu")
|
||||
|
||||
res = client.get(url)
|
||||
assertRedirects(res, reverse("core:login"))
|
||||
|
||||
client.force_login(baker.make(User, cgu_approved_at=now()))
|
||||
res = client.get(url)
|
||||
assertRedirects(res, settings.LOGIN_REDIRECT_URL)
|
||||
res = client.post(url, {"cgu_approved_at": now()})
|
||||
assertRedirects(res, settings.LOGIN_REDIRECT_URL)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("md", "html"),
|
||||
[
|
||||
|
||||
Reference in new issue
Block a user