mirror of
https://github.com/ae-utbm/sith.git
synced 2025-02-26 01:17:13 +00:00
Merge pull request #1030 from ae-utbm/subscription-student-status
Give the student role when creating a new user subscription
This commit is contained in:
commit
c272cad2ea
@ -100,6 +100,13 @@ class SubscriptionNewUserForm(SubscriptionForm):
|
|||||||
email=self.cleaned_data.get("email"),
|
email=self.cleaned_data.get("email"),
|
||||||
date_of_birth=self.cleaned_data.get("date_of_birth"),
|
date_of_birth=self.cleaned_data.get("date_of_birth"),
|
||||||
)
|
)
|
||||||
|
if self.cleaned_data.get("subscription_type") in [
|
||||||
|
"un-semestre",
|
||||||
|
"deux-semestres",
|
||||||
|
"cursus-tronc-commun",
|
||||||
|
"cursus-branche",
|
||||||
|
]:
|
||||||
|
member.role = "STUDENT"
|
||||||
member.generate_username()
|
member.generate_username()
|
||||||
member.set_password(secrets.token_urlsafe(nbytes=10))
|
member.set_password(secrets.token_urlsafe(nbytes=10))
|
||||||
self.instance.member = member
|
self.instance.member = member
|
||||||
|
@ -89,6 +89,28 @@ def test_form_new_user(settings: SettingsWrapper):
|
|||||||
form.save()
|
form.save()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"subscription_type",
|
||||||
|
["un-semestre", "deux-semestres", "cursus-tronc-commun", "cursus-branche"],
|
||||||
|
)
|
||||||
|
def test_form_set_new_user_as_student(settings: SettingsWrapper, subscription_type):
|
||||||
|
"""Test that new users have the student role by default."""
|
||||||
|
data = {
|
||||||
|
"first_name": "John",
|
||||||
|
"last_name": "Doe",
|
||||||
|
"email": "jdoe@utbm.fr",
|
||||||
|
"date_of_birth": localdate() - relativedelta(years=18),
|
||||||
|
"subscription_type": subscription_type,
|
||||||
|
"location": settings.SITH_SUBSCRIPTION_LOCATIONS[0][0],
|
||||||
|
"payment_method": settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0][0],
|
||||||
|
}
|
||||||
|
form = SubscriptionNewUserForm(data)
|
||||||
|
assert form.is_valid()
|
||||||
|
form.clean()
|
||||||
|
assert form.instance.member.role == "STUDENT"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("user_factory", "status_code"),
|
("user_factory", "status_code"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user