class BatchDownloaderDownloadingTestCase(unittest.TestCase): GET_NUM_FILES = 5 def setUp(self): self.linkser = LinksRetriever(THREAD_URL) #self.destination_directory = os.path.expanduser('~/Downloads/TestDownloadThread/') self.thread_dir = TemporaryDirectory(dir=TMP_DIRECTORY) self.destination_directory = self.thread_dir.name self.downloader = BatchDownloader(self.linkser, self.destination_directory) self.download_files() def download_files(self): for url in self.linkser.get_all_file_links()[:self.GET_NUM_FILES]: download_path = utilities.download_file(url, self.downloader.destination_folder) assert os.path.exists(download_path) def test_files_downloaded(self): downloaded = self.downloader.get_files_downloaded() self.assertEqual(len(downloaded), self.GET_NUM_FILES) def test_files_not_downloaded_gen(self): not_downloaded = self.downloader.links_not_downloaded() self.assertIsNotNone(not_downloaded) not_downloaded_tuple = tuple(not_downloaded) self.assertEqual(len(not_downloaded_tuple), len(self.downloader.files_to_download) - len(self.downloader.get_files_downloaded())) def test_compare_downloaded(self): not_downloaded = tuple(self.downloader.get_links_not_downloaded()) self.assertEqual(len(not_downloaded), len(self.linkser.get_all_file_links()) - self.GET_NUM_FILES)
class IgnoreFilteredLinksTestCase(unittest.TestCase): def setUp(self): self.thread_dir = TemporaryDirectory(dir=TMP_DIRECTORY) self.downloader = BatchDownloader(LinksRetriever(STICKY_THREAD_URL), self.thread_dir.name) self.ignore = [os.path.basename(url) for url in ('http://i.4cdn.org/wg/1489266876258.png', 'http://i.4cdn.org/wg/1489266748255.jpg')] self.ifilter = IgnoreFilter(self.ignore, is_regex=True) self.downloader.ifilter = self.ifilter def test_num_links(self): links = tuple(self.downloader.links()) self.assertGreater(len(links), 0) self.assertEqual(len(links), len(self.downloader.get_links_not_downloaded()) - len(self.ignore)) print('Links tuple:', links)