Exemplo n.º 1
0
    def test_clean_username_success(self):
        # Instantiate the form with a new username
        form = MyUserCreationForm({
            "username": "******",
            "password1": "7jefB#f@Cc7YJB]2v",
            "password2": "7jefB#f@Cc7YJB]2v",
        })
        # Run is_valid() to trigger the validation
        valid = form.is_valid()
        self.assertTrue(valid)

        # Run the actual clean_username method
        username = form.clean_username()
        self.assertEqual("alamode", username)
    def test_clean_username_success(self):
        # Instantiate the form with a new username
        form = MyUserCreationForm({
            'username': '******',
            'password1': '123456',
            'password2': '123456',
        })
        # Run is_valid() to trigger the validation
        valid = form.is_valid()
        self.assertTrue(valid)

        # Run the actual clean_username method
        username = form.clean_username()
        self.assertEqual('alamode', username)
    def test_clean_username_false(self):
        # Instantiate the form with the same username as self.user
        form = MyUserCreationForm({
            'username': self.user.username,
            'password1': '123456',
            'password2': '123456',
        })
        # Run is_valid() to trigger the validation, which is going to fail
        # because the username is already taken
        valid = form.is_valid()
        self.assertFalse(valid)

        # The form.errors dict should contain a single error called 'username'
        self.assertTrue(len(form.errors) == 1)
        self.assertTrue('username' in form.errors)
Exemplo n.º 4
0
def test__my_user_creation_form__clean_username_success():
    """Tests that clean username validation works as expected."""
    # Instantiate the form with a new username
    form = MyUserCreationForm({
        'username': '******',
        'password1': '7jefB#f@Cc7YJB]2v',
        'password2': '7jefB#f@Cc7YJB]2v',
    })
    # Run is_valid() to trigger the validation
    valid = form.is_valid()

    # Run the actual clean_username method
    username = form.clean_username()

    assert valid
    assert username == 'alamode'
Exemplo n.º 5
0
def test__my_user_creation_form__clean_username_false(user):
    """Tests that clean_username fails when username already taken."""
    # Instantiate the form with the same username as self.user
    form = MyUserCreationForm({
        'username': user.username,
        'password1': 'notalamodespassword',
        'password2': 'notalamodespassword',
    })
    # Run is_valid() to trigger the validation, which is going to fail
    # because the username is already taken
    valid = form.is_valid()

    # The form.errors dict should contain a single error called 'username'
    assert valid is False
    assert len(form.errors) == 1
    assert 'username' in form.errors
Exemplo n.º 6
0
def register(request):
    if request.method == 'POST':
        form = MyUserCreationForm(request.POST)

        if form.is_valid():
            form.save()

            return HttpResponseRedirect(reverse('users:login'))
    else:
        form = MyUserCreationForm()

    return render(request, 'users/register.html', {'form': form})
Exemplo n.º 7
0
Arquivo: views.py Projeto: duluman/bis
def ro_register(request):
    # current_site = Site.objects.get_current()

    if request.method == 'POST':
        form = MyUserCreationForm(request.POST)

        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('users:login'))
    else:
        form = MyUserCreationForm()

    return render(request, 'users/register.html', {
                        # 'host': current_site.domain,
                        'form': form
                   })