diff --git a/tests/test_session_cache.py b/tests/test_session_cache.py index f2684d3..c59009e 100644 --- a/tests/test_session_cache.py +++ b/tests/test_session_cache.py @@ -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) diff --git a/wakatime/session_cache.py b/wakatime/session_cache.py index a2c0f83..6f87c28 100644 --- a/wakatime/session_cache.py +++ b/wakatime/session_cache.py @@ -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()