def _open(self): """ Initialize EsiPy :return: """ config = key_config.load(self.config_file, self.CONFIG_REQUIREMENTS) self.esi_app = App.create(config['swagger_spec_url']) mc = memcache.Client(['127.0.0.1:11211'], debug=0) cache = MemcachedCache(memcache_client=mc) # init the security object ''' esisecurity = EsiSecurity( app=esiapp, redirect_uri=config.ESI_CALLBACK, client_id=config.ESI_CLIENT_ID, secret_key=config.ESI_SECRET_KEY, ) ''' # init the client self.esi_client = EsiClient( # security=esisecurity, cache=cache, headers={'User-Agent': config['esi_user_agent']})
def test_memcached_invalid_argument(self): with self.assertRaises(TypeError): MemcachedCache(None)
def setUp(self): memcached = memcache.Client(['localhost:11211'], debug=0) self.c = MemcachedCache(memcached)
class TestMemcachedCache(BaseTest): """ Memcached tests """ def setUp(self): memcached = memcache.Client(['localhost:11211'], debug=0) self.c = MemcachedCache(memcached) def tearDown(self): self.c._mc.disconnect_all() def test_memcached_get_set(self): self.c.set(*self.ex_str) self.c.set(*self.ex_int) self.c.set(*self.ex_cpx) self.assertEqual(self.c.get(self.ex_str[0]), self.ex_str[1]) self.assertEqual(self.c.get(self.ex_int[0]), self.ex_int[1]) self.check_complex(self.c.get(self.ex_cpx[0])) self.c.set('expired', 'baz', -1) self.assertEqual(self.c.get('expired'), None) def test_memcached_invalidate(self): self.c.set(*self.ex_str) self.assertEqual(self.c.get(self.ex_str[0]), self.ex_str[1]) self.c.invalidate(self.ex_str[0]) self.assertEqual(self.c.get(self.ex_str[0]), None) def test_memcached_invalid_argument(self): with self.assertRaises(TypeError): MemcachedCache(None)
class TestMemcachedCache(BaseTest): """ Memcached tests """ def setUp(self): memcached = memcache.Client(['localhost:11211'], debug=0) self.c = MemcachedCache(memcached) def tearDown(self): self.c.invalidate(self.ex_str[0]) self.c.invalidate(self.ex_int[0]) self.c.invalidate(self.ex_cpx[0]) self.c._mc.disconnect_all() def test_memcached_get_set(self): self.c.set(*self.ex_str) self.c.set(*self.ex_int) self.c.set(*self.ex_cpx) self.assertEqual(self.c.get(self.ex_str[0]), self.ex_str[1]) self.assertEqual(self.c.get(self.ex_int[0]), self.ex_int[1]) self.check_complex(self.c.get(self.ex_cpx[0])) def test_memcached_update(self): self.c.set( self.ex_cpx[0], CachedResponse( status_code=200, headers={'foo', 'test'}, content='Nothing'.encode('latin-1'), url='http://foobarbaz.com' ) ) self.c.set(*self.ex_cpx) self.check_complex(self.c.get(self.ex_cpx[0])) def test_memcached_invalidate(self): self.c.set(*self.ex_str) self.assertEqual(self.c.get(self.ex_str[0]), self.ex_str[1]) self.c.invalidate(self.ex_str[0]) self.assertEqual(self.c.get(self.ex_str[0]), None) def test_memcached_invalid_argument(self): with self.assertRaises(TypeError): MemcachedCache(None) def test_memcached_expire(self): self.c.set(self.ex_str[0], self.ex_str[1], expire=1) self.assertEqual(self.c.get(self.ex_str[0]), self.ex_str[1]) time.sleep(1) self.assertEqual(self.c.get(self.ex_str[0], None), None) self.c.set(self.ex_str[0], self.ex_str[1], expire=0) self.assertEqual(self.c.get(self.ex_str[0]), self.ex_str[1]) time.sleep(1) self.assertEqual(self.c.get(self.ex_str[0], None), self.ex_str[1]) self.c.set(self.ex_int[0], self.ex_int[1], expire=None) self.assertEqual(self.c.get(self.ex_int[0]), self.ex_int[1]) time.sleep(1) self.assertEqual(self.c.get(self.ex_int[0], None), self.ex_int[1])