def test_cancellation(self): """ Asserts: 1. Cancel for a download and clean up of the downloaded file. 2. Model attributes (Process percent, detail, status) """ url = "http://speedtest.ftp.otenet.gr/files/test10Mb.db" url_dwld = downloader.UrlDownloader(url) loop = asyncio.get_event_loop() fut = loop.run_in_executor(None, url_dwld.download) def cancel(): fut.cancel() url_dwld.cancel_download() @asyncio.coroutine def sleep(): yield from asyncio.sleep(2) cancel() yield from asyncio.sleep(2) loop.run_until_complete(sleep()) self._display_result(url_dwld) assert url_dwld.meta.status == downloader.DownloadStatus.CANCELLED assert url_dwld.meta.bytes_downloaded == url_dwld.meta.bytes_downloaded assert "cancel" in url_dwld.meta.detail self._common_checks(url_dwld.meta)
def download_package(self): _, filename = tempfile.mkstemp() url_downloader = downloader.UrlDownloader( self.url, auth=self.auth, file_obj=filename, decompress_on_fly=True, log=self.log) url_downloader.delegate = self url_downloader.download()
def download_package(self): self.log.debug("Before pkg download, project = {}".format(self.project.name)) _, filename = tempfile.mkstemp() url_downloader = downloader.UrlDownloader( self.url, auth=self.auth, file_obj=filename, decompress_on_fly=True, log=self.log) url_downloader.delegate = self url_downloader.download()
def test_file_not_exists(self): """ Asserts: 1. 404 download with retries 2. Model attributes (Process percent, detail, status) """ url_downl = downloader.UrlDownloader(TEST_URL + ".blah") url_downl.download() self._display_result(url_downl) assert not os.path.isfile(url_downl.filepath) assert url_downl.meta.status == downloader.DownloadStatus.FAILED assert "Max retries" in url_downl.meta.detail or "404" in url_downl.meta.detail self._common_checks(url_downl.meta)
def test_file_download(self): """ Asserts: 1. Successful download 2. Model attributes (Process percent, detail, status) """ url_downl = downloader.UrlDownloader(TEST_URL) url_downl.download() assert os.path.isfile(url_downl.filepath) self._display_result(url_downl) assert url_downl.meta.status == downloader.DownloadStatus.COMPLETED # assert url_downl.job.progress_percent == 100 assert "success" in url_downl.meta.detail self._common_checks(url_downl.meta)
def test_auth_url(self): url_downl = downloader.UrlDownloader('https://api.github.com/user') url_downl.download() self._display_result(url_downl)