class BatchDownloaderDetailsTestCase(unittest.TestCase): def setUp(self): self.linkser = LinksRetriever(THREAD_URL) self.destination_directory = os.path.expanduser(TMP_DIRECTORY) self.downloader = BatchDownloader(self.linkser, self.destination_directory) self.downloader.pickle_details() def test_construct_details_dict(self): details = self.downloader.construct_details_dict() keys = details.keys() self.assertIn('last-modified', keys) self.assertTrue(isinstance(details['last-modified'], str)) self.assertIn('url', keys) self.assertTrue(isinstance(details['url'], str)) self.assertIn('thread_alive', keys) self.assertTrue(isinstance(details['thread_alive'], bool)) def test_load_details(self): down = BatchDownloader(self.linkser, TemporaryDirectory(dir=TMP_DIRECTORY).name) details = down.construct_details_dict() down.pickle_details() loaded = BatchDownloader.load_details_into_dict(self.downloader.get_details_path()) self.assertTrue(isinstance(loaded, dict)) self.assertEqual(loaded, details) def test_compare_details(self): down = BatchDownloader(self.linkser, TemporaryDirectory(dir=TMP_DIRECTORY).name) details = down.construct_details_dict() down.pickle_details() loaded = BatchDownloader.load_details_into_dict(self.downloader.get_details_path()) self.assertEqual(loaded['last-modified'], details['last-modified']) self.assertEqual(loaded['url'], details['url']) self.assertEqual(loaded['thread_alive'], details['thread_alive']) def test_pickle_details_custom_details(self): download_dir = TemporaryDirectory(dir=TMP_DIRECTORY) custom_details = {'last-modified':'123456', 'thread_alive': False, 'url':THREAD_URL} down = BatchDownloader(self.linkser, download_dir.name) #details = down.construct_details_dict() down.pickle_details(custom_details) loaded = BatchDownloader.load_details_into_dict(down.get_details_path()) self.assertEqual(loaded['last-modified'], custom_details['last-modified']) self.assertEqual(loaded['url'], custom_details['url']) self.assertEqual(loaded['thread_alive'], custom_details['thread_alive'])
def test_pickle_details_custom_details(self): download_dir = TemporaryDirectory(dir=TMP_DIRECTORY) custom_details = {'last-modified':'123456', 'thread_alive': False, 'url':THREAD_URL} down = BatchDownloader(self.linkser, download_dir.name) #details = down.construct_details_dict() down.pickle_details(custom_details) loaded = BatchDownloader.load_details_into_dict(down.get_details_path()) self.assertEqual(loaded['last-modified'], custom_details['last-modified']) self.assertEqual(loaded['url'], custom_details['url']) self.assertEqual(loaded['thread_alive'], custom_details['thread_alive'])