def test_cache(self):
        client = mock.Mock()

        store = MemcacheBackingStore(60, client)
        store.cache("get_templates", "content")

        client.set.assert_called_with("get_templates", "content")
    def test_exists_for_invalid_key(self):
        client = mock.Mock()
        client.get.return_value = None

        store = MemcacheBackingStore(60, client)
        self.assertFalse(store.exists("get_templates"))

        client.get.assert_called_once_with("get_templates")
    def test_exists(self):
        client = mock.Mock()
        client.get.return_value = (10, "value")

        store = MemcacheBackingStore(60, client)
        self.assertTrue(store.exists("get_templates"))

        client.get.assert_called_once_with("get_templates")
    def test_retrieve_generic_exc_handling(self):
        client = mock.Mock()
        client.get.side_effect = Exception("error")

        store = MemcacheBackingStore(5, client)
        result = store.retrieve("get_templates")

        self.assertIsNone(result)
    def test_retrieve_pylib_exc_handling(self):
        client = mock.Mock()
        client.get.side_effect = pylibmc.Error()

        store = MemcacheBackingStore(5, client)
        result = store.retrieve("get_templates")

        self.assertIsNone(result)
    def test_retrieve(self):
        client = mock.Mock()
        client.get.return_value = (10, "content")

        store = MemcacheBackingStore(60, client)
        result = store.retrieve("get_templates")

        self.assertEqual((10, "content"), result)
        client.get.assert_called_once_with("get_templates")
    def test_cache_pylibmc_exc_handling(self):
        client = mock.Mock()
        client.set.side_effect = Exception("msg")

        store = MemcacheBackingStore(60, client)
        store.cache("get_templates", "content")