def _check_tags(self, _callable, tags, *args, **kwargs): self.local_cache.clear() self.cache.reset_mock() for tag in tags: self.assertNotIn(create_tag_cache_key(tag), self.local_cache) result = _callable(*args, **kwargs) for tag in tags: self.assertIn(create_tag_cache_key(tag), self.local_cache) self.cache.assert_called_once_with(result) self.cache.reset_mock() # invalidate by tag for tag in tags: invalidate_cache_tags(tag) result = _callable(*args, **kwargs) self.cache.assert_called_once_with(result) self.cache.reset_mock() _callable(*args, **kwargs) self.assertFalse(self.cache.called) _callable.invalidate_cache_by_tags(tag, *args, **kwargs) result = _callable(*args, **kwargs) self.cache.assert_called_once_with(result) self.cache.reset_mock()
def _check_cache_prefix(self, _callable, prefix, *args, **kwargs): self.local_cache.clear() self.cache.reset_mock() as_property = getattr(_callable, 'property', False) tag_prefix = create_tag_cache_key(prefix) self.assertNotIn(tag_prefix, self.local_cache) result = _callable(*args, **kwargs) self.assertIn(tag_prefix, self.local_cache) self.assertTrue(self.local_cache.search_prefix(prefix)) if as_property: self.cache.assert_called_once_with() else: self.cache.assert_called_once_with(result) self.cache.reset_mock() _callable(*args, **kwargs) self.assertFalse(self.cache.called) _callable.invalidate_cache_by_prefix(*args, **kwargs) result = _callable(*args, **kwargs) if as_property: self.cache.assert_called_once_with() else: self.cache.assert_called_once_with(result) self.cache.reset_mock()