Skip to content

Commit

Permalink
Modifying tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ezturner committed Dec 6, 2017
1 parent ae184bd commit b1cca8e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
8 changes: 4 additions & 4 deletions restclients_core/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _load_resource(self, method, url, headers, body):
if cache_response:
if "response" in cache_response:
self._log(service=service, url=url, method=method,
status=cache_response["response"].status,
response=cache_response["response"],
cached=True, start_time=start_time)
return cache_response["response"]
if "headers" in cache_response:
Expand All @@ -170,8 +170,8 @@ def _load_resource(self, method, url, headers, body):
if cache_post_response is not None:
if "response" in cache_post_response:
self._log(service=service, url=url, method=method,
status=cache_post_response["response"].status,
cached=True, start_time=start_time)
response=response, cached=True,
start_time=start_time)
return cache_post_response["response"]

self._log(service=service, url=url, method=method, response=response,
Expand Down Expand Up @@ -265,7 +265,7 @@ def _log(self, *args, **kwargs):
from_cache = 'yes' if kwargs.get('cached') else 'no'
response = kwargs.get('response')
cache_class = (response.cache_class if hasattr(response, 'cache_class')
else None)
else "None")
total_time = time.time() - kwargs.get('start_time')
msg = (('service:%s method:%s url:%s status:%s from_cache:%s ' +
'cache_class:%s time:%s')
Expand Down
19 changes: 13 additions & 6 deletions restclients_core/tests/dao_implementation/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from commonconf import override_settings
from restclients_core.dao import DAO, MockDAO
from restclients_core.cache import NoCache
from restclients_core.models import MockHTTP
from restclients_core.models import MockHTTP, CacheHTTP
from restclients_core.exceptions import ImproperlyConfigured


Expand Down Expand Up @@ -72,7 +72,8 @@ def test_log(self):
(msg, time) = cm.output[0].split(' time:')
self.assertEquals(msg,
'INFO:restclients_core.dao:service:backend_test '
'method:GET url:/ok status:200 from_cache:no')
'method:GET url:/ok status:200 from_cache:no'
' cache_class:None')
self.assertGreater(float(time), 0)

with self.assertLogs('restclients_core.dao', level='INFO') as cm:
Expand All @@ -81,7 +82,8 @@ def test_log(self):
(msg, time) = cm.output[0].split(' time:')
self.assertEquals(msg,
'INFO:restclients_core.dao:service:backend_test '
'method:PUT url:/api status:200 from_cache:no')
'method:PUT url:/api status:200 from_cache:no'
' cache_class:None')
self.assertGreater(float(time), 0)

# Cached response
Expand All @@ -91,7 +93,9 @@ def test_log(self):
(msg, time) = cm.output[0].split(' time:')
self.assertEquals(msg,
'INFO:restclients_core.dao:service:backend_test '
'method:GET url:/ok status:200 from_cache:yes')
'method:GET url:/ok status:200 from_cache:yes'
' cache_class:<class \'restclients_core.tests'
'.dao_implementation.test_backend.Cache\'>')
self.assertGreater(float(time), 0)

# Cached post response
Expand All @@ -101,7 +105,9 @@ def test_log(self):
(msg, time) = cm.output[0].split(' time:')
self.assertEquals(msg,
'INFO:restclients_core.dao:service:backend_test '
'method:GET url:/ok2 status:404 from_cache:yes')
'method:GET url:/ok2 status:404 from_cache:yes'
' cache_class:<class \'restclients_core.tests'
'.dao_implementation.test_backend.Cache\'>')
self.assertGreater(float(time), 0)


Expand All @@ -116,7 +122,8 @@ def load(self, method, url, headers, body):
class Cache(NoCache):
def getCache(self, service, url, headers):
if url == '/ok':
response = MockHTTP()
response = CacheHTTP()
response.cache_class = self.__class__
response.status = 200
response.data = 'ok - GET'
return {'response': response}
Expand Down

0 comments on commit b1cca8e

Please sign in to comment.