def test_error_results(self, fetch_and_save_file): "Sets the correct error values if things go wrong." fetch_and_save_file.side_effect = FetchError('Oh dear') results = FilesFetcher().fetch() self.assertFalse(results[0]['success']) self.assertEqual(results[0]['fetched'], 0) self.assertEqual(len(results[0]['messages']), 4) self.assertEqual(results[0]['messages'][0], 'Oh dear')
def test_calls_fetch_and_save_missing(self, fetch_and_save_file): "Goes to fetch for media without files already." results = FilesFetcher().fetch() calls = [ call(media_obj=self.image, media_type='image'), call(media_obj=self.animated_gif, media_type='image'), call(media_obj=self.animated_gif, media_type='mp4'), call(media_obj=self.video, media_type='image'), ] fetch_and_save_file.assert_has_calls(calls)
def test_calls_fetch_and_save_all(self, fetch_and_save_file): "Goes to fetch for ALL media." results = FilesFetcher().fetch(fetch_all=True) calls = [ call(media_obj=self.fetched_image, media_type='image'), call(media_obj=self.image, media_type='image'), call(media_obj=self.animated_gif, media_type='image'), call(media_obj=self.animated_gif, media_type='mp4'), call(media_obj=self.video, media_type='image'), ] fetch_and_save_file.assert_has_calls(calls)
def test_results_for_fetch_all(self, fetch_and_save_file): results = FilesFetcher().fetch(fetch_all=True) self.assertEqual(len(results), 1) self.assertTrue(results[0]['success']) self.assertEqual(results[0]['fetched'], 5)
def test_results_for_fetch_missing(self, fetch_and_save_file): results = FilesFetcher().fetch() self.assertEqual(len(results), 1) self.assertTrue(results[0]['success']) # Three images and one MP4 file: self.assertEqual(results[0]['fetched'], 4)
def test_calls_fetch_files_with_all(self, fetch): results = FilesFetcher().fetch(fetch_all=True) fetch.assert_has_calls([call(fetch_all=True)])
def test_calls_fetch_files(self, fetch): results = FilesFetcher().fetch() fetch.assert_has_calls([call(fetch_all=False)])