tests for connection issues with session caching
This commit is contained in:
parent
9af0c110ca
commit
dd5678a919
1 changed files with 27 additions and 11 deletions
|
@ -10,10 +10,9 @@ class SessionCacheTestCase(utils.TestCase):
|
|||
|
||||
def test_can_crud_session(self):
|
||||
with tempfile.NamedTemporaryFile() as fh:
|
||||
db_file = fh.name
|
||||
|
||||
cache = SessionCache()
|
||||
cache.DB_FILE = db_file
|
||||
cache.DB_FILE = fh.name
|
||||
|
||||
session = cache.get()
|
||||
session.headers.update({'x-test': 'abc'})
|
||||
cache.save(session)
|
||||
|
@ -22,3 +21,20 @@ class SessionCacheTestCase(utils.TestCase):
|
|||
cache.delete()
|
||||
session = cache.get()
|
||||
self.assertEquals(session.headers.get('x-test'), None)
|
||||
|
||||
def test_get_handles_connection_error(self):
|
||||
with tempfile.NamedTemporaryFile() as fh:
|
||||
cache = SessionCache()
|
||||
cache.DB_FILE = fh.name
|
||||
|
||||
with utils.mock.patch('wakatime.session_cache.SessionCache.connect') as mock_connect:
|
||||
mock_connect.side_effect = OSError('')
|
||||
|
||||
session = cache.get()
|
||||
session.headers.update({'x-test': 'abc'})
|
||||
cache.save(session)
|
||||
session = cache.get()
|
||||
self.assertEquals(session.headers.get('x-test'), None)
|
||||
cache.delete()
|
||||
session = cache.get()
|
||||
self.assertEquals(session.headers.get('x-test'), None)
|
||||
|
|
Loading…
Reference in a new issue