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):
|
class SessionCacheTestCase(utils.TestCase):
|
||||||
|
|
||||||
def test_can_connect(self):
|
def test_can_crud_session(self):
|
||||||
|
|
||||||
db_file = None
|
|
||||||
with tempfile.NamedTemporaryFile() as fh:
|
with tempfile.NamedTemporaryFile() as fh:
|
||||||
db_file = fh.name
|
db_file = fh.name
|
||||||
|
|
||||||
|
@ -19,5 +17,8 @@ class SessionCacheTestCase(utils.TestCase):
|
||||||
session = cache.get()
|
session = cache.get()
|
||||||
session.headers.update({'x-test': 'abc'})
|
session.headers.update({'x-test': 'abc'})
|
||||||
cache.save(session)
|
cache.save(session)
|
||||||
cached_session = cache.get()
|
session = cache.get()
|
||||||
self.assertEquals(cached_session.headers.get('x-test'), 'abc')
|
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.
|
"""Saves a requests.Session object for the next heartbeat process.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not HAS_SQL:
|
if not HAS_SQL: # pragma: nocover
|
||||||
return # pragma: nocover
|
return
|
||||||
try:
|
try:
|
||||||
conn, c = self.connect()
|
conn, c = self.connect()
|
||||||
c.execute('DELETE FROM session')
|
c.execute('DELETE FROM session')
|
||||||
|
@ -67,14 +67,14 @@ class SessionCache(object):
|
||||||
Gets Session from sqlite3 cache or creates a new Session.
|
Gets Session from sqlite3 cache or creates a new Session.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not HAS_SQL:
|
if not HAS_SQL: # pragma: nocover
|
||||||
return requests.session()
|
return requests.session()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conn, c = self.connect()
|
conn, c = self.connect()
|
||||||
except:
|
except:
|
||||||
log.error(traceback.format_exc())
|
log.error(traceback.format_exc())
|
||||||
return requests.session() # pragma: nocover
|
return requests.session()
|
||||||
|
|
||||||
session = None
|
session = None
|
||||||
try:
|
try:
|
||||||
|
@ -98,7 +98,7 @@ class SessionCache(object):
|
||||||
"""Clears all cached Session objects.
|
"""Clears all cached Session objects.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not HAS_SQL:
|
if not HAS_SQL: # pragma: nocover
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
conn, c = self.connect()
|
conn, c = self.connect()
|
||||||
|
|
Loading…
Reference in a new issue