예제 #1
0
 def test_form_valid_data(self):
     form = UserCreationForm(
         data={
             'email': '*****@*****.**',
             'username': '******',
             'password1': 'TempraryPass123!',
             'password2': 'TempraryPass123!',
         })
     self.assertTrue(form.is_valid())
예제 #2
0
def user_create(request):
    args = {}
    args.update(csrf(request))
    if request.method == 'POST':
        user_form = UserCreationForm(request.POST)
        args['user_form'] = user_form
        if user_form.is_valid():
            user = user_form.save()
            send_activation_email(request, user)
            user.backend = 'django.contrib.auth.backends.ModelBackend'
            logger.info('user %s created' % str(user))
            return redirect(reverse('index:alert', kwargs={'alert_info': 'mailbox'}))
        else:
            return render_index(request, 'users/auth.html', {'form': user_form, 'title': 'Sign Up'})
    return render_index(request, 'users/auth.html', {'form': UserCreationForm(), 'title': 'Sign Up'})
def register(request):

    if request.method == 'POST':

        form = UserCreationForm(request.POST)

        if form.is_valid():

            form.save()
            email = form.cleaned_data.get('email')
            messages.success(request, f'Создан аккаунт для {email}!')
            return redirect('login')
    else:
        form = users.admin.UserCreationForm()

    return render(request, 'users/register.html', {'form': form})
예제 #4
0
    def test_form_not_valid_username(self):
        user1 = User.objects.create(email='*****@*****.**', username='******')
        password = '******'
        user1.set_password(password)
        user1.is_active = True
        user1.save()

        form = UserCreationForm(
            data={
                'email': '*****@*****.**',
                'username': '******',
                'password1': 'TempraryPass123!',
                'password2': 'TempraryPass123!',
            })
        self.assertFalse(form.is_valid())
        self.assertEquals(len(form.errors), 1)

        form = UserCreationForm(
            data={
                'email': '*****@*****.**',
                'username': '',
                'password1': 'TempraryPass123!',
                'password2': 'TempraryPass123!',
            })
        self.assertFalse(form.is_valid())
        self.assertEquals(len(form.errors), 1)

        form = UserCreationForm(
            data={
                'email': '*****@*****.**',
                'username': '******',
                'password1': 'TempraryPass123!',
                'password2': 'TempraryPass123!',
            })
        self.assertFalse(form.is_valid())
        self.assertEquals(len(form.errors), 1)
예제 #5
0
def register(request):
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            messages.success(request, f'Account created for {username}!')

            return HttpResponseRedirect(reverse('login'))
    else:
        form = UserCreationForm()

        context = {
            'form': form,
            'user_exists': False
        }

        return render(request, 'users/save-user.html', context)
예제 #6
0
 def test_form_no_data(self):
     form = UserCreationForm(data={})
     self.assertFalse(form.is_valid())
     self.assertEquals(len(form.errors), 4)
예제 #7
0
    def test_form_not_valid_password(self):
        form = UserCreationForm(
            data={
                'email': '*****@*****.**',
                'username': '******',
                'password1': '',
                'password2': 'TempraryPass123!',
            })
        self.assertFalse(form.is_valid())
        self.assertEquals(len(form.errors), 1)

        form = UserCreationForm(
            data={
                'email': '*****@*****.**',
                'username': '******',
                'password1': 'TempraryPass123!',
                'password2': '',
            })
        self.assertFalse(form.is_valid())
        self.assertEquals(len(form.errors), 1)

        form = UserCreationForm(
            data={
                'email': '*****@*****.**',
                'username': '******',
                'password1': 'Match',
                'password2': 'NoMatchNoMatch',
            })
        self.assertFalse(form.is_valid())
        self.assertEquals(len(form.errors), 1)

        form = UserCreationForm(
            data={
                'email': '*****@*****.**',
                'username': '******',
                'password1': '1234',
                'password2': '1234',
            })
        self.assertFalse(form.is_valid())
        self.assertEquals(len(form.errors), 1)

        form = UserCreationForm(
            data={
                'email': '*****@*****.**',
                'username': '******',
                'password1': 'test123',
                'password2': 'test123',
            })
        self.assertFalse(form.is_valid())
        self.assertEquals(len(form.errors), 1)
예제 #8
0
 def test_form_username_widget_class(self):
     form = UserCreationForm()
     self.assertTrue(form.fields['email'].widget.attrs['placeholder'] ==
                     'Email address')
예제 #9
0
 def test_form_username_label(self):
     form = UserCreationForm()
     self.assertTrue(form.fields['username'].label == '')