Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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))
Exemplo n.º 3
0
    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))
Exemplo n.º 4
0
 def fill_last_modified(self, pkg: ArchPackage, api_data: dict):
     last_modified = api_data.get('LastModified')
     if last_modified is not None and isinstance(last_modified, int):
         pkg.last_modified = last_modified
         self.logger.info(
             "'last_modified' field ({}) set to package '{}'".format(
                 last_modified, pkg.name))
     else:
         self.logger.warning(
             "Could not set the 'last_modified' field ({}) to package '{}'".
             format(last_modified, pkg.name))
Exemplo n.º 5
0
    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))
Exemplo n.º 6
0
    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))
Exemplo n.º 7
0
    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))