def fill_api_data(self, pkg: ArchPackage, package: dict, fill_version: bool = True): version = package.get('Version') if version: version = version.split(':') version = version[0] if len(version) == 1 else version[1] pkg.id = package.get('ID') pkg.name = package.get('Name') if fill_version: pkg.version = version pkg.latest_version = version pkg.description = package.get('Description') pkg.package_base = package.get('PackageBase') pkg.popularity = package.get('Popularity') pkg.votes = package.get('NumVotes') pkg.maintainer = package.get('Maintainer') pkg.url_download = URL_PKG_DOWNLOAD.format( package['URLPath']) if package.get('URLPath') else None pkg.first_submitted = datetime.fromtimestamp( package['FirstSubmitted']) if package.get( 'FirstSubmitted') else None pkg.last_modified = datetime.fromtimestamp( package['LastModified']) if package.get('LastModified') else None pkg.update = self.check_update(pkg.version, pkg.latest_version, check_suffix=pkg.name in BAUH_PACKAGES)
def test_check_update__pkg_no_last_modified_and_latest_version_higher_than_version( self): mapper = AURDataMapper(i18n=Mock(), logger=Mock(), http_client=Mock()) pkg = ArchPackage(name='test') pkg.last_modified = None pkg.version = '1.0.0' pkg.latest_version = '1.1.0' self.assertTrue(mapper.check_update(pkg=pkg, last_modified=1608143812))
def test_check_update__none_last_modified_and_version_equal_latest_version( self): mapper = AURDataMapper(i18n=Mock(), logger=Mock(), http_client=Mock()) pkg = ArchPackage(name='test') pkg.last_modified = 1608143812 pkg.version = '1.0.0' pkg.latest_version = pkg.version self.assertFalse(mapper.check_update(pkg=pkg, last_modified=None))
def test_check_update__pkg_no_last_modified_and_install_date_and_no_last_modified_and_latest_higher( self): mapper = AURDataMapper(i18n=Mock(), logger=Mock(), http_client=Mock()) pkg = ArchPackage(name='test') pkg.last_modified = None pkg.install_date = 1608143812 pkg.version = '1.0.0' pkg.latest_version = '1.1.0' # in this case, install_date will be considered instead of package's last_modified. # as 'install_date' is higher, only the string versions will be compared self.assertTrue(mapper.check_update(pkg=pkg, last_modified=None))
def test_check_update__pkg_last_modified_less_than_last_modified_and_version_higher_than_latest_version( self): mapper = AURDataMapper(i18n=Mock(), logger=Mock(), http_client=Mock()) pkg = ArchPackage(name='test') pkg.last_modified = 1608143812 pkg.version = '2.0.0' pkg.latest_version = '1.0.0' # in this case, last modified is more relevant than the string version self.assertTrue( mapper.check_update(pkg=pkg, last_modified=pkg.last_modified + 100))
def test_check_update__pkg_no_last_modified_and_install_date_less_than_last_modified_and_version_higher_than_latest( self): mapper = AURDataMapper(i18n=Mock(), logger=Mock(), http_client=Mock()) pkg = ArchPackage(name='test') pkg.last_modified = None pkg.install_date = 1608143812 pkg.version = '3.0.0' pkg.latest_version = '2.0.0' # in this case, install_date will be considered instead of package's last_modified. # even that 'version' is higher than 'latest_version', 'last_modified' is greater than 'install_date' self.assertTrue( mapper.check_update(pkg=pkg, last_modified=pkg.install_date + 100))
def fill_api_data(self, pkg: ArchPackage, api_data: dict, fill_version: bool = True): pkg.id = api_data.get('ID') if not pkg.name: pkg.name = api_data.get('Name') if not pkg.description: pkg.description = api_data.get('Description') pkg.package_base = api_data.get('PackageBase') pkg.popularity = api_data.get('Popularity') pkg.votes = api_data.get('NumVotes') pkg.maintainer = api_data.get('Maintainer') pkg.url_download = URL_PKG_DOWNLOAD.format( api_data['URLPath']) if api_data.get('URLPath') else None pkg.out_of_date = bool(api_data.get('OutOfDate')) if api_data['FirstSubmitted'] and isinstance( api_data['FirstSubmitted'], int): pkg.first_submitted = api_data['FirstSubmitted'] if not pkg.installed: self.fill_last_modified(pkg=pkg, api_data=api_data) version = api_data.get('Version') if version: version = version.split(':') version = version[0] if len(version) == 1 else version[1] if fill_version: pkg.version = version pkg.latest_version = version