-
Notifications
You must be signed in to change notification settings - Fork 81
/
conftest.py
32 lines (23 loc) · 995 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
import pytest
from django_webtest import DjangoTestApp, WebTestMixin
class OurTestApp(DjangoTestApp):
def __init__(self, *args, **kwargs):
self.default_user = kwargs.pop('default_user', None)
super(OurTestApp, self).__init__(*args, **kwargs)
def get(self, *args, **kwargs):
kwargs.setdefault('user', self.default_user)
kwargs.setdefault('auto_follow', True)
return super(OurTestApp, self).get(*args, **kwargs)
@pytest.fixture(scope='function')
def app(request, admin_user):
"""WebTest's TestApp.
Patch and unpatch settings before and after each test.
WebTestMixin, when used in a unittest.TestCase, automatically calls
_patch_settings() and _unpatchsettings.
source: https://gist.github.com/magopian/6673250
"""
wtm = WebTestMixin()
wtm._patch_settings()
request.addfinalizer(wtm._unpatch_settings)
# XXX change this admin user to "saploper"
return OurTestApp(default_user=admin_user.username)