mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 20:09:25 +00:00
methode clean dans MergeForm
fixed formatting Update rootplace/forms.py Co-authored-by: thomas girod <56346771+imperosol@users.noreply.github.com> Check that a user cannot be merged into itself ajout des traductions changed test language to french Check that a user cannot be merged into itself
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from core.models import User, UserBan
|
||||
@ -22,6 +23,16 @@ class MergeForm(forms.Form):
|
||||
queryset=User.objects.all(),
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
user1 = cleaned_data.get("user1")
|
||||
user2 = cleaned_data.get("user2")
|
||||
|
||||
if user1.id == user2.id:
|
||||
raise ValidationError(_("You cannot merge two identical users."))
|
||||
|
||||
return cleaned_data
|
||||
|
||||
|
||||
class SelectUserForm(forms.Form):
|
||||
user = forms.ModelChoiceField(
|
||||
|
@ -22,6 +22,7 @@ from django.utils.timezone import localtime, now
|
||||
from club.models import Club
|
||||
from core.models import Group, User
|
||||
from counter.models import Counter, Customer, Product, Refilling, Selling
|
||||
from rootplace.forms import MergeForm
|
||||
from subscription.models import Subscription
|
||||
|
||||
|
||||
@ -79,6 +80,15 @@ class TestMergeUser(TestCase):
|
||||
sas_admin.id,
|
||||
}
|
||||
|
||||
def test_identical_accounts(self):
|
||||
form = MergeForm(data={"user1": self.to_keep.id, "user2": self.to_keep.id})
|
||||
assert not form.is_valid()
|
||||
assert "__all__" in form.errors
|
||||
assert (
|
||||
"Vous ne pouvez pas fusionner deux utilisateurs identiques."
|
||||
in form.errors["__all__"]
|
||||
)
|
||||
|
||||
def test_both_subscribers_and_with_account(self):
|
||||
Customer(user=self.to_keep, account_id="11000l", amount=0).save()
|
||||
Customer(user=self.to_delete, account_id="12000m", amount=0).save()
|
||||
|
Reference in New Issue
Block a user