This repository has been archived by the owner on Apr 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
conftest.py
84 lines (62 loc) · 2.2 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import pytest
from django.conf import settings
from pytest_django.lazy_django import django_settings_is_configured
def pytest_addoption(parser):
parser.addoption("--collectstatic", action="store_true",
help="run slow collectstatic test")
@pytest.fixture(autouse=True, scope='session')
def _django_test_environment(request):
"""
overwrite pytest_django/plugin.py
"""
if django_settings_is_configured():
from django.conf import settings
from pytest_django.compat import (setup, setup_test_environment,
teardown_test_environment)
settings.DEBUG = True # OVERWRITEN CONFIG
setup()
setup_test_environment()
request.addfinalizer(teardown_test_environment)
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)
user.accepted_terms = True
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')
@pytest.fixture()
def timbrowser(browser, live_server):
browser.url = unicode(live_server)
browser.live_server = live_server
return browser
def pytest_configure():
# removes django debug toolbar that was interfering with tests
settings.INTERNAL_IPS = ('',)
# workaround to avoid django pipeline issue
# refers to https://github.com/cyberdelia/django-pipeline/issues/277
settings.STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'