Browse Source

Simplifica conf do webtest (refatoração)

pull/313/head
Marcio Mazza 9 years ago
parent
commit
8d3285625b
  1. 28
      conftest.py

28
conftest.py

@ -1,27 +1,17 @@
import pytest
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,
default_user=None):
super(SaplTestApp, self).__init__(extra_environ, relative_to)
self.default_user = default_user
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)
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')
@ -39,4 +29,4 @@ def app(request, admin_user):
wtm._patch_settings()
request.addfinalizer(wtm._unpatch_settings)
# XXX change this admin user to "saploper"
return SaplTestApp(default_user=admin_user.username)
return OurTestApp(default_user=admin_user.username)

Loading…
Cancel
Save