def _download_verify_patches(self): # Downloads & verifies all patches log.debug('Downloading patches') total = 0 if len(self.patch_data) > 3: percent_each = 100 / len(self.patch_data) else: percent_each = None for p in self.patch_data: fd = FileDownloader(p[u'patch_name'], p[u'patch_urls'], p[u'patch_hash'], self.verify) data = fd.download_verify_return() if data is not None: self.patch_binary_data.append(data) # Gathering info to send in signal if percent_each is not None: total += percent_each done = total else: done = '...' progress_signal.send(info=u'Downloading patches', percent=str(done)) else: progress_signal.send(info=u'Failed to download patches', percent=u'...') return False progress_signal.send(info=u'Download Complete', percent=u'100') return True
def _full_update(self, name): # Updates the binary by downloading full update # # Args: # name (str): Name of file to update # # version (str): Current version number of file to update # # Returns: # (bool) Meanings:: # # True - Update Successful # # False - Update Failed log.debug(u'Starting full update') latest = self._get_highest_version(name) filename = self._get_filename(name, latest) hash_key = u'{}*{}*{}*{}*{}'.format(self.updates_key, name, latest, self.platform, u'file_hash') _hash = self.star_access_update_data.get(hash_key) with ChDir(self.update_folder): log.debug(u'Downloading update...') fd = FileDownloader(filename, self.update_urls, _hash, self.verify) result = fd.download_verify_write() if result: log.debug(u'Update Complete') return True else: log.error(u'Failed To Updated To Latest Version') return False
def test_bad_content_length(): with ChDir(u'tests'): class FakeHeaders(object): headers = {} fd = FileDownloader(FILENAME, URL, FILE_HASH) data = FakeHeaders() assert fd._get_content_length(data) == 100000
def test_bad_url(): with ChDir('tests'): fd = FileDownloader(FILENAME, u'bad url', u'bad hash') binary_data = fd.download_verify_return() assert binary_data is None
def test_url_with_spaces(): with ChDir(u'tests'): fd = FileDownloader(FILENAME_WITH_SPACES, URL, FILE_HASH) binary_data = fd.download_verify_return() assert binary_data is not None
def test_download_return_fail(): with ChDir(u'tests'): fd = FileDownloader(FILENAME, URL, u'JKFEIFJILEFJ983NKFNKL') binary_data = fd.download_verify_return() assert binary_data is None
def test_download_return(): with ChDir(u'tests'): fd = FileDownloader(FILENAME, URL, FILE_HASH) binary_data = fd.download_verify_return() assert binary_data is not None
def test_download_write_bad_hash(): with ChDir(u'tests'): fd = FileDownloader(FILENAME, URL, u'38839didkdkflrlrkdfa') success = fd.download_verify_write() assert success is False
def test_good_conent_length(): with ChDir(u'tests'): fd = FileDownloader(FILENAME, URL, FILE_HASH) fd.download_verify_write() assert fd.content_length == 60000
def test_download_write(): with ChDir(u'tests'): fd = FileDownloader(FILENAME, URL, FILE_HASH) success = fd.download_verify_write() assert success is True