Exemplo n.º 1
0
def test_repository_helpers_properties_pending_update():
    repository = HacsRepository()
    repository.hacs.system.ha_version = "0.109.0"
    repository.data.homeassistant = "0.110.0"
    repository.data.releases = True
    assert not repository.pending_update

    repository = HacsRepository()
    repository.data.installed = True
    repository.data.default_branch = "master"
    repository.data.selected_tag = "master"
    assert not repository.pending_update

    repository.data.installed_commit = "1"
    repository.data.last_commit = "2"
    assert repository.pending_update
Exemplo n.º 2
0
def dummy_repository_base(repository=None):
    if repository is None:
        repository = HacsRepository()
    repository.hacs.hass = HomeAssistant()
    repository.hacs.hass.data = {"custom_components": []}
    repository.hacs.system.config_path = tempfile.gettempdir()
    repository.logger = getLogger("test.test")
    repository.data.full_name = "test/test"
    repository.data.domain = "test"
    repository.data.last_version = "3"
    repository.data.selected_tag = "3"
    repository.ref = version_to_install(repository)
    repository.integration_manifest = {"config_flow": False, "domain": "test"}
    repository.data.published_tags = ["1", "2", "3"]
    repository.data.update_data(repository_data)
    return repository
Exemplo n.º 3
0
def test_restore_repository_data():
    repo = HacsRepository()
    data = {
        "description": "test",
        "installed": True,
        "full_name": "hacs/integration"
    }
    restore_repository_data(repo, data)
    assert repo.data.description == "test"
Exemplo n.º 4
0
def test_hacs_can_install():
    hacs = get_hacs()
    repository = HacsRepository()
    repository.repository_manifest = {"test": "test"}
    repository.data.releases = True

    hacs.system.ha_version = "1.0.0"
    repository.data.homeassistant = "1.0.0b1"
    assert repository.can_install

    hacs.system.ha_version = "1.0.0b1"
    repository.data.homeassistant = "1.0.0"
    assert not repository.can_install

    hacs.system.ha_version = "1.0.0b1"
    repository.data.homeassistant = "1.0.0b2"
    assert not repository.can_install

    hacs.system.ha_version = "1.0.0"
    repository.data.homeassistant = "1.0.0"
    assert repository.can_install
Exemplo n.º 5
0
def test_hacs_repository_core_can_install_manifest():
    repository = HacsRepository()
    repository.hacs.system.ha_version = "1.0.0"
    repository.data.releases = True

    repository.data.homeassistant = "1.1.0"
    assert not repository.can_install

    repository.data.homeassistant = "1.0.0"
    assert repository.can_install

    repository.data.homeassistant = "0.1.0"
    assert repository.can_install
Exemplo n.º 6
0
def test_repository_helpers_properties_custom():
    repository = HacsRepository()

    repository.data.full_name = "test/test"
    assert repository.custom

    repository.data.id = 1337
    repository.hacs.common.default.append(repository.data.id)
    assert not repository.custom

    repository.hacs.common.default = []
    assert repository.custom

    repository.data.full_name = "hacs/integration"
    assert not repository.custom
Exemplo n.º 7
0
def test_hacs_repository_core_mostly_defaults():
    repository = HacsRepository()

    repository.data.full_name = "developer/repository"
    repository.data.default_branch = "master"
    repository.data.description = "Awesome GitHub repository"

    assert repository.display_name == "Repository"
    assert repository.custom
    assert repository.display_status == "new"
    assert repository.display_status_description == "This is a newly added repository."
    assert repository.main_action == "INSTALL"
    assert repository.display_version_or_commit == "commit"
    assert repository.display_available_version == ""
    assert repository.display_installed_version == ""
    assert repository.can_install
    assert not repository.pending_upgrade
Exemplo n.º 8
0
def test_repository_helpers_properties_can_be_installed():
    repository = HacsRepository()
    assert repository.can_be_installed
Exemplo n.º 9
0
async def common_update_data(repository: HacsRepository,
                             ignore_issues=False,
                             force=False):
    """Common update data."""
    hacs = get_hacs()
    releases = []
    try:
        repository_object, etag = await get_repository(
            hacs.session,
            hacs.configuration.token,
            repository.data.full_name,
            etag=None if force or repository.data.installed else
            repository.data.etag_repository,
        )
        repository.repository_object = repository_object
        if repository.data.full_name.lower(
        ) != repository_object.full_name.lower():
            hacs.common.renamed_repositories[
                repository.data.full_name] = repository_object.full_name
            if str(repository_object.id) not in hacs.common.default:
                hacs.common.default.append(str(repository_object.id))
            raise HacsRepositoryExistException
        repository.data.update_data(repository_object.attributes)
        repository.data.etag_repository = etag
    except HacsNotModifiedException:
        return
    except HacsRepositoryExistException:
        raise HacsRepositoryExistException from None
    except (AIOGitHubAPIException, HacsException) as exception:
        if not hacs.status.startup:
            repository.logger.error("%s %s", repository, exception)
        if not ignore_issues:
            repository.validate.errors.append("Repository does not exist.")
            raise HacsException(exception) from None

    # Make sure the repository is not archived.
    if repository.data.archived and not ignore_issues:
        repository.validate.errors.append("Repository is archived.")
        hacs.common.archived_repositories.append(repository.data.full_name)
        raise HacsRepositoryArchivedException("Repository is archived.")

    # Make sure the repository is not in the blacklist.
    if is_removed(repository.data.full_name) and not ignore_issues:
        repository.validate.errors.append("Repository is in the blacklist.")
        raise HacsException("Repository is in the blacklist.")

    # Get releases.
    try:
        releases = await get_releases(
            repository.repository_object,
            repository.data.show_beta,
            hacs.configuration.release_limit,
        )
        if releases:
            repository.data.releases = True
            repository.releases.objects = [x for x in releases if not x.draft]
            repository.data.published_tags = [
                x.tag_name for x in repository.releases.objects
            ]
            repository.data.last_version = next(
                iter(repository.data.published_tags))

    except (AIOGitHubAPIException, HacsException):
        repository.data.releases = False

    if not repository.force_branch:
        repository.ref = version_to_install(repository)
    if repository.data.releases:
        for release in repository.releases.objects or []:
            if release.tag_name == repository.ref:
                assets = release.assets
                if assets:
                    downloads = next(
                        iter(assets)).attributes.get("download_count")
                    repository.data.downloads = downloads

    repository.logger.debug("%s Running checks against %s", repository,
                            repository.ref.replace("tags/", ""))

    try:
        repository.tree = await get_tree(repository.repository_object,
                                         repository.ref)
        if not repository.tree:
            raise HacsException("No files in tree")
        repository.treefiles = []
        for treefile in repository.tree:
            repository.treefiles.append(treefile.full_path)
    except (AIOGitHubAPIException, HacsException) as exception:
        if not hacs.status.startup:
            repository.logger.error("%s %s", repository, exception)
        if not ignore_issues:
            raise HacsException(exception) from None