From 8d3285625b27b21f0889fb36f90adae857bc9a69 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Thu, 14 Apr 2016 18:26:11 -0300 Subject: [PATCH] =?UTF-8?q?Simplifica=20conf=20do=20webtest=20(refatora?= =?UTF-8?q?=C3=A7=C3=A3o)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conftest.py | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/conftest.py b/conftest.py index 17bacd6d8..62064338e 100644 --- a/conftest.py +++ b/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)