Django 3 compat (#7058)

* First pass at Django 3.0 compat

* Drop Guardian for 1.11 tests, since we're installing an incompatible version

* Fix ROOT_URLCONF override in test case

* Fix typo

Co-Authored-By: Rémy HUBSCHER <hubscher.remy@gmail.com>

* Linting
This commit is contained in:
Tom Christie 2019-11-21 11:55:53 +00:00 committed by GitHub
parent fe840a34ff
commit 7fbbfe2c60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 16 deletions

View File

@ -14,13 +14,16 @@ matrix:
- { python: "3.6", env: DJANGO=2.0 }
- { python: "3.6", env: DJANGO=2.1 }
- { python: "3.6", env: DJANGO=2.2 }
- { python: "3.6", env: DJANGO=3.0 }
- { python: "3.6", env: DJANGO=master }
- { python: "3.7", env: DJANGO=2.0 }
- { python: "3.7", env: DJANGO=2.1 }
- { python: "3.7", env: DJANGO=2.2 }
- { python: "3.7", env: DJANGO=3.0 }
- { python: "3.7", env: DJANGO=master }
- { python: "3.8", env: DJANGO=3.0 }
- { python: "3.8", env: DJANGO=master }
- { python: "3.8", env: TOXENV=base }

View File

@ -2,7 +2,7 @@
psycopg2-binary>=2.8.2, <2.9
markdown==3.1.1
pygments==2.4.2
django-guardian==1.5.0
django-guardian==2.1.0
django-filter>=2.2.0, <2.3
coreapi==2.3.1
coreschema==0.0.4

View File

@ -67,19 +67,22 @@ def pytest_configure(config):
)
# guardian is optional
try:
import guardian # NOQA
except ImportError:
pass
else:
settings.ANONYMOUS_USER_ID = -1
settings.AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'guardian.backends.ObjectPermissionBackend',
)
settings.INSTALLED_APPS += (
'guardian',
)
# Note that for the test cases we're installing a version of django-guardian
# that's only compatible with Django 2.0+.
if django.VERSION >= (2, 0, 0):
try:
import guardian # NOQA
except ImportError:
pass
else:
settings.ANONYMOUS_USER_ID = -1
settings.AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'guardian.backends.ObjectPermissionBackend',
)
settings.INSTALLED_APPS += (
'guardian',
)
if config.getoption('--no-pkgroot'):
sys.path.pop(0)

View File

@ -145,9 +145,12 @@ class TestProxiedPrimaryKeyRelatedField(APISimpleTestCase):
assert representation == self.instance.pk.int
@override_settings(ROOT_URLCONF=[
urlpatterns = [
url(r'^example/(?P<name>.+)/$', lambda: None, name='example'),
])
]
@override_settings(ROOT_URLCONF='tests.test_relations')
class TestHyperlinkedRelatedField(APISimpleTestCase):
def setUp(self):
self.queryset = MockQueryset([

View File

@ -4,6 +4,7 @@ envlist =
{py35,py36,py37}-django20,
{py35,py36,py37}-django21
{py35,py36,py37}-django22
{py36,py37,py38}-django30,
{py36,py37,py38}-djangomaster,
base,dist,lint,docs,
@ -13,6 +14,7 @@ DJANGO =
2.0: django20
2.1: django21
2.2: django22
3.0: django30
master: djangomaster
[testenv]
@ -26,6 +28,7 @@ deps =
django20: Django>=2.0,<2.1
django21: Django>=2.1,<2.2
django22: Django>=2.2,<3.0
django30: Django==3.0rc1
djangomaster: https://github.com/django/django/archive/master.tar.gz
-rrequirements/requirements-testing.txt
-rrequirements/requirements-optionals.txt