Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] add django 1.9 support and remove the obsolete versions code. #121

Merged
merged 9 commits into from
Mar 30, 2016
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
13 changes: 5 additions & 8 deletions rest_framework_extensions/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests_app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@

import django

if django.VERSION < (1, 3):
INSTALLED_APPS += ('staticfiles',)


TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions tests_app/tests/functional/routers/tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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