Exemplo n.º 1
0
 def test_fields_required(self):
     form = CreateUserForm(data={})
     self.assertFalse(form.is_valid())
     self.assertEqual(form['password1'].errors,
                      [str(Field.default_error_messages['required'])])
     self.assertEqual(form['password2'].errors,
                      [str(Field.default_error_messages['required'])])
Exemplo n.º 2
0
 def test_password_similar(self):
     form = CreateUserForm(
         data={
             'username': '******',
             'first_name': 'doe',
             'last_name': 'doe',
             'password1': 'janedoe',
             'password2': 'janedoe'
         })
     self.assertFalse(form.is_valid())
Exemplo n.º 3
0
 def test_password_too_common(self):
     form = CreateUserForm(
         data={
             'username': '******',
             'first_name': 'doe',
             'last_name': 'doe',
             'password1': 'password',
             'password2': 'password'
         })
     self.assertFalse(form.is_valid())
Exemplo n.º 4
0
 def test_password_same(self):
     form = CreateUserForm(
         data={
             'username': '******',
             'first_name': 'doe',
             'last_name': 'doe',
             'password1': 'super_strong123',
             'password2': 'super_strong123'
         })
     self.assertTrue(form.is_valid())
Exemplo n.º 5
0
 def test_gmail_invalid(self):  #Gmail Invalid
     form = CreateUserForm(
         data={
             'username': '******',
             'first_name': 'gurjar',
             'email': 'piyushgurjar',
             'password1': 'piyush123',
             'password2': 'piyush123'
         })
     self.assertFalse(form.is_valid())
Exemplo n.º 6
0
 def test_password_entirely_numeric(self):
     form = CreateUserForm(
         data={
             'username': '******',
             'first_name': 'doe',
             'last_name': 'doe',
             'password1': '1234567890',
             'password2': '1234567890'
         })
     self.assertFalse(form.is_valid())
Exemplo n.º 7
0
 def test_valid(self):  #Valid Deatails
     form = CreateUserForm(
         data={
             'username': '******',
             'first_name': 'gurjar',
             'email': '*****@*****.**',
             'password1': 'piyush123',
             'password2': 'piyush123'
         })
     self.assertTrue(form.is_valid())
Exemplo n.º 8
0
 def test_password_size(self):  #Password Too Small
     form = CreateUserForm(
         data={
             'username': '******',
             'first_name': 'gurjar',
             'email': '*****@*****.**',
             'password1': 'p',
             'password2': 'p'
         })
     self.assertFalse(form.is_valid())
Exemplo n.º 9
0
 def test_password_mismatch(self):  #Password Mismatch
     form = CreateUserForm(
         data={
             'username': '******',
             'first_name': 'gurjar',
             'email': '*****@*****.**',
             'password1': 'piyush1233',
             'password2': 'piyush123'
         })
     self.assertFalse(form.is_valid())
Exemplo n.º 10
0
 def test_username_password_similarity(
         self):  #Password Is to similiar to username
     form = CreateUserForm(
         data={
             'username': '******',
             'first_name': 'piyush',
             'email': '*****@*****.**',
             'password1': 'piyush123',
             'password2': 'piyush123'
         })
     self.assertFalse(form.is_valid())
Exemplo n.º 11
0
 def test_password_different(self):
     form = CreateUserForm(
         data={
             'username': '******',
             'first_name': 'doe',
             'last_name': 'doe',
             'password1': 'super_strong123',
             'password2': 'f'
         })
     self.assertFalse(form.is_valid())
     self.assertEqual(form["password2"].errors,
                      [str(form.error_messages['password_mismatch'])])
Exemplo n.º 12
0
def register(request):
    form = CreateUserForm()
    if request.method == "POST":
        form = CreateUserForm(data=request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            messages.success(request, 'Registration successfull for ' + username)
            return redirect('login_page')

    context = {"form": form}
    return render(request, 'register.html', context)
Exemplo n.º 13
0
def registerPage(request):
    if request.user.is_authenticated:
        return redirect('home')
    form = CreateUserForm()
    if request.method == 'POST':

        form = CreateUserForm(request.POST)

        if form.is_valid():
            form.save()
            return redirect('login')

    context = {'form': form}
    return render(request, 'main/register.html', context)
Exemplo n.º 14
0
    def test_empty_fields(self):  #Empty Fields Check
        form = CreateUserForm(data={})

        self.assertFalse(form.is_valid())
        self.assertEquals(len(form.errors), 3)