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

Made compatible with DRF 3.2.2 and django 1.8 #99

Merged
merged 14 commits into from
Dec 1, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 10 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
language: python

python:
- "3.5"
- "3.4"
- "2.7"

matrix:
exclude:
- env: TOX_ENV=django.1.7
python: "3.5"

install:
- pip install tox

env:
- TOX_ENV=py27-drf2.3.5
- TOX_ENV=py27-drf2.3.6
- TOX_ENV=py27-drf2.3.7
- TOX_ENV=py27-drf2.3.8
- TOX_ENV=py27-drf2.3.9
- TOX_ENV=py27-drf2.3.10
- TOX_ENV=py27-drf2.3.11
- TOX_ENV=py27-drf2.3.12
- TOX_ENV=py27-drf2.3.13
- TOX_ENV=py27-drf2.3.14
- TOX_ENV=py27-drf2.4.0
- TOX_ENV=py27-drf2.4.1
- TOX_ENV=py27-drf2.4.2
- TOX_ENV=py27-drf2.4.3
- TOX_ENV=py27-drf2.4.4
- TOX_ENV=py27-drf3.0
- TOX_ENV=py27-drf3.0.1
- TOX_ENV=py27-drf3.0.2
- TOX_ENV=py27-drf3.0.3
- TOX_ENV=py27-drf3.0.4
- TOX_ENV=py3
- TOX_ENV=django1.5
- TOX_ENV=django1.6
- TOX_ENV=django1.7
- TOX_ENV=latest,
- TOX_ENV=django.1.8.lts,
- TOX_ENV=django.1.7

script:
- tox -e $TOX_ENV -- tests_app
12 changes: 6 additions & 6 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html>
<!--
Backdoc is a tool for backbone-like documentation generation.
Backdoc is a tool for backbone-like documentation generation.
Backdoc main goal is to help to generate one page documentation from one markdown source file.

https://github.com/chibisov/backdoc
Expand Down Expand Up @@ -103,7 +103,7 @@
}

.sidebar ul ul li:before {
content: "- ";
content: "- ";
}
.sidebar ul ul li {
margin-bottom: 3px;
Expand Down Expand Up @@ -155,7 +155,7 @@
font-size: 13px;
line-height: 18px;
padding-left: 15px;
}
}

pre {
font-size: 12px;
Expand Down Expand Up @@ -218,7 +218,7 @@
padding-left: 10px;
padding-right: 10px;
}
.main_container > ul,
.main_container > ul,
.main_container > ol {
padding-left: 27px;
}
Expand All @@ -235,7 +235,7 @@
.force_show_sidebar .toggle_sidebar_button {
right: 0;
}
.force_show_sidebar .toggle_sidebar_button .line:first-child,
.force_show_sidebar .toggle_sidebar_button .line:first-child,
.force_show_sidebar .toggle_sidebar_button .line:last-child {
visibility: hidden;
}
Expand Down Expand Up @@ -1617,7 +1617,7 @@ <h4 id="how-key-constructor-works">How key constructor works</h4>
<pre><code>'{"unique_method_id": "your_app.views.SometView.get", "language": "en", "format": "json"}'
</code></pre>

<p>And finally compresses json with <strong>sha256</strong> and returns hash value:</p>
<p>And finally compresses json with <strong>md5</strong> and returns hash value:</p>

<pre><code>'b04f8f03c89df824e0ecd25230a90f0e0ebe184cf8c0114342e9471dd2275baa'
</code></pre>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ Then constructor dumps resulting dict to json:

'{"unique_method_id": "your_app.views.SometView.get", "language": "en", "format": "json"}'

And finally compresses json with **sha256** and returns hash value:
And finally compresses json with **md5** and returns hash value:

'b04f8f03c89df824e0ecd25230a90f0e0ebe184cf8c0114342e9471dd2275baa'

Expand Down
2 changes: 1 addition & 1 deletion rest_framework_extensions/bulk_operations/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def partial_update_bulk(self, request, *args, **kwargs):
is_valid, errors = self.is_valid_bulk_operation()
if is_valid:
queryset = self.filter_queryset(self.get_queryset())
update_bulk_dict = self.get_update_bulk_dict(serializer=self.get_serializer_class()(), data=request.DATA)
update_bulk_dict = self.get_update_bulk_dict(serializer=self.get_serializer_class()(), data=request.data)
self.pre_save_bulk(queryset, update_bulk_dict) # todo: test and document me
try:
queryset.update(**update_bulk_dict)
Expand Down
6 changes: 3 additions & 3 deletions rest_framework_extensions/key_constructor/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ def _get_key(self, view_instance, view_method, request, args, kwargs):
)

def prepare_key(self, key_dict):
return hashlib.sha256(json.dumps(key_dict, sort_keys=True).encode('utf-8')).hexdigest()
return hashlib.md5(json.dumps(key_dict, sort_keys=True).encode('utf-8')).hexdigest()

