forked from hacklabr/timtec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
45 lines (32 loc) · 967 Bytes
/
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
import pytest
def create_user(username):
"""A Django common user"""
email = username + '@example.com'
password = 'password'
from django.contrib.auth import get_user_model
User = get_user_model()
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
user = User.objects.create_user(username, email, password)
if username == 'admintest':
user.is_staff = True
user.is_superuser = True
user.save()
return user
@pytest.fixture()
def admin_user(db):
"""A Django test admin user"""
user = create_user('admintest')
return user
@pytest.fixture()
def admin_client(db):
"""A Django admin user"""
from django.test.client import Client
user = create_user('admintest')
client = Client()
client.login(username=user.username, password='password')
return client
@pytest.fixture()
def user(db):
return create_user('common')