tests for connection issues with session caching

This commit is contained in:
Alan Hamlett 2015-09-27 01:59:39 -07:00
parent 9af0c110ca
commit dd5678a919

View file

@ -10,15 +10,31 @@ class SessionCacheTestCase(utils.TestCase):
def test_can_crud_session(self):
with tempfile.NamedTemporaryFile() as fh:
db_file = fh.name
cache = SessionCache()
cache.DB_FILE = fh.name
cache = SessionCache()
cache.DB_FILE = db_file
session = cache.get()
session.headers.update({'x-test': 'abc'})
cache.save(session)
session = cache.get()
self.assertEquals(session.headers.get('x-test'), 'abc')
cache.delete()
session = cache.get()
self.assertEquals(session.headers.get('x-test'), None)
session = cache.get()
session.headers.update({'x-test': 'abc'})
cache.save(session)
session = cache.get()
self.assertEquals(session.headers.get('x-test'), 'abc')
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)