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 2733022
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion restclients_core/dao.py
Original file line number Diff line number Diff line change
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: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: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 2733022

Please sign in to comment.