def test_fetch_from_empty_cache(self): """Test if there are not any events returned when the cache is empty""" cache = Cache(self.tmp_path) mozillaclub = MozillaClub(MozillaClub_FEED_URL, cache=cache) cached_events = [event for event in mozillaclub.fetch_from_cache()] self.assertEqual(len(cached_events), 0)
def test_fetch_from_non_set_cache(self): """Test if a error is raised when the cache was not set""" mozillaclub = MozillaClub(MozillaClub_FEED_URL) with self.assertRaises(CacheError): _ = [event for event in mozillaclub.fetch_from_cache()]
def test_fetch_from_cache(self): """Test whether the cache works""" http_requests = configure_http_server() # First, we fetch the events from the server, storing them # in a cache cache = Cache(self.tmp_path) mozillaclub = MozillaClub(MozillaClub_FEED_URL, cache=cache) events = [event for event in mozillaclub.fetch()] self.assertEqual(len(http_requests), 1) # Now, we get the events from the cache. # The contents should be the same and there won't be # any new request to the server cached_events = [event for event in mozillaclub.fetch_from_cache()] self.assertEqual(len(cached_events), len(events)) for i in range(0, len(events)): self.assertDictEqual(cached_events[i]['data'], events[i]['data']) self.assertEqual(len(http_requests), 1) # no more requests done