diff --git a/.build b/.build index b6a7d89..98d9bcb 100644 --- a/.build +++ b/.build @@ -1 +1 @@ -16 +17 diff --git a/pylast.py b/pylast.py index 588401f..051007c 100644 --- a/pylast.py +++ b/pylast.py @@ -986,15 +986,15 @@ class _ShelfCacheBackend(object): def __init__(self, file_path=None): self.shelf = shelve.open(file_path) + def __iter__(self): + return iter(self.shelf.keys()) + def get_xml(self, key): return self.shelf[key] def set_xml(self, key, xml_string): self.shelf[key] = xml_string - def has_key(self, key): - return key in self.shelf.keys() - class _Request(object): """Representing an abstract web service operation.""" @@ -1073,7 +1073,7 @@ class _Request(object): def _is_cached(self): """Returns True if the request is already in cache.""" - return self.cache.has_key(self._get_cache_key()) + return self._get_cache_key() in self.cache def _download_response(self): """Returns a response body string from the server.""" diff --git a/test_pylast.py b/test_pylast.py index 18cd691..3a583f5 100755 --- a/test_pylast.py +++ b/test_pylast.py @@ -1393,6 +1393,21 @@ class TestPyLast(unittest.TestCase): # Assert self.helper_only_one_thing_in_top_list(albums, pylast.Album) + def test_caching(self): + # Arrange + user = self.network.get_user("RJ") + + # Act + self.network.enable_caching() + shouts1 = user.get_shouts(limit=1, cacheable=True) + shouts2 = user.get_shouts(limit=1, cacheable=True) + + # Assert + self.assertTrue(self.network.is_caching_enabled()) + self.assertEqual(shouts1, shouts2) + self.network.disable_caching() + self.assertFalse(self.network.is_caching_enabled()) + if __name__ == '__main__': parser = argparse.ArgumentParser(