mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 01:26:53 +03:00
Dropped test compatibility shims for Django <2.2. (#7523)
This commit is contained in:
parent
d5461e93fe
commit
9990b59281
|
@ -67,22 +67,19 @@ def pytest_configure(config):
|
||||||
)
|
)
|
||||||
|
|
||||||
# guardian is optional
|
# guardian is optional
|
||||||
# Note that for the test cases we're installing a version of django-guardian
|
try:
|
||||||
# that's only compatible with Django 2.0+.
|
import guardian # NOQA
|
||||||
if django.VERSION >= (2, 0, 0):
|
except ImportError:
|
||||||
try:
|
pass
|
||||||
import guardian # NOQA
|
else:
|
||||||
except ImportError:
|
settings.ANONYMOUS_USER_ID = -1
|
||||||
pass
|
settings.AUTHENTICATION_BACKENDS = (
|
||||||
else:
|
'django.contrib.auth.backends.ModelBackend',
|
||||||
settings.ANONYMOUS_USER_ID = -1
|
'guardian.backends.ObjectPermissionBackend',
|
||||||
settings.AUTHENTICATION_BACKENDS = (
|
)
|
||||||
'django.contrib.auth.backends.ModelBackend',
|
settings.INSTALLED_APPS += (
|
||||||
'guardian.backends.ObjectPermissionBackend',
|
'guardian',
|
||||||
)
|
)
|
||||||
settings.INSTALLED_APPS += (
|
|
||||||
'guardian',
|
|
||||||
)
|
|
||||||
|
|
||||||
if config.getoption('--no-pkgroot'):
|
if config.getoption('--no-pkgroot'):
|
||||||
sys.path.pop(0)
|
sys.path.pop(0)
|
||||||
|
|
|
@ -456,7 +456,6 @@ class TestSchemaGenerator(TestCase):
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(coreapi, 'coreapi is not installed')
|
@unittest.skipUnless(coreapi, 'coreapi is not installed')
|
||||||
@unittest.skipUnless(path, 'needs Django 2')
|
|
||||||
@override_settings(REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.AutoSchema'})
|
@override_settings(REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.AutoSchema'})
|
||||||
class TestSchemaGeneratorDjango2(TestCase):
|
class TestSchemaGeneratorDjango2(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
@ -12,7 +12,6 @@ import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
import django
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.core.serializers.json import DjangoJSONEncoder
|
from django.core.serializers.json import DjangoJSONEncoder
|
||||||
|
@ -63,7 +62,7 @@ class RegularFieldsModel(models.Model):
|
||||||
email_field = models.EmailField(max_length=100)
|
email_field = models.EmailField(max_length=100)
|
||||||
float_field = models.FloatField()
|
float_field = models.FloatField()
|
||||||
integer_field = models.IntegerField()
|
integer_field = models.IntegerField()
|
||||||
null_boolean_field = models.NullBooleanField()
|
null_boolean_field = models.BooleanField(null=True, default=False)
|
||||||
positive_integer_field = models.PositiveIntegerField()
|
positive_integer_field = models.PositiveIntegerField()
|
||||||
positive_small_integer_field = models.PositiveSmallIntegerField()
|
positive_small_integer_field = models.PositiveSmallIntegerField()
|
||||||
slug_field = models.SlugField(max_length=100)
|
slug_field = models.SlugField(max_length=100)
|
||||||
|
@ -218,25 +217,6 @@ class TestRegularFieldMappings(TestCase):
|
||||||
""")
|
""")
|
||||||
self.assertEqual(repr(TestSerializer()), expected)
|
self.assertEqual(repr(TestSerializer()), expected)
|
||||||
|
|
||||||
# merge this into test_regular_fields / RegularFieldsModel when
|
|
||||||
# Django 2.1 is the minimum supported version
|
|
||||||
@pytest.mark.skipif(django.VERSION < (2, 1), reason='Django version < 2.1')
|
|
||||||
def test_nullable_boolean_field(self):
|
|
||||||
class NullableBooleanModel(models.Model):
|
|
||||||
field = models.BooleanField(null=True, default=False)
|
|
||||||
|
|
||||||
class NullableBooleanSerializer(serializers.ModelSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = NullableBooleanModel
|
|
||||||
fields = ['field']
|
|
||||||
|
|
||||||
expected = dedent("""
|
|
||||||
NullableBooleanSerializer():
|
|
||||||
field = BooleanField(allow_null=True, required=False)
|
|
||||||
""")
|
|
||||||
|
|
||||||
self.assertEqual(repr(NullableBooleanSerializer()), expected)
|
|
||||||
|
|
||||||
def test_nullable_boolean_field_choices(self):
|
def test_nullable_boolean_field_choices(self):
|
||||||
class NullableBooleanChoicesModel(models.Model):
|
class NullableBooleanChoicesModel(models.Model):
|
||||||
CHECKLIST_OPTIONS = (
|
CHECKLIST_OPTIONS = (
|
||||||
|
|
|
@ -2,7 +2,6 @@ import base64
|
||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import django
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import AnonymousUser, Group, Permission, User
|
from django.contrib.auth.models import AnonymousUser, Group, Permission, User
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
@ -248,12 +247,6 @@ class BasicPermModel(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
app_label = 'tests'
|
app_label = 'tests'
|
||||||
|
|
||||||
if django.VERSION < (2, 1):
|
|
||||||
permissions = (
|
|
||||||
('view_basicpermmodel', 'Can view basic perm model'),
|
|
||||||
# add, change, delete built in to django
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class BasicPermSerializer(serializers.ModelSerializer):
|
class BasicPermSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import unittest
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
from django.conf.urls import include, url
|
from django.conf.urls import include, url
|
||||||
|
@ -66,7 +65,6 @@ class FormatSuffixTests(TestCase):
|
||||||
]
|
]
|
||||||
self._test_trailing_slash(urlpatterns)
|
self._test_trailing_slash(urlpatterns)
|
||||||
|
|
||||||
@unittest.skipUnless(path, 'needs Django 2')
|
|
||||||
def test_trailing_slash_django2(self):
|
def test_trailing_slash_django2(self):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('test/', dummy_view),
|
path('test/', dummy_view),
|
||||||
|
@ -87,14 +85,12 @@ class FormatSuffixTests(TestCase):
|
||||||
]
|
]
|
||||||
self._test_format_suffix(urlpatterns)
|
self._test_format_suffix(urlpatterns)
|
||||||
|
|
||||||
@unittest.skipUnless(path, 'needs Django 2')
|
|
||||||
def test_format_suffix_django2(self):
|
def test_format_suffix_django2(self):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('test', dummy_view),
|
path('test', dummy_view),
|
||||||
]
|
]
|
||||||
self._test_format_suffix(urlpatterns)
|
self._test_format_suffix(urlpatterns)
|
||||||
|
|
||||||
@unittest.skipUnless(path, 'needs Django 2')
|
|
||||||
def test_format_suffix_django2_args(self):
|
def test_format_suffix_django2_args(self):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('convtest/<int:pk>', dummy_view),
|
path('convtest/<int:pk>', dummy_view),
|
||||||
|
@ -124,7 +120,6 @@ class FormatSuffixTests(TestCase):
|
||||||
]
|
]
|
||||||
self._test_default_args(urlpatterns)
|
self._test_default_args(urlpatterns)
|
||||||
|
|
||||||
@unittest.skipUnless(path, 'needs Django 2')
|
|
||||||
def test_default_args_django2(self):
|
def test_default_args_django2(self):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('test', dummy_view, {'foo': 'bar'}),
|
path('test', dummy_view, {'foo': 'bar'}),
|
||||||
|
@ -148,7 +143,6 @@ class FormatSuffixTests(TestCase):
|
||||||
]
|
]
|
||||||
self._test_included_urls(urlpatterns)
|
self._test_included_urls(urlpatterns)
|
||||||
|
|
||||||
@unittest.skipUnless(path, 'needs Django 2')
|
|
||||||
def test_included_urls_django2(self):
|
def test_included_urls_django2(self):
|
||||||
nested_patterns = [
|
nested_patterns = [
|
||||||
path('path', dummy_view)
|
path('path', dummy_view)
|
||||||
|
@ -158,7 +152,6 @@ class FormatSuffixTests(TestCase):
|
||||||
]
|
]
|
||||||
self._test_included_urls(urlpatterns)
|
self._test_included_urls(urlpatterns)
|
||||||
|
|
||||||
@unittest.skipUnless(path, 'needs Django 2')
|
|
||||||
def test_included_urls_django2_mixed(self):
|
def test_included_urls_django2_mixed(self):
|
||||||
nested_patterns = [
|
nested_patterns = [
|
||||||
path('path', dummy_view)
|
path('path', dummy_view)
|
||||||
|
@ -168,7 +161,6 @@ class FormatSuffixTests(TestCase):
|
||||||
]
|
]
|
||||||
self._test_included_urls(urlpatterns)
|
self._test_included_urls(urlpatterns)
|
||||||
|
|
||||||
@unittest.skipUnless(path, 'needs Django 2')
|
|
||||||
def test_included_urls_django2_mixed_args(self):
|
def test_included_urls_django2_mixed_args(self):
|
||||||
nested_patterns = [
|
nested_patterns = [
|
||||||
path('path/<int:child>', dummy_view),
|
path('path/<int:child>', dummy_view),
|
||||||
|
@ -216,7 +208,6 @@ class FormatSuffixTests(TestCase):
|
||||||
]
|
]
|
||||||
self._test_allowed_formats(urlpatterns)
|
self._test_allowed_formats(urlpatterns)
|
||||||
|
|
||||||
@unittest.skipUnless(path, 'needs Django 2')
|
|
||||||
def test_allowed_formats_django2(self):
|
def test_allowed_formats_django2(self):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('test', dummy_view),
|
path('test', dummy_view),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user