forked from Silvian/bookworm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
50 lines (35 loc) · 1.12 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Pytest fixtures and setup for tests."""
import pytest
from django.utils.translation import activate
from rest_framework.test import APIClient
from authentication.test import UserFactory
@pytest.fixture(autouse=True)
def set_default_language():
"""Unless otherwise specified set the localisation to English."""
activate('en')
@pytest.fixture(autouse=True)
def enable_db_access_for_all_tests(db):
"""Automatically support database access to any tests requiring."""
pass
@pytest.fixture
def profile():
"""Normal user and profile account."""
user = UserFactory()
return user.profile
@pytest.fixture
def profile_admin():
"""Administration user and profile."""
user = UserFactory(is_superuser=True)
return user.profile
@pytest.fixture
def client_profile(profile):
"""API Client authenticated as a user."""
client = APIClient()
client.force_authenticate(profile.user)
return client
@pytest.fixture
def client_admin(profile_admin):
"""API Client authenticated as an administrator."""
client = APIClient()
client.force_authenticate(profile_admin.user)
return client