Skip to content

Commit

Permalink
Fixes #32. @cache_response doesn't seem to be working with DRF 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Chibisov Gennady committed Sep 9, 2014
1 parent 8aed65b commit 2812b50
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 0 deletions.
Binary file modified docs/index.html
Binary file not shown.
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2063,6 +2063,8 @@ django >= 1.7
* [Documented ETag usage with GZipMiddleware](#gzipped-etags)
* Fixed `ListSqlQueryKeyBit` and `RetrieveSqlQueryKeyBit` [problems](https://github.com/chibisov/drf-extensions/issues/28)
with `EmptyResultSet`.
* Fixed [cache response](#cache-response) compatibility [issue](https://github.com/chibisov/drf-extensions/issues/32)
with DRF 2.4.x

#### 0.2.5

Expand Down
2 changes: 2 additions & 0 deletions rest_framework_extensions/cache/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def process_cache_response(self,
response = view_instance.finalize_response(request, response, *args, **kwargs)
response.render() # should be rendered, before picklining while storing to cache
self.cache.set(key, response, self.timeout)
if not hasattr(response, '_closable_objects'):
response._closable_objects = []
return response

def calculate_key(self,
Expand Down
1 change: 1 addition & 0 deletions tests_app/tests/functional/cache/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions tests_app/tests/functional/cache/decorators/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

19 changes: 19 additions & 0 deletions tests_app/tests/functional/cache/decorators/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
import datetime

from django.test import TestCase

from .urls import urlpatterns


class TestCacheResponseFunctionally(TestCase):
urls = urlpatterns

def test_should_return_response(self):
resp = self.client.get('/hello/')
self.assertEqual(resp.content, '"Hello world"')

def test_should_return_same_response_if_cached(self):
resp_1 = self.client.get('/hello/')
resp_2 = self.client.get('/hello/')
self.assertEqual(resp_1.content, resp_2.content)
9 changes: 9 additions & 0 deletions tests_app/tests/functional/cache/decorators/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
from django.conf.urls import url

from .views import HelloView


urlpatterns = [
url(r'^hello/$', HelloView.as_view(), name='hello'),
]
11 changes: 11 additions & 0 deletions tests_app/tests/functional/cache/decorators/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
from rest_framework import views
from rest_framework.response import Response

from rest_framework_extensions.cache.decorators import cache_response


class HelloView(views.APIView):
@cache_response()
def get(self, request, *args, **kwargs):
return Response('Hello world')
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ envlist =
py27-drf2.3.12,
py27-drf2.3.13,
py27-drf2.3.14,
py27-drf2.4.0,
py27-drf2.4.1,
py27-drf2.4.2,
py3,
django1.5,
django1.6,
Expand Down

0 comments on commit 2812b50

Please sign in to comment.