83 lines
1.8 KiB
Python
83 lines
1.8 KiB
Python
import logging
|
|
import pytest
|
|
import django_webtest
|
|
from django.contrib.auth.models import User
|
|
|
|
|
|
class WebTestMixin(django_webtest.WebTestMixin):
|
|
csrf_checks = False
|
|
|
|
@pytest.fixture
|
|
def app(request):
|
|
wtm = WebTestMixin()
|
|
wtm._patch_settings()
|
|
request.addfinalizer(wtm._unpatch_settings)
|
|
return django_webtest.DjangoTestApp()
|
|
|
|
|
|
@pytest.fixture
|
|
def concurrency(settings):
|
|
'''Select a level of concurrency based on the db, sqlite3 is less robust
|
|
thant postgres due to its transaction lock timeout of 5 seconds.
|
|
'''
|
|
if 'sqlite' in settings.DATABASES['default']['ENGINE']:
|
|
return 20
|
|
else:
|
|
return 100
|
|
|
|
|
|
@pytest.fixture
|
|
def private_settings(request):
|
|
import django.conf
|
|
from django.conf import UserSettingsHolder
|
|
old = django.conf.settings._wrapped
|
|
django.conf.settings._wrapped = UserSettingsHolder(old)
|
|
|
|
def finalizer():
|
|
django.conf.settings._wrapped = old
|
|
request.addfinalizer(finalizer)
|
|
return django.conf.settings
|
|
|
|
|
|
@pytest.fixture
|
|
def caplog(caplog):
|
|
import py.io
|
|
caplog.setLevel(logging.INFO)
|
|
caplog.handler.stream = py.io.TextIO()
|
|
caplog.handler.records = []
|
|
return caplog
|
|
|
|
|
|
@pytest.fixture
|
|
def john_doe(db):
|
|
user = User(
|
|
username='john.doe',
|
|
first_name='John',
|
|
last_name='Doe',
|
|
email='john.doe@example.com')
|
|
user.set_password('john.doe')
|
|
user.save()
|
|
return user
|
|
|
|
|
|
@pytest.fixture
|
|
def jane_doe(db):
|
|
user = User(
|
|
username='jane.doe',
|
|
first_name='Jane',
|
|
last_name='Doe',
|
|
email='jane.doe@example.com')
|
|
user.set_password('jane.doe')
|
|
user.save()
|
|
return user
|
|
|
|
|
|
@pytest.fixture
|
|
def admin_user(db):
|
|
try:
|
|
user = User.objects.get(username='admin')
|
|
except User.DoesNotExist:
|
|
user = User.objects.create_superuser('admin', email=None, password='admin')
|
|
return user
|
|
|