|
@ -1,27 +1,17 @@ |
|
|
import pytest |
|
|
import pytest |
|
|
from django_webtest import DjangoTestApp, WebTestMixin |
|
|
from django_webtest import DjangoTestApp, WebTestMixin |
|
|
|
|
|
|
|
|
DEFAULT_MARK = object() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OurTestApp(DjangoTestApp): |
|
|
|
|
|
|
|
|
class SaplTestApp(DjangoTestApp): |
|
|
def __init__(self, *args, **kwargs): |
|
|
|
|
|
self.default_user = kwargs.pop('default_user', None) |
|
|
|
|
|
super(OurTestApp, self).__init__(*args, **kwargs) |
|
|
|
|
|
|
|
|
def __init__(self, extra_environ=None, relative_to=None, |
|
|
def get(self, *args, **kwargs): |
|
|
default_user=None): |
|
|
kwargs.setdefault('user', self.default_user) |
|
|
super(SaplTestApp, self).__init__(extra_environ, relative_to) |
|
|
kwargs.setdefault('auto_follow', True) |
|
|
self.default_user = default_user |
|
|
return super(OurTestApp, self).get(*args, **kwargs) |
|
|
|
|
|
|
|
|
def get(self, url, params=None, headers=None, extra_environ=None, |
|
|
|
|
|
status=None, expect_errors=False, user=DEFAULT_MARK, |
|
|
|
|
|
auto_follow=True, content_type=None, **kwargs): |
|
|
|
|
|
# note we altered the default values for user and auto_follow |
|
|
|
|
|
|
|
|
|
|
|
if user is DEFAULT_MARK: # a trick to allow explicit user=None |
|
|
|
|
|
user = self.default_user |
|
|
|
|
|
|
|
|
|
|
|
return super(SaplTestApp, self).get( |
|
|
|
|
|
url, params, headers, extra_environ, status, expect_errors, user, |
|
|
|
|
|
auto_follow, content_type, **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='function') |
|
|
@pytest.fixture(scope='function') |
|
@ -39,4 +29,4 @@ def app(request, admin_user): |
|
|
wtm._patch_settings() |
|
|
wtm._patch_settings() |
|
|
request.addfinalizer(wtm._unpatch_settings) |
|
|
request.addfinalizer(wtm._unpatch_settings) |
|
|
# XXX change this admin user to "saploper" |
|
|
# XXX change this admin user to "saploper" |
|
|
return SaplTestApp(default_user=admin_user.username) |
|
|
return OurTestApp(default_user=admin_user.username) |
|
|