Пример #1
0
def test_has_same_hash(hash_name, match, mocker, faker):
    """Ensure method returns True when checksum matches and False otherwise"""
    file_path = faker.file_path()
    remote_hash = getattr(faker, hash_name)()
    if match:
        local_hash = remote_hash
    else:
        local_hash = getattr(faker, hash_name)()

    mocker.patch('nexuscli.nexus_util.calculate_hash', return_value=local_hash)
    artefact = {'checksum': {hash_name: remote_hash}}

    assert match == nexus_util.has_same_hash(artefact, file_path)
    nexus_util.calculate_hash.assert_called_with(hash_name, file_path)
Пример #2
0
    def _should_skip_download(download_url, download_path, artefact, nocache):
        """False when nocache is set or local file is out-of-date"""
        if nocache:
            try:
                LOG.debug('Removing {} because nocache is set\n'.format(
                    download_path))
                os.remove(download_path)
            except FileNotFoundError:
                pass
            return False

        if nexus_util.has_same_hash(artefact, download_path):
            LOG.debug(f'Skipping {download_url} because local copy '
                      f'{download_path} is up-to-date\n')
            return True

        return False
Пример #3
0
def test_has_same_hash_empty():
    """Ensure method returns false when artefact has no checksum entries"""
    assert not nexus_util.has_same_hash({}, 'any')