Exemple #1
0
    def test_existing_username(self):
        test_data = {'username': '******', 'password': '******'}

        form = UserForm(data=test_data)
        self.assertEqual(form.errors['username'],
                         ["Пользователь с таким именем уже существует"])
        self.assertFalse(form.is_valid())
Exemple #2
0
 def test_invalid_password(self):
     test_data = {'username': '******', 'password': '******'}
     form = UserForm(data=test_data)
     self.assertEqual(
         form.errors['password'],
         ["Убедитесь, что значение содержит больше 3 символов  (их 1)."])
     self.assertFalse(form.is_valid())
Exemple #3
0
    def test_too_long_username(self):
        test_data = {'username': '******', 'password': '******'}

        form = UserForm(data=test_data)
        self.assertEqual(
            form.errors['username'],
            ["Убедитесь, что значение содержит меньше 12 символов (их 13)."])
        self.assertFalse(form.is_valid())
Exemple #4
0
 def test_invalid_username(self):
     test_data = {'username': '******', 'password': '******'}
     form = UserForm(data=test_data)
     self.assertEqual(
         form.errors['username'],
         ["Это значение может содержать буквы, "
          "цифры и знак _."])
Exemple #5
0
def register(request):
    """
    Handles user registration using UserForm from forms.py
    Creates new User and new RedditUser models if appropriate data
    has been supplied.

    If account has been created user is redirected to login page.
    """
    user_form = UserForm()
    if request.user.is_authenticated():
        messages.warning(request, 'Вы уже зарегистрированы и вошли')
        return render(request, 'public/register.html', {'form': user_form})

    if request.method == "POST":
        user_form = UserForm(request.POST)

        if user_form.is_valid():
            if user_form.cleaned_data["password"] != user_form.cleaned_data[
                    "rep_password"]:
                messages.error(request, 'пароли не совпадают')
            else:
                print(user_form.cleaned_data["keyWord"])
                if user_form.cleaned_data["keyWord"] == REG_PASSWORD:

                    print("complete")
                    user = user_form.save()
                    user.set_password(user.password)
                    user.save()
                    reddit_user = ScUser()
                    reddit_user.user = user
                    reddit_user.save()
                    user = authenticate(username=request.POST['username'],
                                        password=request.POST['password'])
                    login(request, user)
                    return redirect('frontpage')
                else:
                    messages.warning(request, 'Неправильный ключ')
                    pass

    return render(request, 'public/register.html', {'form': user_form})
Exemple #6
0
 def test_missing_password(self):
     test_data = {'username': '******'}
     form = UserForm(data=test_data)
     self.assertEqual(form.errors['password'], ["This field is required."])
Exemple #7
0
 def test_missing_username(self):
     test_data = {'password': '******'}
     form = UserForm(data=test_data)
     self.assertEqual(form.errors['username'], ["Это поле обязательно."])
Exemple #8
0
 def test_valid_form(self):
     test_data = {'username': '******', 'password': '******'}
     form = UserForm(data=test_data)
     self.assertTrue(form.is_valid())