Skip to content

Commit 7fbbfe2

Browse files
authored
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
1 parent fe840a3 commit 7fbbfe2

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ matrix:
1414
- { python: "3.6", env: DJANGO=2.0 }
1515
- { python: "3.6", env: DJANGO=2.1 }
1616
- { python: "3.6", env: DJANGO=2.2 }
17+
- { python: "3.6", env: DJANGO=3.0 }
1718
- { python: "3.6", env: DJANGO=master }
1819

1920
- { python: "3.7", env: DJANGO=2.0 }
2021
- { python: "3.7", env: DJANGO=2.1 }
2122
- { python: "3.7", env: DJANGO=2.2 }
23+
- { python: "3.7", env: DJANGO=3.0 }
2224
- { python: "3.7", env: DJANGO=master }
2325

26+
- { python: "3.8", env: DJANGO=3.0 }
2427
- { python: "3.8", env: DJANGO=master }
2528

2629
- { python: "3.8", env: TOXENV=base }

requirements/requirements-optionals.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
psycopg2-binary>=2.8.2, <2.9
33
markdown==3.1.1
44
pygments==2.4.2
5-
django-guardian==1.5.0
5+
django-guardian==2.1.0
66
django-filter>=2.2.0, <2.3
77
coreapi==2.3.1
88
coreschema==0.0.4

tests/conftest.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,22 @@ def pytest_configure(config):
6767
)
6868

6969
# guardian is optional
70-
try:
71-
import guardian # NOQA
72-
except ImportError:
73-
pass
74-
else:
75-
settings.ANONYMOUS_USER_ID = -1
76-
settings.AUTHENTICATION_BACKENDS = (
77-
'django.contrib.auth.backends.ModelBackend',
78-
'guardian.backends.ObjectPermissionBackend',
79-
)
80-
settings.INSTALLED_APPS += (
81-
'guardian',
82-
)
70+
# Note that for the test cases we're installing a version of django-guardian
71+
# that's only compatible with Django 2.0+.
72+
if django.VERSION >= (2, 0, 0):
73+
try:
74+
import guardian # NOQA
75+
except ImportError:
76+
pass
77+
else:
78+
settings.ANONYMOUS_USER_ID = -1
79+
settings.AUTHENTICATION_BACKENDS = (
80+
'django.contrib.auth.backends.ModelBackend',
81+
'guardian.backends.ObjectPermissionBackend',
82+
)
83+
settings.INSTALLED_APPS += (
84+
'guardian',
85+
)
8386

8487
if config.getoption('--no-pkgroot'):
8588
sys.path.pop(0)

tests/test_relations.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,12 @@ def test_pk_representation(self):
145145
assert representation == self.instance.pk.int
146146

147147

148-
@override_settings(ROOT_URLCONF=[
148+
urlpatterns = [
149149
url(r'^example/(?P<name>.+)/$', lambda: None, name='example'),
150-
])
150+
]
151+
152+
153+
@override_settings(ROOT_URLCONF='tests.test_relations')
151154
class TestHyperlinkedRelatedField(APISimpleTestCase):
152155
def setUp(self):
153156
self.queryset = MockQueryset([

tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ envlist =
44
{py35,py36,py37}-django20,
55
{py35,py36,py37}-django21
66
{py35,py36,py37}-django22
7+
{py36,py37,py38}-django30,
78
{py36,py37,py38}-djangomaster,
89
base,dist,lint,docs,
910

@@ -13,6 +14,7 @@ DJANGO =
1314
2.0: django20
1415
2.1: django21
1516
2.2: django22
17+
3.0: django30
1618
master: djangomaster
1719

1820
[testenv]
@@ -26,6 +28,7 @@ deps =
2628
django20: Django>=2.0,<2.1
2729
django21: Django>=2.1,<2.2
2830
django22: Django>=2.2,<3.0
31+
django30: Django==3.0rc1
2932
djangomaster: https://github.com/django/django/archive/master.tar.gz
3033
-rrequirements/requirements-testing.txt
3134
-rrequirements/requirements-optionals.txt

0 commit comments

Comments
 (0)