Files
website-v2/users/tests/fixtures.py
Natalia 06cd04f263 Expose view for user preferences (email notifications so far).
Added tests for the new form and view for updating user preferences.
2023-06-20 12:24:40 -03:00

71 lines
1.5 KiB
Python

import pytest
from django.utils import timezone
from model_bakery import baker
@pytest.fixture
def user(db):
"""Regular website user"""
user = baker.make(
"users.User",
email="user@example.com",
first_name="Regular",
last_name="User",
last_login=timezone.now(),
image="static/img/fpo/user.png",
)
user.set_password("password")
user.save()
return user
@pytest.fixture
def staff_user(db):
"""Staff website user with access to the Django admin"""
user = baker.make(
"users.User",
email="staff@example.com",
first_name="Staff",
last_name="User",
last_login=timezone.now(),
is_staff=True,
image="static/img/fpo/user.png",
)
user.set_password("password")
user.save()
return user
@pytest.fixture
def super_user(db):
"""Superuser with access to everything"""
user = baker.make(
"users.User",
email="super@example.com",
first_name="Super",
last_name="User",
last_login=timezone.now(),
is_staff=True,
is_superuser=True,
image="static/img/fpo/user.png",
)
user.set_password("password")
user.save()
return user
@pytest.fixture
def assert_messages():
def _assert_and_fetch(response, expected):
messages = [
(m.level_tag, m.message) for m in response.context.get("messages", [])
]
assert messages == expected
return _assert_and_fetch