예제 #1
0
    def test_can_crud_session(self):
        with utils.NamedTemporaryFile() as fh:
            cache = SessionCache()
            cache.DB_FILE = fh.name

            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)
예제 #2
0
    def test_uses_wakatime_home_env_variable(self):
        with utils.TemporaryDirectory() as tempdir:
            expected = os.path.realpath(os.path.join(os.path.expanduser('~'), '.wakatime.db'))

            cache = SessionCache()
            actual = cache._get_db_file()
            self.assertEquals(actual, expected)

            with utils.mock.patch('os.environ.get') as mock_env:
                mock_env.return_value = os.path.realpath(tempdir)

                expected = os.path.realpath(os.path.join(tempdir, '.wakatime.db'))
                actual = cache._get_db_file()
                self.assertEquals(actual, expected)
예제 #3
0
    def test_handles_connection_exception(self):
        with utils.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)
예제 #4
0
    def test_uses_wakatime_home_env_variable(self):
        with utils.TemporaryDirectory() as tempdir:
            expected = os.path.realpath(
                os.path.join(os.path.expanduser('~'), '.wakatime.db'))

            cache = SessionCache()
            actual = cache._get_db_file()
            self.assertEquals(actual, expected)

            with utils.mock.patch('os.environ.get') as mock_env:
                mock_env.return_value = os.path.realpath(tempdir)

                expected = os.path.realpath(
                    os.path.join(tempdir, '.wakatime.db'))
                actual = cache._get_db_file()
                self.assertEquals(actual, expected)
예제 #5
0
    def test_can_crud_session(self):
        with tempfile.NamedTemporaryFile() as fh:
            cache = SessionCache()
            cache.DB_FILE = fh.name

            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)
예제 #6
0
    def test_handles_connection_exception(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)
예제 #7
0
    def test_can_crud_session(self):
        with utils.NamedTemporaryFile() as fh:
            cache = SessionCache()

            with utils.mock.patch(
                    'wakatime.session_cache.SessionCache._get_db_file'
            ) as mock_dbfile:
                mock_dbfile.return_value = fh.name

                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)
예제 #8
0
    def test_can_crud_session(self):
        with utils.NamedTemporaryFile() as fh:
            cache = SessionCache()

            with utils.mock.patch('wakatime.session_cache.SessionCache._get_db_file') as mock_dbfile:
                mock_dbfile.return_value = fh.name

                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)