From 9990b5928139072c8e010c8b5c86616f0d40ef9d Mon Sep 17 00:00:00 2001 From: David Smith <39445562+smithdc1@users.noreply.github.com> Date: Mon, 7 Sep 2020 19:00:17 +0100 Subject: [PATCH] Dropped test compatibility shims for Django <2.2. (#7523) --- tests/conftest.py | 29 +++++++++++++---------------- tests/schemas/test_coreapi.py | 1 - tests/test_model_serializer.py | 22 +--------------------- tests/test_permissions.py | 7 ------- tests/test_urlpatterns.py | 9 --------- 5 files changed, 14 insertions(+), 54 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index d28edeb8a..ac29e4a42 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -67,22 +67,19 @@ def pytest_configure(config): ) # guardian is optional - # 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', - ) + 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) diff --git a/tests/schemas/test_coreapi.py b/tests/schemas/test_coreapi.py index 403b3b634..5f646258b 100644 --- a/tests/schemas/test_coreapi.py +++ b/tests/schemas/test_coreapi.py @@ -456,7 +456,6 @@ class TestSchemaGenerator(TestCase): @unittest.skipUnless(coreapi, 'coreapi is not installed') -@unittest.skipUnless(path, 'needs Django 2') @override_settings(REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.AutoSchema'}) class TestSchemaGeneratorDjango2(TestCase): def setUp(self): diff --git a/tests/test_model_serializer.py b/tests/test_model_serializer.py index 1733930a6..7da1b41ae 100644 --- a/tests/test_model_serializer.py +++ b/tests/test_model_serializer.py @@ -12,7 +12,6 @@ import sys import tempfile from collections import OrderedDict -import django import pytest from django.core.exceptions import ImproperlyConfigured from django.core.serializers.json import DjangoJSONEncoder @@ -63,7 +62,7 @@ class RegularFieldsModel(models.Model): email_field = models.EmailField(max_length=100) float_field = models.FloatField() integer_field = models.IntegerField() - null_boolean_field = models.NullBooleanField() + null_boolean_field = models.BooleanField(null=True, default=False) positive_integer_field = models.PositiveIntegerField() positive_small_integer_field = models.PositiveSmallIntegerField() slug_field = models.SlugField(max_length=100) @@ -218,25 +217,6 @@ class TestRegularFieldMappings(TestCase): """) 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): class NullableBooleanChoicesModel(models.Model): CHECKLIST_OPTIONS = ( diff --git a/tests/test_permissions.py b/tests/test_permissions.py index 232c72dd2..4e6cae4b8 100644 --- a/tests/test_permissions.py +++ b/tests/test_permissions.py @@ -2,7 +2,6 @@ import base64 import unittest from unittest import mock -import django from django.conf import settings from django.contrib.auth.models import AnonymousUser, Group, Permission, User from django.db import models @@ -248,12 +247,6 @@ class BasicPermModel(models.Model): class Meta: 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 Meta: diff --git a/tests/test_urlpatterns.py b/tests/test_urlpatterns.py index ec19494b0..90820b532 100644 --- a/tests/test_urlpatterns.py +++ b/tests/test_urlpatterns.py @@ -1,4 +1,3 @@ -import unittest from collections import namedtuple from django.conf.urls import include, url @@ -66,7 +65,6 @@ class FormatSuffixTests(TestCase): ] self._test_trailing_slash(urlpatterns) - @unittest.skipUnless(path, 'needs Django 2') def test_trailing_slash_django2(self): urlpatterns = [ path('test/', dummy_view), @@ -87,14 +85,12 @@ class FormatSuffixTests(TestCase): ] self._test_format_suffix(urlpatterns) - @unittest.skipUnless(path, 'needs Django 2') def test_format_suffix_django2(self): urlpatterns = [ path('test', dummy_view), ] self._test_format_suffix(urlpatterns) - @unittest.skipUnless(path, 'needs Django 2') def test_format_suffix_django2_args(self): urlpatterns = [ path('convtest/', dummy_view), @@ -124,7 +120,6 @@ class FormatSuffixTests(TestCase): ] self._test_default_args(urlpatterns) - @unittest.skipUnless(path, 'needs Django 2') def test_default_args_django2(self): urlpatterns = [ path('test', dummy_view, {'foo': 'bar'}), @@ -148,7 +143,6 @@ class FormatSuffixTests(TestCase): ] self._test_included_urls(urlpatterns) - @unittest.skipUnless(path, 'needs Django 2') def test_included_urls_django2(self): nested_patterns = [ path('path', dummy_view) @@ -158,7 +152,6 @@ class FormatSuffixTests(TestCase): ] self._test_included_urls(urlpatterns) - @unittest.skipUnless(path, 'needs Django 2') def test_included_urls_django2_mixed(self): nested_patterns = [ path('path', dummy_view) @@ -168,7 +161,6 @@ class FormatSuffixTests(TestCase): ] self._test_included_urls(urlpatterns) - @unittest.skipUnless(path, 'needs Django 2') def test_included_urls_django2_mixed_args(self): nested_patterns = [ path('path/', dummy_view), @@ -216,7 +208,6 @@ class FormatSuffixTests(TestCase): ] self._test_allowed_formats(urlpatterns) - @unittest.skipUnless(path, 'needs Django 2') def test_allowed_formats_django2(self): urlpatterns = [ path('test', dummy_view),