'Generic helper for cache tests.'

def _test_cache_and_retrieve_resources(self, resource_name):

    cache_all_func = ('cache_db_%ss' % resource_name)
    cache_one_func = ('cache_db_%s' % resource_name)
    get_db_all_func = ('get_db_%ss' % resource_name)
    get_db_one_func = ('get_db_%s' % resource_name)
    r = wsgi.Request.blank('/foo')
    resources = []
    for x in range(3):
        resources.append({'id': ('id%s' % x)})
    getattr(r, cache_all_func)(resources[:2])
    getattr(r, cache_one_func)(resources[2])
    self.assertEqual(resources[0], getattr(r, get_db_one_func)('id0'))
    self.assertEqual(resources[1], getattr(r, get_db_one_func)('id1'))
    self.assertEqual(resources[2], getattr(r, get_db_one_func)('id2'))
    self.assertIsNone(getattr(r, get_db_one_func)('id3'))
    self.assertEqual({'id0': resources[0], 'id1': resources[1], 'id2': resources[2]}, getattr(r, get_db_all_func)())
