diff --git a/rest_framework_extensions/compat.py b/rest_framework_extensions/compat.py index 2887229..1b621b5 100644 --- a/rest_framework_extensions/compat.py +++ b/rest_framework_extensions/compat.py @@ -12,16 +12,13 @@ from django.conf import settings # Try to import six from Django, fallback to included `six`. -try: - from django.utils import six -except ImportError: - from rest_framework import six +from django.utils import six + # location of patterns, url, include changes in 1.4 onwards -try: - from django.conf.urls import patterns, url, include -except ImportError: - from django.conf.urls.defaults import patterns, url, include + +from django.conf.urls import url, include + # Handle django.utils.encoding rename: # smart_unicode -> smart_text diff --git a/tests_app/settings.py b/tests_app/settings.py index 352cc18..1566c84 100644 --- a/tests_app/settings.py +++ b/tests_app/settings.py @@ -126,8 +126,7 @@ import django -if django.VERSION < (1, 3): - INSTALLED_APPS += ('staticfiles',) + TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' diff --git a/tests_app/tests/functional/permissions/extended_django_object_permissions/tests.py b/tests_app/tests/functional/permissions/extended_django_object_permissions/tests.py index 227c753..5b2cba0 100644 --- a/tests_app/tests/functional/permissions/extended_django_object_permissions/tests.py +++ b/tests_app/tests/functional/permissions/extended_django_object_permissions/tests.py @@ -1,18 +1,15 @@ # -*- coding: utf-8 -*- import json -from django.test import TestCase -from django.utils import unittest from django.contrib.auth.models import User, Group, Permission from django.contrib.auth.management import create_permissions -from django.db.models import get_app, get_models +from django.db.models import get_app from django.contrib.contenttypes.models import ContentType from rest_framework import status from rest_framework_extensions.test import APITestCase -from rest_framework_extensions.compat import guardian, get_model_name -from rest_framework_extensions.utils import get_rest_framework_features +from rest_framework_extensions.compat import get_model_name from tests_app.testutils import basic_auth_header from .urls import urlpatterns @@ -45,7 +42,7 @@ def setUp(self): app_label = PermissionsComment._meta.app_label f = '{0}_{1}'.format perms = { - 'view': f('view', model_name), + 'view': f('view', model_name), 'change': f('change', model_name), 'delete': f('delete', model_name) } @@ -74,21 +71,22 @@ def setUp(self): self.credentials[user.username] = basic_auth_header(user.username, 'password') -@unittest.skipIf( - not get_rest_framework_features()['django_object_permissions_class'], - "Current DRF version doesn't support DjangoObjectPermissions" -) + class ExtendedDjangoObjectPermissionsTest_should_inherit_standard(ExtendedDjangoObjectPermissionTestMixin, APITestCase): urls = urlpatterns # Delete def test_can_delete_permissions(self): - response = self.client.delete('/comments/1/', **{'HTTP_AUTHORIZATION': self.credentials['deleteonly']}) + response = self.client.delete( + '/comments/1/', + **{'HTTP_AUTHORIZATION': self.credentials['deleteonly']}) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) def test_cannot_delete_permissions(self): - response = self.client.delete('/comments/1/', **{'HTTP_AUTHORIZATION': self.credentials['readonly']}) + response = self.client.delete( + '/comments/1/', + **{'HTTP_AUTHORIZATION': self.credentials['readonly']}) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) # Update @@ -128,11 +126,15 @@ def test_cannot_update_permissions_non_existing(self): # Read def test_can_read_permissions(self): - response = self.client.get('/comments/1/', **{'HTTP_AUTHORIZATION': self.credentials['readonly']}) + response = self.client.get( + '/comments/1/', + **{'HTTP_AUTHORIZATION': self.credentials['readonly']}) self.assertEqual(response.status_code, status.HTTP_200_OK) def test_cannot_read_permissions(self): - response = self.client.get('/comments/1/', **{'HTTP_AUTHORIZATION': self.credentials['writeonly']}) + response = self.client.get( + '/comments/1/', + **{'HTTP_AUTHORIZATION': self.credentials['writeonly']}) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) # Read list @@ -153,10 +155,6 @@ def test_cannot_read_list_permissions(self): self.assertListEqual(response.data, []) -@unittest.skipIf( - not get_rest_framework_features()['django_object_permissions_class'], - "Current DRF version doesn't support DjangoObjectPermissions" -) class ExtendedDjangoObjectPermissionsTest_without_hiding_forbidden_objects(ExtendedDjangoObjectPermissionTestMixin, APITestCase): urls = urlpatterns diff --git a/tests_app/tests/functional/routers/tests.py b/tests_app/tests/functional/routers/tests.py index 92ae227..b34bfb5 100644 --- a/tests_app/tests/functional/routers/tests.py +++ b/tests_app/tests/functional/routers/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- + from django.test import TestCase -from django.utils import unittest + from rest_framework_extensions.compat_drf import get_lookup_allowed_symbols from rest_framework_extensions.utils import get_rest_framework_features @@ -26,10 +27,7 @@ def test_urls_have_trailing_slash_by_default(self): self.assertIsNotNone(get_url_pattern_by_regex_pattern(urls, exp), msg=msg) -@unittest.skipUnless( - get_rest_framework_features()['router_trailing_slash'], - "Current DRF version doesn't support Router trailing_slash" -) + class TestTrailingSlashRemoved(TestCase): def test_urls_can_have_trailing_slash_removed(self): router = ExtendedSimpleRouter(trailing_slash=False) diff --git a/tox.ini b/tox.ini index e22aae7..89bfcdb 100644 --- a/tox.ini +++ b/tox.ini @@ -12,19 +12,19 @@ setenv = commands= {envbindir}/django-admin.py test --settings=settings {posargs} + [testenv:django.1.9] deps= {[testenv]deps} Django>=1.9,<1.10 - djangorestframework>=3.3.3 + djangorestframework>=3.3.2 django-guardian>=1.4.1 [testenv:django.1.8.lts] deps= {[testenv]deps} - Django==1.8.11 - djangorestframework==3.3.3 + Django>=1.8,<1.9 + djangorestframework>=3.3.2 django-guardian>=1.4.1 -