Commit b215bb91 authored by Cornee Traas's avatar Cornee Traas
Browse files

Add docstrings to some tests

parent dde7ab5d
......@@ -10,6 +10,9 @@ def test_email_is_username():
@pytest.mark.django_db
def test_can_create_user():
"""
Test that a new normal user can be created.
"""
user = User.objects.create_user("test_user@example.com", "password")
assert user.email == "test_user@example.com", "email is set incorrectly"
assert user.check_password("password"), "password is set incorreclty"
......@@ -17,18 +20,27 @@ def test_can_create_user():
@pytest.mark.django_db
def test_can_create_superuser():
"""
Test that a new superuser (admin) can be created.
"""
user = User.objects.create_superuser("admin@example.com", "password")
assert user.is_superuser, "user is not a superuser"
@pytest.mark.django_db
def test_superuser_must_be_staff():
"""
Test that a new superuser (admin) must be a staff member.
"""
with pytest.raises(ValueError):
User.objects.create_superuser("admin@example.com", "password", is_staff=False)
@pytest.mark.django_db
def test_superuser_must_be_superuser():
"""
Test that a new superuser (admin) must have the flag superuser.
"""
with pytest.raises(ValueError):
User.objects.create_superuser(
"admin@example.com", "password", is_superuser=False
......@@ -37,9 +49,15 @@ def test_superuser_must_be_superuser():
@pytest.mark.django_db
def test_user_can_login(user):
"""
Test that an existing user can log in.
"""
assert user.check_password("password"), "password is incorrect"
@pytest.mark.django_db
def test_application_exists():
"""
Test that the Application object exists.
"""
assert Application.objects.exists(), "application is not created"
......@@ -9,6 +9,9 @@ from users.serializers import PasswordResetSerializer, UserSerializer
@pytest.mark.django_db
def test_serialize_user(user):
"""
Test that all properties of the User model are serialized correctly.
"""
assert UserSerializer(user).data == {
"pk": user.pk,
"email": "john.doe@example.com",
......@@ -21,6 +24,9 @@ def test_serialize_user(user):
@pytest.mark.django_db
def test_validate_token(user):
"""
Test that the server can create valid password reset tokens.
"""
token = default_token_generator.make_token(user)
serializer = PasswordResetSerializer(instance=user)
assert serializer.validate_token(token) == token, "token validation failed"
......@@ -30,6 +36,9 @@ def test_validate_token(user):
@pytest.mark.django_db
def test_validate_password(user):
"""
Test that the password requirements validator works.
"""
serializer = PasswordResetSerializer(instance=user)
assert (
serializer.validate_password("JzS@*4682JP#%a#uT3QQvndf")
......@@ -45,6 +54,9 @@ def test_validate_password(user):
@pytest.mark.django_db
def test_update_password(user):
"""
Test that a changed password is updated in the model, and saved to the database.
"""
serializer = PasswordResetSerializer()
user = serializer.update(user, {"password": "new_password"})
assert user.check_password("new_password"), "password was not updated"
......
......@@ -2,4 +2,7 @@ from django.urls import reverse
def test_admin_urls_are_configured():
"""
Test that the admin urls exist.
"""
assert reverse("admin:index") == "/admin/", "admin urls are not configured"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment