tests for crud session cache
This commit is contained in:
parent
dfb8ad4502
commit
9af0c110ca
2 changed files with 11 additions and 10 deletions
|
@ -8,9 +8,7 @@ from . import utils
|
|||
|
||||
class SessionCacheTestCase(utils.TestCase):
|
||||
|
||||
def test_can_connect(self):
|
||||
|
||||
db_file = None
|
||||
def test_can_crud_session(self):
|
||||
with tempfile.NamedTemporaryFile() as fh:
|
||||
db_file = fh.name
|
||||
|
||||
|
@ -19,5 +17,8 @@ class SessionCacheTestCase(utils.TestCase):
|
|||
session = cache.get()
|
||||
session.headers.update({'x-test': 'abc'})
|
||||
cache.save(session)
|
||||
cached_session = cache.get()
|
||||
self.assertEquals(cached_session.headers.get('x-test'), 'abc')
|
||||
session = cache.get()
|
||||
self.assertEquals(session.headers.get('x-test'), 'abc')
|
||||
cache.delete()
|
||||
session = cache.get()
|
||||
self.assertEquals(session.headers.get('x-test'), None)
|
||||
|
|
|
@ -46,8 +46,8 @@ class SessionCache(object):
|
|||
"""Saves a requests.Session object for the next heartbeat process.
|
||||
"""
|
||||
|
||||
if not HAS_SQL:
|
||||
return # pragma: nocover
|
||||
if not HAS_SQL: # pragma: nocover
|
||||
return
|
||||
try:
|
||||
conn, c = self.connect()
|
||||
c.execute('DELETE FROM session')
|
||||
|
@ -67,14 +67,14 @@ class SessionCache(object):
|
|||
Gets Session from sqlite3 cache or creates a new Session.
|
||||
"""
|
||||
|
||||
if not HAS_SQL:
|
||||
if not HAS_SQL: # pragma: nocover
|
||||
return requests.session()
|
||||
|
||||
try:
|
||||
conn, c = self.connect()
|
||||
except:
|
||||
log.error(traceback.format_exc())
|
||||
return requests.session() # pragma: nocover
|
||||
return requests.session()
|
||||
|
||||
session = None
|
||||
try:
|
||||
|
@ -98,7 +98,7 @@ class SessionCache(object):
|
|||
"""Clears all cached Session objects.
|
||||
"""
|
||||
|
||||
if not HAS_SQL:
|
||||
if not HAS_SQL: # pragma: nocover
|
||||
return
|
||||
try:
|
||||
conn, c = self.connect()
|
||||
|
|
Loading…
Reference in a new issue