def test_birth_date_incorrect_day(self): form1 = forms.CreateUserForm({ 'email': '*****@*****.**', 'password1': 'admin', 'password2': 'admin', 'birth_date': '1999-1-00' }) form2 = forms.CreateUserForm({ 'email': '*****@*****.**', 'password1': 'admin', 'password2': 'admin', 'birth_date': '1999.1.32' }) self.assertFalse(form1.is_valid()) self.assertFalse(form2.is_valid())
def test_birth_date_correct(self): form = forms.CreateUserForm({ 'email': '*****@*****.**', 'password1': 'admin', 'password2': 'admin', 'birth_date': '1999-12-01' }) self.assertTrue(form.is_valid())
def test_uppercase_email(self): form = forms.CreateUserForm( { 'email': '*****@*****.**', 'password1': 'admin', 'password2': 'admin', }, ) self.assertTrue(form.is_valid())
def test_incorrect_email(self): form = forms.CreateUserForm( { 'email': 'cooluser', 'password1': 'admin', 'password2': 'admin', }, ) self.assertFalse(form.is_valid())
def test_form_is_valid(self) -> None: form = forms.CreateUserForm( { 'email': '*****@*****.**', 'password1': 'admin', 'password2': 'admin', }, ) self.assertTrue(form.is_valid(), 'Form isn`t valid.')
def user_create_view(request): user_form = forms.CreateUserForm() if request.POST: user_form = forms.CreateUserForm( request.POST or None, request.FILES, ) if user_form.is_valid(): user = user_form.save(commit=False) raw_password1 = user_form.cleaned_data['password1'] raw_password2 = user_form.cleaned_data['password2'] if raw_password1 == raw_password2: user.set_password(raw_password1) user.save() messages.success(request, 'Владелец квартиры создан!') return redirect('admin_panel:users_list') else: messages.success(request, 'Пароли не совпадают!') else: messages.success(request, 'Ошибка создания пользователя!') return render(request, 'admin_panel/users/create.html', { 'user_form': user_form, })
def test_valid_label_form(self) -> None: form = forms.CreateUserForm() self.assertEqual(form.fields['first_name'].label, 'First name') self.assertEqual(form.fields['last_name'].label, 'Last name') self.assertEqual(form.fields['middle_name'].label, 'Middle name')