def test_progress_json(self): """ Make sure the JSON encoding isn't broken """ progg = ProgressManifest( downloaders=[DownloaderProgress(), DownloaderProgress()], loader=LoaderProgress(), deduplication=True, running=False) self.assertIsNotNone(json.dumps(progg.to_obj()))
def mock_handler_request(base_dir, target_url): """ Simplify generating a HandlerTask, DownloaderProgress, & RelFile object combo, for Handler tests. """ import processing.handlers as handlers from processing.wrappers import SanitizedRelFile, DownloaderProgress filename = str(uuid.uuid4()) _file = SanitizedRelFile(base=base_dir, file_path=filename) _task = handlers.HandlerTask(url=target_url, file_obj=_file) _prog = DownloaderProgress() return _task, _prog, _file
def __init__(self, settings_json, stop_event): """ Create a Hasher Process, which will be bound to the stop_event, performing post-processing on downloaded Files. """ super().__init__() self._settings = settings_json self._stop_event = stop_event self.progress = DownloaderProgress() self.progress.clear(status="Starting up...") self._session = None self.daemon = True
def __init__(self, reader, ack_queue, settings_json): """ Create a Downloader Process, which will be bound to the queue given, listening for URLs to download. """ super().__init__() self._reader = reader self._settings = settings_json self.progress = DownloaderProgress() self._session = None self._ack_queue = ack_queue self.daemon = True
def test_binary(self): """ Download a binary file """ file = rel.SanitizedRelFile(self.dir, 'test_file') prog = DownloaderProgress() res = http.download_binary(url='https://i.imgur.com/8770jp0.png', rel_file=file, prog=prog, handler_id='test-run') self.assertTrue(res.success, "The test file failed to download!") self.assertTrue(file.exists(), "Failed to download the test binary!") self.assertIn('.png', file.absolute(), "Downloaded invalid filetype!") # Downloaded a PNG. self.assertEqual('100', prog.get_percent(), 'Download did not reach 100%!')