def test_cache_populated(self): vid = VideoFactory.build(youtube_id="123") cache.set(VIDEO_TITLE_CACHE_PREFIX + "123", { "title": "henlo", "description": "bluh bluh" }) results = list(video_add_titles([vid])) self.assertEqual(results, [vid]) self.assertEqual(vid.title, "henlo") self.assertEqual(vid.description, "bluh bluh") self.assertEqual(self.video_mock.call_count, 0)
def test_clean_cache(self): vid = VideoFactory.build(youtube_id="123") cached_data = cache.get(VIDEO_TITLE_CACHE_PREFIX + "123") self.assertEqual(cached_data, None) results = list(video_add_titles([vid])) self.assertEqual(results, [vid]) self.assertEqual(vid.title, "henlo") self.assertEqual(vid.description, "bluh bluh") self.assertEqual(self.video_mock.call_count, 1) self.assertEqual(self.video_mock.call_args[1]["id"], "123") cached_data = cache.get(VIDEO_TITLE_CACHE_PREFIX + "123") self.assertEqual(cached_data, { "title": "henlo", "description": "bluh bluh" })