def test_persistent_error(self): """ Test persistent not cache error """ registry = getUtility(IRegistry) embedly_settings = registry.forInterface(IEmbedlySettings) embedly_settings.persistent_cache = True get_oembed(self.obj_url, u'1234') storage = IAnnotations(self.layer['portal']) self.assertEqual(0, len(storage['_embedly_persistent_'])) get_oembed(self.obj_url) self.assertEqual(1, len(storage['_embedly_persistent_']))
def test_persistent_timeout(self): """ Test persistent cache timeout """ registry = getUtility(IRegistry) embedly_settings = registry.forInterface(IEmbedlySettings) embedly_settings.persistent_cache = True get_oembed(self.obj_url) storage = IAnnotations(self.layer['portal']) self.assertEqual(1, len(storage['_embedly_persistent_'])) embedly_settings.cache_timeout = 1 get_oembed(self.obj_url) self.assertEqual(2, len(storage['_embedly_persistent_']))
def test_cache_timeout(self): """ Test cache timeout """ ramcache = queryUtility(IRAMCache) registry = getUtility(IRegistry) embedly_settings = registry.forInterface(IEmbedlySettings) get_oembed(self.obj_url) stats = filter(embedly_filter, ramcache.getStatistics()) self.assertEqual(1, stats[0]['entries']) embedly_settings.cache_timeout = 1 get_oembed(self.obj_url) stats = filter(embedly_filter, ramcache.getStatistics()) self.assertEqual(2, stats[0]['entries'])
def test_no_key_url(self): """ Test query with initial api_key """ registry = getUtility(IRegistry) embedly_settings = registry.forInterface(IEmbedlySettings) self.assertFalse(embedly_settings.api_key) res = get_oembed(self.obj_url, embedly_settings.api_key) self.assertEqual(res, json_result)
def test_persistent_entries(self): """ Test persistent cache entries """ registry = getUtility(IRegistry) embedly_settings = registry.forInterface(IEmbedlySettings) embedly_settings.persistent_cache = True res = get_oembed(self.obj_url) self.assertEqual(res, json_result) storage = IAnnotations(self.layer['portal']) self.assertEqual(1, len(storage['_embedly_persistent_']))
def test_persistent_cache(self): """ Test persistent cache """ registry = getUtility(IRegistry) embedly_settings = registry.forInterface(IEmbedlySettings) self.assertFalse(embedly_settings.persistent_cache) embedly_settings.persistent_cache = True res = get_oembed(self.obj_url) self.assertEqual(res, json_result)
def test_cache_stats(self): """ Test cache stats """ ramcache = queryUtility(IRAMCache) get_oembed(self.obj_url) stats = filter(embedly_filter, ramcache.getStatistics()) self.assertEqual(0, stats[0]['hits']) get_oembed(self.obj_url) stats = filter(embedly_filter, ramcache.getStatistics()) self.assertEqual(1, stats[0]['hits']) get_oembed(self.obj_url) stats = filter(embedly_filter, ramcache.getStatistics()) self.assertEqual(2, stats[0]['hits'])
def test_embedly_params(self): """ Test query with additional embedly parameters """ url = "http://www.youtube.com/watch?v=L1NPLlhFTVk&maxwidth=10&maxheight=10" res = get_oembed(url) self.assertEqual(res, json_result)
def test_empty_key(self): """ Test query with empty api_key """ res = get_oembed(self.obj_url, u' ') self.assertEqual(res, json_result)
def test_fake_key(self): """ Test query with not valid api_key """ res = get_oembed(self.obj_url, u'1234') self.assertNotEqual(res, json_result)
def test_normal_key(self): """ Test query with embedly api_key """ res = get_oembed(self.obj_url, u'1234567890abcdef1234567890abcdef') self.assertEqual(res, json_result)