def get_data_from_bits(self, **kwargs):
result_dict = {}
result_dict = {}
for bit_name, bit_instance in self.bits.items():
if bit_name in self.params:
params = self.params[bit_name]
Expand All @@ -103,4 +103,4 @@ class DefaultObjectKeyConstructor(DefaultKeyConstructor):

class DefaultListKeyConstructor(DefaultKeyConstructor):
list_sql_query = bits.ListSqlQueryKeyBit()
pagination = bits.PaginationKeyBit()
pagination = bits.PaginationKeyBit()
14 changes: 7 additions & 7 deletions rest_framework_extensions/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ def _is_request_to_detail_endpoint(self):


class PaginateByMaxMixin(object):
def get_paginate_by(self, *args, **kwargs):

def get_page_size(self, request):
if (get_rest_framework_features()['max_paginate_by'] and
self.paginate_by_param and
self.max_paginate_by and
self.request.QUERY_PARAMS.get(self.paginate_by_param) == 'max'):
return self.max_paginate_by
else:
return super(PaginateByMaxMixin, self).get_paginate_by(*args, **kwargs)
self.page_size_query_param and
self.max_page_size and
request.query_params.get(self.page_size_query_param) == 'max'):
return self.max_page_size
return super(PaginateByMaxMixin, self).get_page_size(request)


class ReadOnlyCacheResponseAndETAGMixin(ReadOnlyETAGMixin, CacheResponseMixin):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class UserSerializer(serializers.ModelSerializer):

class Meta:
model = User
write_only_fields = ('password',)
extra_kwargs = {'password': {'write_only': True}}
read_only_fields = ('name',)
fields = [
'id',
Expand All @@ -24,4 +24,4 @@ class Meta:

class CommentSerializer(serializers.ModelSerializer):
class Meta:
model = Comment
model = Comment
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import json

from django.utils import unittest
import unittest

from rest_framework_extensions.test import APITestCase
from rest_framework_extensions.settings import extensions_api_settings
Expand Down Expand Up @@ -197,4 +197,4 @@ def test_should_not_update_hidden_fields(self):
}
resp = self.client.patch('/users/', data=json.dumps(data), content_type='application/json', **self.headers)
self.assertEqual(resp.status_code, 204)
self.assertEqual(self.get_fresh_user().email, self.user.email)
self.assertEqual(self.get_fresh_user().email, self.user.email)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from rest_framework_extensions.mixins import PaginateByMaxMixin
from rest_framework.pagination import PageNumberPagination


class WithMaxPagination(PaginateByMaxMixin, PageNumberPagination):
page_size = 10
page_size_query_param = 'limit'
max_page_size = 20


class FlexiblePagination(PageNumberPagination):
page_size = 10
page_size_query_param = 'page_size'


class FixedPagination(PageNumberPagination):
page_size = 10
16 changes: 8 additions & 8 deletions tests_app/tests/functional/mixins/paginate_by_max_mixin/tests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
import datetime
import unittest

from django.test import TestCase
from django.utils import unittest

from rest_framework_extensions.utils import get_rest_framework_features

Expand Down Expand Up @@ -30,15 +30,15 @@ def test_default_page_size(self):
self.assertEqual(len(resp.data['results']), 10)

def test_custom_page_size__less_then_maximum(self):
resp = self.client.get('/comments/?page_size=15')
resp = self.client.get('/comments/?limit=15')
self.assertEqual(len(resp.data['results']), 15)

def test_custom_page_size__more_then_maximum(self):
resp = self.client.get('/comments/?page_size=25')
resp = self.client.get('/comments/?limit=25')
self.assertEqual(len(resp.data['results']), 20)

def test_custom_page_size_with_max_value(self):
resp = self.client.get('/comments/?page_size=max')
resp = self.client.get('/comments/?limit=max')
self.assertEqual(len(resp.data['results']), 20)

def test_custom_page_size_with_max_value__for_view_without__paginate_by_param__attribute(self):
Expand Down Expand Up @@ -70,13 +70,13 @@ def test_default_page_size(self):
self.assertEqual(len(resp.data['results']), 10)

def test_custom_page_size__less_then_maximum(self):
resp = self.client.get('/comments/?page_size=15')
resp = self.client.get('/comments/?limit=15')
self.assertEqual(len(resp.data['results']), 15)

def test_custom_page_size__more_then_maximum(self):
resp = self.client.get('/comments/?page_size=25')
resp = self.client.get('/comments/?limit=25')
self.assertEqual(len(resp.data['results']), 25)

def test_custom_page_size_with_max_value(self):
resp = self.client.get('/comments/?page_size=max')
self.assertEqual(len(resp.data['results']), 10)
resp = self.client.get('/comments/?limit=max')
self.assertEqual(len(resp.data['results']), 10)
20 changes: 8 additions & 12 deletions tests_app/tests/functional/mixins/paginate_by_max_mixin/views.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
# -*- coding: utf-8 -*-
from rest_framework import viewsets
from rest_framework_extensions.mixins import PaginateByMaxMixin

