Web service voor het LED-display
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.5 KiB

11 years ago
# -*- coding: utf-8 -*-
"""Test forms."""
11 years ago
from {{cookiecutter.app_name}}.public.forms import LoginForm
from {{cookiecutter.app_name}}.user.forms import RegisterForm
11 years ago
class TestRegisterForm:
"""Register form."""
11 years ago
def test_validate_user_already_registered(self, user):
"""Enter username that is already registered."""
form = RegisterForm(
username=user.username,
email="foo@bar.com",
password="example",
confirm="example",
)
11 years ago
assert form.validate() is False
assert "Username already registered" in form.username.errors
11 years ago
def test_validate_email_already_registered(self, user):
"""Enter email that is already registered."""
form = RegisterForm(
username="unique", email=user.email, password="example", confirm="example"
)
11 years ago
assert form.validate() is False
assert "Email already registered" in form.email.errors
11 years ago
def test_validate_success(self, db):
"""Register with success."""
form = RegisterForm(
username="newusername",
email="new@test.test",
password="example",
confirm="example",
)
11 years ago
assert form.validate() is True
class TestLoginForm:
"""Login form."""
11 years ago
def test_validate_success(self, user):
"""Login successful."""
user.set_password("example")
11 years ago
user.save()
form = LoginForm(username=user.username, password="example")
11 years ago
assert form.validate() is True
assert form.user == user
def test_validate_unknown_username(self, db):
"""Unknown username."""
form = LoginForm(username="unknown", password="example")
11 years ago
assert form.validate() is False
assert "Unknown username" in form.username.errors
11 years ago
assert form.user is None
def test_validate_invalid_password(self, user):
"""Invalid password."""
user.set_password("example")
11 years ago
user.save()
form = LoginForm(username=user.username, password="wrongpassword")
11 years ago
assert form.validate() is False
assert "Invalid password" in form.password.errors
11 years ago
def test_validate_inactive_user(self, user):
"""Inactive user."""
11 years ago
user.active = False
user.set_password("example")
11 years ago
user.save()
# Correct username and password, but user is not activated
form = LoginForm(username=user.username, password="example")
11 years ago
assert form.validate() is False
assert "User not activated" in form.username.errors