Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion tests/schemas/test_coreapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ def test_schema_for_regular_views(self):


@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):
Expand Down
22 changes: 1 addition & 21 deletions tests/test_model_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import tempfile
from collections import OrderedDict

import django
import pytest
from django.core.exceptions import ImproperlyConfigured
from django.core.serializers.json import DjangoJSONEncoder
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -218,25 +217,6 @@ class Meta:
""")
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 = (
Expand Down
7 changes: 0 additions & 7 deletions tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
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
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 0 additions & 9 deletions tests/test_urlpatterns.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import unittest
from collections import namedtuple

from django.conf.urls import include, url
Expand Down Expand Up @@ -66,7 +65,6 @@ def test_trailing_slash(self):
]
self._test_trailing_slash(urlpatterns)

@unittest.skipUnless(path, 'needs Django 2')
def test_trailing_slash_django2(self):
urlpatterns = [
path('test/', dummy_view),
Expand All @@ -87,14 +85,12 @@ def test_format_suffix(self):
]
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/<int:pk>', dummy_view),
Expand Down Expand Up @@ -124,7 +120,6 @@ def test_default_args(self):
]
self._test_default_args(urlpatterns)

@unittest.skipUnless(path, 'needs Django 2')
def test_default_args_django2(self):
urlpatterns = [
path('test', dummy_view, {'foo': 'bar'}),
Expand All @@ -148,7 +143,6 @@ def test_included_urls(self):
]
self._test_included_urls(urlpatterns)

@unittest.skipUnless(path, 'needs Django 2')
def test_included_urls_django2(self):
nested_patterns = [
path('path', dummy_view)
Expand All @@ -158,7 +152,6 @@ def test_included_urls_django2(self):
]
self._test_included_urls(urlpatterns)

@unittest.skipUnless(path, 'needs Django 2')
def test_included_urls_django2_mixed(self):
nested_patterns = [
path('path', dummy_view)
Expand All @@ -168,7 +161,6 @@ def test_included_urls_django2_mixed(self):
]
self._test_included_urls(urlpatterns)

@unittest.skipUnless(path, 'needs Django 2')
def test_included_urls_django2_mixed_args(self):
nested_patterns = [
path('path/<int:child>', dummy_view),
Expand Down Expand Up @@ -216,7 +208,6 @@ def test_allowed_formats(self):
]
self._test_allowed_formats(urlpatterns)

@unittest.skipUnless(path, 'needs Django 2')
def test_allowed_formats_django2(self):
urlpatterns = [
path('test', dummy_view),
Expand Down