This repository has been archived by the owner on Jul 5, 2019. It is now read-only.
forked from opbeat/opbeat_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
109 lines (96 loc) · 3.52 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
import sys
from os.path import abspath, dirname, join
where_am_i = dirname(abspath(__file__))
BASE_TEMPLATE_DIR = join(where_am_i, 'tests', 'contrib', 'django', 'testapp',
'templates')
sys.path.insert(0, where_am_i)
# don't run tests of dependencies that land in "build" and "src"
collect_ignore = ['build', 'src']
try:
from psycopg2cffi import compat
compat.register()
except ImportError:
pass
def pytest_configure(config):
try:
from django.conf import settings
except ImportError:
settings = None
if settings is not None and not settings.configured:
import django
if django.VERSION >= (2, 0):
middleware_settings_name = 'MIDDLEWARE'
else:
middleware_settings_name = 'MIDDLEWARE_CLASSES'
# django-celery does not work well with Django 1.8+
if django.VERSION < (1, 8):
djcelery = ['djcelery']
else:
djcelery = []
settings_dict = dict(
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'opbeat_tests.db',
'TEST_NAME': 'opbeat_tests.db',
'TEST': {
'NAME': 'opbeat_tests.db',
}
},
},
TEST_DATABASE_NAME='opbeat_tests.db',
INSTALLED_APPS=[
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.redirects',
'django.contrib.contenttypes',
'opbeat.contrib.django',
'tests.contrib.django.testapp',
] + djcelery,
ROOT_URLCONF='tests.contrib.django.testapp.urls',
DEBUG=False,
SITE_ID=1,
BROKER_HOST="localhost",
BROKER_PORT=5672,
BROKER_USER="guest",
BROKER_PASSWORD="guest",
BROKER_VHOST="/",
CELERY_ALWAYS_EAGER=True,
TEMPLATE_DEBUG=False,
TEMPLATE_DIRS=[BASE_TEMPLATE_DIR],
ALLOWED_HOSTS=['*'],
MIDDLEWARE_CLASSES=[
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
],
TEMPLATES=[
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_TEMPLATE_DIR],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
],
'loaders': [
'django.template.loaders.filesystem.Loader',
],
'debug': False,
},
},
]
)
settings_dict[middleware_settings_name] = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
]
settings.configure(**settings_dict)
if hasattr(django, 'setup'):
django.setup()
if django.VERSION < (1, 8):
import djcelery
djcelery.setup_loader()