def test_validate_token_with_cache_exception(self):

        mock_keystoneauth = patch(
            'globomap_auth_manager.auth.KeystoneAuth').start()
        mock_keystoneauth.return_value.validate_token.return_value = ''
        auth_inst = Auth()
        auth_inst._set_config_keystone = Mock()
        auth_inst.cache = RedisClient()
        auth_inst.cache.is_redis_ok = Mock(return_value=False)
        auth_inst.cache.get_cache_token = Mock(return_value='')
        auth_inst.token = 'token123'
        auth_inst._keystone_auth = mock_keystoneauth()

        with self.assertRaises(exceptions.InvalidToken):
            auth_inst.validate_token()
    def test_get_token_data(self):

        auth_inst = Auth()
        auth_inst.cache = RedisClient()
        auth_inst.cache.is_redis_ok = Mock(return_value=False)
        auth_inst._keystone_auth = Mock()
        auth_inst._keystone_auth.conn.auth_ref = {
            'expires_at': '2018-04-11T19:17:49.870116Z',
            'auth_token': 'token',
            'roles': [{
                'name': 'role1',
                'id': '123'
            }],
            'user': {
                'name': 'test'
            },
            'useless': 1
        }

        data = {'expires_at': '2018-04-11T19:17:49.870116Z', 'token': 'token'}
        auth_inst.token = 'token'

        self.assertEqual(data, auth_inst.get_token_data())
    def test_get_token_data_with_cache(self):

        auth_inst = Auth()
        auth_inst.cache = Mock()
        auth_inst._keystone_auth = Mock()
        auth_ref = {
            'expires_at': '2018-04-11T19:17:49.870116Z',
            'auth_token': 'token',
            'roles': [{
                'name': 'role1',
                'id': '123'
            }],
            'user': {
                'name': 'test'
            },
            'useless': 1
        }
        auth_inst._keystone_auth.conn.auth_ref = auth_ref

        data = {'expires_at': '2018-04-11T19:17:49.870116Z', 'token': 'token'}
        auth_inst.token = 'token'
        self.assertEqual(data, auth_inst.get_token_data())

        auth_inst.cache.set_cache_token.assert_called_once_with(auth_ref)