Skip to content

Commit

Permalink
Use gapipy.cache.NullCache by default. Caching must be set explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
bartek committed May 22, 2015
1 parent e36f641 commit 36f29ee
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
History
-------

0.1.44 (2015-05-22)
-------------------

* Changed default `cache_backend` to use `gapipy.cache.NullCache`. Previously, `SimpleCache` was the default and led to confusion in production environments, specifically as to why resources were not matching the API output. Now, by default, to get any caching from gapipy you must explicitly set it.

0.1.43 (2015-04-29)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ configurable by adjusting the ``GAPI_CACHE_BACKEND`` environment variable.
``gapipy.cache.RedisCache``
A key-value cache store using Redis as a backend.

``gapipy.cache.NullCache``
``gapipy.cache.NullCache`` (Default)
A cache that doesn't cache.

Since the cache backend is defined by a python module path, you are free to use
Expand Down
2 changes: 1 addition & 1 deletion gapipy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

__version__ = '0.1.43'
__version__ = '0.1.44'
__title__ = 'gapipy'


Expand Down
2 changes: 1 addition & 1 deletion gapipy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'api_root': os.environ.get('GAPI_API_ROOT', 'https://rest.gadventures.com'),
'api_proxy': os.environ.get('GAPI_API_PROXY', ''),
'api_language': os.environ.get('GAPI_LANGUAGE'),
'cache_backend': os.environ.get('GAPI_CACHE_BACKEND', 'gapipy.cache.SimpleCache'),
'cache_backend': os.environ.get('GAPI_CACHE_BACKEND', 'gapipy.cache.NullCache'),
'cache_options': {'threshold': 500, 'default_timeout': 3600},
'debug': os.environ.get('GAPI_CLIENT_DEBUG', False),
}
Expand Down
32 changes: 20 additions & 12 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@ def test_get_instance_by_id_with_non_404_error(self, mock_request):

self.assertEqual(cm.exception.response.status_code, 401)

@patch('gapipy.request.APIRequestor._request', return_value=PPP_TOUR_DATA)
def test_resources_are_cached(self, mock_request):
query = Query(self.client, Tour)
self.assertEqual(self.cache.count(), 0)

query.get(21346)
self.assertEqual(self.cache.count(), 1)
self.assertEqual(len(mock_request.mock_calls), 1)

query.get(21346)
self.assertEqual(len(mock_request.mock_calls), 1)

@patch('gapipy.request.APIRequestor._request')
def test_filtered_query(self, mock_request):
query = Query(self.client, Tour).filter(tour_dossier_code='PPP')
Expand Down Expand Up @@ -140,6 +128,26 @@ def test_fetch_all_with_wrong_argument_for_limit(self):
list(query) # force the query to evaluate


class QueryCacheTestCase(unittest.TestCase):
def setUp(self):
self.client = Client(cache_backend='gapipy.cache.SimpleCache')
self.cache = self.client._cache
self.cache.clear()

@patch('gapipy.request.APIRequestor._request', return_value=PPP_TOUR_DATA)
def test_resources_are_cached(self, mock_request):
query = Query(self.client, Tour)

self.assertEqual(self.cache.count(), 0)

query.get(21346)
self.assertEqual(self.cache.count(), 1)
self.assertEqual(len(mock_request.mock_calls), 1)

query.get(21346)
self.assertEqual(len(mock_request.mock_calls), 1)


class MockResource(Resource):
_as_is_fields = ['id', 'first_name', 'last_name']
_resource_name = 'mocks'
Expand Down

0 comments on commit 36f29ee

Please sign in to comment.