<s> from twisted . trial . unittest import TestCase <EOL> import jasmin . vendor . txredisapi as redis <EOL> from twisted . internet import reactor , defer <EOL> from jasmin . redis . configs import RedisForJasminConfig <EOL> from jasmin . redis . client import ConnectionWithConfiguration <EOL> @ defer . inlineCallbacks <EOL> def waitFor ( seconds ) : <EOL> waitDeferred = defer . Deferred ( ) <EOL> reactor . callLater ( seconds , waitDeferred . callback , None ) <EOL> yield waitDeferred <EOL> class AuthenticationTestCase ( TestCase ) : <EOL> @ defer . inlineCallbacks <EOL> def setUp ( self ) : <EOL> self . RedisForJasminConfigInstance = RedisForJasminConfig ( ) <EOL> self . RedisForJasminConfigInstance . password = '<STR_LIT>' <EOL> self . redisClient = yield ConnectionWithConfiguration ( self . RedisForJasminConfigInstance ) <EOL> yield self . redisClient . _connected <EOL> @ defer . inlineCallbacks <EOL> def tearDown ( self ) : <EOL> yield self . redisClient . disconnect ( ) <EOL> @ defer . inlineCallbacks <EOL> def test_auth ( self ) : <EOL> try : <EOL> yield self . redisClient . auth ( self . RedisForJasminConfigInstance . password ) <EOL> yield self . redisClient . select ( self . RedisForJasminConfigInstance . dbid ) <EOL> except Exception , e : <EOL> self . assertEqual ( type ( e ) , redis . ResponseError ) <EOL> self . assertEqual ( str ( e ) , '<STR_LIT>' ) <EOL> class RedisTestCase ( TestCase ) : <EOL> @ defer . inlineCallbacks <EOL> def setUp ( self ) : <EOL> RedisForJasminConfigInstance = RedisForJasminConfig ( ) <EOL> RedisForJasminConfigInstance . password = None <EOL> self . redisClient = yield ConnectionWithConfiguration ( RedisForJasminConfigInstance ) <EOL> if RedisForJasminConfigInstance . password is not None : <EOL> yield self . redisClient . auth ( RedisForJasminConfigInstance . password ) <EOL> yield self . redisClient . select ( RedisForJasminConfigInstance . dbid ) <EOL> yield self . redisClient . _connected <EOL> @ defer . inlineCallbacks <EOL> def tearDown ( self ) : <EOL> yield self . redisClient . disconnect ( ) <EOL> class DataTestCase ( RedisTestCase ) : <EOL> @ defer . inlineCallbacks <EOL> def test_set_get_string ( self ) : <EOL> yield self . redisClient . set ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> g = yield self . redisClient . get ( '<STR_LIT:foo>' ) <EOL> self . assertEqual ( g , '<STR_LIT:bar>' ) <EOL> @ defer . inlineCallbacks <EOL> def test_set_get_list ( self ) : <EOL> yield self . redisClient . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> yield self . redisClient . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> yield self . redisClient . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> yield self . redisClient . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> g = yield self . redisClient . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( g , '<STR_LIT>' ) <EOL> g = yield self . redisClient . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( g , '<STR_LIT>' ) <EOL> g = yield self . redisClient . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( g , '<STR_LIT>' ) <EOL> g = yield self . redisClient . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( g , '<STR_LIT>' ) <EOL> @ defer . inlineCallbacks <EOL> def test_hmset ( self ) : <EOL> yield self . redisClient . hmset ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> g = yield self . redisClient . hmget ( '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( g , [ u'<STR_LIT>' , u'<STR_LIT>' , None ] ) <EOL> g = yield self . redisClient . hgetall ( '<STR_LIT>' ) <EOL> self . assertEqual ( g , { u'<STR_LIT>' : u'<STR_LIT>' , u'<STR_LIT>' : u'<STR_LIT>' } ) <EOL> g = yield self . redisClient . hgetall ( '<STR_LIT>' ) <EOL> self . assertEqual ( g , { } ) <EOL> @ defer . inlineCallbacks <EOL> def test_hmset_expiry ( self ) : <EOL> yield self . redisClient . hmset ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> yield self . redisClient . expire ( '<STR_LIT>' , <NUM_LIT:5> ) <EOL> g = yield self . redisClient . hgetall ( '<STR_LIT>' ) <EOL> self . assertEqual ( g , { u'<STR_LIT>' : u'<STR_LIT>' , u'<STR_LIT>' : u'<STR_LIT>' } ) <EOL> yield waitFor ( <NUM_LIT:6> ) <EOL> g = yield self . redisClient . hgetall ( '<STR_LIT>' ) <EOL> self . assertEqual ( g , { } ) </s>