from .pagination import WithMaxPagination, FixedPagination, FlexiblePagination
from .models import CommentForPaginateByMaxMixin
from .serializers import CommentSerializer


class CommentViewSet(PaginateByMaxMixin, viewsets.ReadOnlyModelViewSet):
paginate_by_param = 'page_size'
paginate_by = 10
max_paginate_by = 20
class CommentViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class = CommentSerializer
pagination_class = WithMaxPagination
queryset = CommentForPaginateByMaxMixin.objects.all()


class CommentWithoutPaginateByParamViewSet(PaginateByMaxMixin, viewsets.ReadOnlyModelViewSet):
paginate_by = 10
max_paginate_by = 20
class CommentWithoutPaginateByParamViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class = CommentSerializer
pagination_class = FixedPagination
queryset = CommentForPaginateByMaxMixin.objects.all()


class CommentWithoutMaxPaginateByAttributeViewSet(PaginateByMaxMixin, viewsets.ReadOnlyModelViewSet):
paginate_by_param = 'page_size'
paginate_by = 10
class CommentWithoutMaxPaginateByAttributeViewSet(viewsets.ReadOnlyModelViewSet):
pagination_class = FlexiblePagination
serializer_class = CommentSerializer
queryset = CommentForPaginateByMaxMixin.objects.all()
queryset = CommentForPaginateByMaxMixin.objects.all()
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@


class UserViewSet(NestedViewSetMixin, ModelViewSet):
model = DefaultRouterUserModel
queryset = DefaultRouterUserModel.objects.all()


class GroupViewSet(NestedViewSetMixin, ModelViewSet):
model = DefaultRouterGroupModel
queryset = DefaultRouterGroupModel.objects.all()


class PermissionViewSet(NestedViewSetMixin, ModelViewSet):
model = DefaultRouterPermissionModel
queryset = DefaultRouterPermissionModel.objects.all()
2 changes: 1 addition & 1 deletion tests_app/tests/functional/routers/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ def test_urls_can_have_trailing_slash_removed(self):
'^router-viewset/list_controller$',
'^router-viewset/{0}/detail_controller$'.format(lookup_allowed_symbols)]:
msg = 'Should find url pattern with regexp %s' % exp
self.assertIsNotNone(get_url_pattern_by_regex_pattern(urls, exp), msg=msg)
self.assertIsNotNone(get_url_pattern_by_regex_pattern(urls, exp), msg=msg)
4 changes: 2 additions & 2 deletions tests_app/tests/functional/routers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@


class RouterViewSet(viewsets.ModelViewSet):
model = RouterTestModel
queryset = RouterTestModel.objects.all()

@action()
def detail_controller(self):
pass

@action(is_for_list=True)
def list_controller(self):
pass
pass
6 changes: 3 additions & 3 deletions tests_app/tests/unit/etag/decorators/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


factory = APIRequestFactory()
UNSAFE_METHODS = ['POST', 'PUT', 'DELETE', 'PATCH']
UNSAFE_METHODS = ('POST', 'PUT', 'DELETE', 'PATCH')


def default_etag_func(**kwargs):
Expand Down Expand Up @@ -319,6 +319,6 @@ def setUp(self):

def test_for_all_methods(self):
self.run_for_methods(
SAFE_METHODS + UNSAFE_METHODS,
tuple(SAFE_METHODS) + UNSAFE_METHODS,
condition_failed_status=status.HTTP_412_PRECONDITION_FAILED
)
)
4 changes: 2 additions & 2 deletions tests_app/tests/unit/key_constructor/constructor/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class MyKeyConstructor(KeyConstructor):
self.assertEqual(constructor_instance.prepare_key(one), constructor_instance.prepare_key(two))

def prepare_key(self, key_dict):
return hashlib.sha256(json.dumps(key_dict, sort_keys=True).encode('utf-8')).hexdigest()
return hashlib.md5(json.dumps(key_dict, sort_keys=True).encode('utf-8')).hexdigest()

def test_key_construction__with_bits_without_params(self):
class MyKeyConstructor(KeyConstructor):
Expand Down Expand Up @@ -270,4 +270,4 @@ class View_2(viewsets.ReadOnlyModelViewSet):
self.kwargs['view_instance'] = view_2_instance
self.kwargs['view_instance'] = view_2_instance.retrieve
response_2 = constructor_instance(**self.kwargs)
self.assertFalse(response_1 is response_2)
self.assertFalse(response_1 is response_2)
5 changes: 3 additions & 2 deletions tests_app/tests/unit/serializers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class CommentModel(models.Model):
users_liked = models.ManyToManyField(UserModel, blank=True, null=True)
title = models.CharField(max_length=20)
text = models.CharField(max_length=200)
attachment = models.FileField(upload_to=upload_to, blank=True, null=True)
attachment = models.FileField(
upload_to=upload_to, blank=True, null=True, max_length=500)
hidden_text = models.CharField(max_length=200, blank=True, null=True)

class Meta:
app_label = 'tests_app'
app_label = 'tests_app'