Beispiel #1
0
async def test_frontend_debug():
    hacs = get_hacs()
    hacs.hass = HomeAssistant()
    hacs.configuration = Configuration()
    hacs.configuration.debug = True
    await async_serve_frontend()
    hacs.configuration = Configuration()
Beispiel #2
0
async def test_frontend_repo(tmpdir):
    hacs = get_hacs()
    hacs.hass = HomeAssistant()
    hacs.configuration = Configuration()
    hacs.configuration.frontend_repo = tmpdir

    await async_serve_frontend()

    os.makedirs(f"{tmpdir}/hacs_frontend", exist_ok=True)
    with open(f"{tmpdir}/hacs_frontend/main.js", "w") as target:
        target.write("")

    await async_serve_frontend()

    hacs.configuration = Configuration()
async def test_common_blacklist(aresponses, event_loop):
    aresponses.add(
        "api.github.com",
        "/rate_limit",
        "get",
        aresponses.Response(body=b"{}",
                            headers=response_rate_limit_header,
                            status=200),
    )
    aresponses.add(
        "api.github.com",
        "/repos/test/test",
        "get",
        aresponses.Response(body=json.dumps(repository_data),
                            headers=response_rate_limit_header),
    )
    async with aiohttp.ClientSession(loop=event_loop) as session:
        hacs = get_hacs()
        hacs.session = session
        hacs.configuration = Configuration()
        hacs.configuration.token = TOKEN
        removed = get_removed("test/test")
        assert removed.repository == "test/test"
        repository = dummy_repository_base()
        with pytest.raises(HacsException):
            await common_validate(repository)
Beispiel #4
0
async def async_setup_entry(hass, config_entry):
    """Set up this integration using UI."""
    hacs = get_hacs()
    conf = hass.data.get(DOMAIN)
    if conf is not None:
        return False
    if config_entry.source == config_entries.SOURCE_IMPORT:
        hass.async_create_task(hass.config_entries.async_remove(config_entry.entry_id))
        return False
    hacs.hass = hass
    hacs.session = async_create_clientsession(hass)
    hacs.configuration = Configuration.from_dict(
        config_entry.data, config_entry.options
    )
    hacs.configuration.config_type = "flow"
    hacs.configuration.config_entry = config_entry
    config_entry.add_update_listener(reload_hacs)
    try:
        startup_result = await hacs_startup()
    except AIOGitHubAPIException:
        startup_result = False
    if not startup_result:
        hacs.system.disabled = True
        raise ConfigEntryNotReady
    hacs.system.disabled = False
    return startup_result
Beispiel #5
0
def test_configuration_and_option():
    config = Configuration.from_dict({"token": "xxxxxxxxxx"}, {})

    assert isinstance(config.options, dict)
    assert isinstance(config.config, dict)

    assert isinstance(config.token, str)
    assert config.token == "xxxxxxxxxx"

    assert isinstance(config.sidepanel_title, str)
    assert config.sidepanel_title == "Community"

    assert isinstance(config.sidepanel_icon, str)
    assert config.sidepanel_icon == "mdi:alpha-c-box"

    assert isinstance(config.appdaemon, bool)
    assert not config.appdaemon

    assert isinstance(config.python_script, bool)
    assert not config.python_script

    assert isinstance(config.theme, bool)
    assert not config.theme

    assert isinstance(config.options, dict)

    assert isinstance(config.country, str)
    assert config.country == "ALL"

    assert isinstance(config.release_limit, int)
    assert config.release_limit == 5

    assert isinstance(config.experimental, bool)
    assert not config.experimental
Beispiel #6
0
async def async_setup(hass, config):
    """Set up this integration using yaml."""
    hacs = get_hacs()
    if DOMAIN not in config:
        return True
    if hacs.configuration and hacs.configuration.config_type == "flow":
        return True

    configuration = config[DOMAIN]

    if configuration.get(FRONTEND_REPO) and configuration.get(
            FRONTEND_REPO_URL):
        hacs.logger.critical(
            "Could not setup HACS, set only one of ('frontend_repo', 'frontend_repo_url)"
        )

        return False

    hass.data[DOMAIN] = config
    hacs.hass = hass
    hacs.session = async_create_clientsession(hass)
    hacs.configuration = Configuration.from_dict(configuration)
    hacs.configuration.config = config
    hacs.configuration.config_type = "yaml"
    await startup_wrapper_for_yaml()
    return True
async def test_common_base_exception_does_not_exsist(aresponses, event_loop):
    aresponses.add(
        "api.github.com",
        "/rate_limit",
        "get",
        aresponses.Response(headers=response_rate_limit_header_with_limit,
                            status=500),
    )
    aresponses.add(
        "api.github.com",
        "/repos/test/test",
        "get",
        aresponses.Response(
            body=json.dumps({"message": "X"}),
            headers=response_rate_limit_header_with_limit,
            status=500,
        ),
    )

    async with aiohttp.ClientSession(loop=event_loop) as session:
        hacs = get_hacs()
        hacs.session = session
        hacs.configuration = Configuration()
        hacs.configuration.token = TOKEN
        hacs.system.status.startup = False
        repository = dummy_repository_base()
        with pytest.raises(HacsException):
            await common_validate(repository)
Beispiel #8
0
async def test_frontend_view_class():
    hacs = get_hacs()
    hacs.hass = HomeAssistant()
    hacs.configuration = Configuration()
    frontend = HacsFrontend()
    await frontend.get({}, "test")
    await frontend.get({}, "class-map.js.map")
    await frontend.get({}, "frontend-test")
    await frontend.get({}, "iconset.js")
Beispiel #9
0
async def test_hacs_data_async_write2(tmpdir):
    data = HacsData()
    hacs = get_hacs()
    hacs.hass = HomeAssistant()
    hacs.hass.config.config_dir = tmpdir
    hacs.configuration = Configuration()
    hacs.system.status.background_task = False
    hacs.system.disabled = False
    await data.async_write()
Beispiel #10
0
async def test_common_base_exception_tree_issues(aresponses, event_loop):
    aresponses.add(
        "api.github.com",
        "/rate_limit",
        "get",
        aresponses.Response(body=b"{}",
                            headers=response_rate_limit_header,
                            status=200),
    )
    aresponses.add(
        "api.github.com",
        "/repos/test/test",
        "get",
        aresponses.Response(body=json.dumps(repository_data),
                            headers=response_rate_limit_header),
    )
    aresponses.add(
        "api.github.com",
        "/rate_limit",
        "get",
        aresponses.Response(body=b"{}",
                            headers=response_rate_limit_header,
                            status=200),
    )
    aresponses.add(
        "api.github.com",
        "/repos/test/test/releases",
        "get",
        aresponses.Response(body=json.dumps(release_data),
                            headers=response_rate_limit_header),
    )
    aresponses.add(
        "api.github.com",
        "/rate_limit",
        "get",
        aresponses.Response(body=b"{}",
                            headers=response_rate_limit_header,
                            status=200),
    )
    aresponses.add(
        "api.github.com",
        "/repos/test/test/git/trees/3",
        "get",
        aresponses.Response(body=json.dumps({"message": "X"}),
                            headers=response_rate_limit_header),
    )

    async with aiohttp.ClientSession(loop=event_loop) as session:
        hacs = get_hacs()
        hacs.session = session
        hacs.configuration = Configuration()
        hacs.configuration.token = TOKEN
        repository = dummy_repository_base()
        hacs.common.blacklist = []
        hacs.system.status.startup = False
        with pytest.raises(HacsException):
            await common_validate(repository)
Beispiel #11
0
async def test_frontend_frontend_repo_url(aresponses, event_loop):
    aresponses.add(
        "127.0.0.1",
        "/main.js",
        "get",
        "",
    )

    hacs = get_hacs()
    hacs.hass = HomeAssistant()
    hacs.configuration = Configuration()
    hacs.configuration.frontend_repo_url = "http://127.0.0.1"
    await async_serve_frontend()

    async with aiohttp.ClientSession(loop=event_loop) as session:
        hacs.session = session
        await async_serve_frontend()
        hacs.configuration = Configuration()
Beispiel #12
0
async def validate_repository(repository, category, ref=None):
    """Validate."""
    async with aiohttp.ClientSession() as session:
        hacs = get_hacs()
        hacs.session = session
        hacs.configuration = Configuration()
        hacs.configuration.token = TOKEN
        hacs.github = AIOGitHub(hacs.configuration.token, hacs.session)
        await register_repository(repository, category, ref=ref)
        print("All good!")
Beispiel #13
0
async def test_hacs_data_async_write1(tmpdir):
    data = HacsData()
    hacs = get_hacs()
    repository = dummy_repository_base()
    repository.data.installed = True
    repository.data.installed_version = "1"
    hacs.repositories = [repository]
    hacs.hass = HomeAssistant()
    hacs.hass.config.config_dir = tmpdir
    hacs.configuration = Configuration()
    await data.async_write()
Beispiel #14
0
async def validate_repository(repository, category, ref=None):
    """Validate."""
    async with aiohttp.ClientSession() as session:
        hacs = get_hacs()
        hacs.session = session
        hacs.configuration = Configuration()
        hacs.configuration.token = TOKEN
        hacs.github = GitHub(hacs.configuration.token, hacs.session)
        try:
            await register_repository(repository, category, ref=ref, action=True)
        except HacsException as exception:
            exit(exception)
        print("All good!")
Beispiel #15
0
async def validate_repository(repository, category, ref=None):
    """Validate."""
    async with aiohttp.ClientSession() as session:
        hacs = get_hacs()
        hacs.hass = HomeAssistant()
        hacs.session = session
        hacs.configuration = Configuration()
        hacs.configuration.token = TOKEN
        hacs.github = GitHub(hacs.configuration.token, hacs.session)
        try:
            await register_repository(repository, category, ref=ref)
        except HacsException as exception:
            error(exception)
Beispiel #16
0
async def async_setup(hass, config):
    """Set up this integration using yaml."""
    hacs = get_hacs()
    if DOMAIN not in config:
        return True
    if hacs.configuration and hacs.configuration.config_type == "flow":
        return True

    await _async_common_setup(hass)

    hacs.configuration = Configuration.from_dict(config[DOMAIN])
    hacs.configuration.config_type = "yaml"
    await async_startup_wrapper_for_yaml()
    return True
Beispiel #17
0
async def test_installation_method():
    hacs = get_hacs()
    hacs.configuration = Configuration()
    hacs.configuration.token = TOKEN
    repo = MockRepo()

    with pytest.raises(HacsException):
        await repo.async_install()
    repo.content.path.local = ""

    with pytest.raises(HacsException):
        await repo.async_install()
    repo.can_install = True

    await repo._async_post_install()
Beispiel #18
0
async def async_setup(hass, config):
    """Set up this integration using yaml."""
    hacs = get_hacs()
    if DOMAIN not in config:
        return True
    if hacs.configuration and hacs.configuration.config_type == "flow":
        return True
    hass.data[DOMAIN] = config
    hacs.hass = hass
    hacs.session = async_create_clientsession(hass)
    hacs.configuration = Configuration.from_dict(config[DOMAIN])
    hacs.configuration.config = config
    hacs.configuration.config_type = "yaml"
    await startup_wrapper_for_yaml()
    return True
Beispiel #19
0
async def validate_repository(repository, category, ref=None):
    """Validate."""
    async with aiohttp.ClientSession() as session:
        hacs = get_hacs()
        hacs.hass = HomeAssistant()
        hacs.session = session
        hacs.configuration = Configuration()
        hacs.configuration.token = TOKEN
        hacs.core.config_path = None
        hacs.github = GitHub(hacs.configuration.token, hacs.session)
        print(
            "::warning::Use hacs/integration/action@main instead of hacs/integration/action@master"
        )
        try:
            await register_repository(repository, category, ref=ref)
        except HacsException as exception:
            error(exception)
Beispiel #20
0
async def async_setup(hass, config):
    """Set up this integration using yaml."""
    hacs = get_hacs()
    if DOMAIN not in config:
        return True
    hass.data[DOMAIN] = config
    hacs.hass = hass
    hacs.session = async_create_clientsession(hass)
    hacs.configuration = Configuration.from_dict(config[DOMAIN],
                                                 config[DOMAIN].get("options"))
    hacs.configuration.config = config
    hacs.configuration.config_type = "yaml"
    await startup_wrapper_for_yaml()
    hass.async_create_task(
        hass.config_entries.flow.async_init(
            DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={}))
    return True
Beispiel #21
0
async def async_setup_entry(hass, config_entry):
    """Set up this integration using UI."""
    hacs = get_hacs()
    if hass.data.get(DOMAIN) is not None:
        return False
    if config_entry.source == config_entries.SOURCE_IMPORT:
        hass.async_create_task(hass.config_entries.async_remove(config_entry.entry_id))
        return False

    await hass.async_add_executor_job(_common_setup, hass)

    hacs.configuration = Configuration.from_dict(
        config_entry.data, config_entry.options
    )
    hacs.configuration.config_type = "flow"
    hacs.configuration.config_entry = config_entry

    return await async_startup_wrapper_for_config_entry()
Beispiel #22
0
def test_configuration_and_option():
    config = Configuration.from_dict({"token": "xxxxxxxxxx"}, {})

    assert isinstance(config.to_json(), dict)
    config.print()

    assert isinstance(config.options, dict)
    assert isinstance(config.config, dict)

    assert isinstance(config.token, str)
    assert config.token == "xxxxxxxxxx"

    assert isinstance(config.sidepanel_title, str)
    assert config.sidepanel_title == "HACS"

    assert isinstance(config.sidepanel_icon, str)
    assert config.sidepanel_icon == "hacs:hacs"

    assert isinstance(config.appdaemon, bool)
    assert not config.appdaemon

    assert isinstance(config.netdaemon, bool)
    assert not config.netdaemon

    assert isinstance(config.python_script, bool)
    assert not config.python_script

    assert isinstance(config.onboarding_done, bool)
    assert not config.onboarding_done

    assert isinstance(config.theme, bool)
    assert not config.theme

    assert isinstance(config.options, dict)

    assert isinstance(config.country, str)
    assert config.country == "ALL"

    assert isinstance(config.release_limit, int)
    assert config.release_limit == 5

    assert isinstance(config.experimental, bool)
    assert not config.experimental
async def test_get_releases_exception(aresponses, event_loop):
    aresponses.add(
        "api.github.com",
        "/rate_limit",
        "get",
        aresponses.Response(body=b"{}",
                            headers=response_rate_limit_header,
                            status=200),
    )
    aresponses.add(
        "api.github.com",
        "/repos/test/test",
        "get",
        aresponses.Response(body=json.dumps(repository_data),
                            headers=response_rate_limit_header),
    )
    aresponses.add(
        "api.github.com",
        "/rate_limit",
        "get",
        aresponses.Response(
            body=json.dumps({"message": "X"}),
            headers=response_rate_limit_header_with_limit,
            status=403,
        ),
    )
    aresponses.add(
        "api.github.com",
        "/rate_limit",
        "get",
        aresponses.Response(body=b"{}",
                            headers=response_rate_limit_header,
                            status=200),
    )
    aresponses.add(
        "api.github.com",
        "/repos/test/test/git/trees/3",
        "get",
        aresponses.Response(body=json.dumps(tree_files_base),
                            headers=response_rate_limit_header),
    )
    aresponses.add(
        "api.github.com",
        "/rate_limit",
        "get",
        aresponses.Response(body=b"{}",
                            headers=response_rate_limit_header,
                            status=200),
    )
    aresponses.add(
        "api.github.com",
        "/repos/test/test/contents/hacs.json",
        "get",
        aresponses.Response(body=json.dumps({}),
                            headers=response_rate_limit_header),
    )
    aresponses.add(
        "api.github.com",
        "/repos/test/test/releases",
        "get",
        aresponses.Response(
            body=json.dumps(release_data),
            headers=response_rate_limit_header_with_limit,
            status=403,
        ),
    )

    async with aiohttp.ClientSession(loop=event_loop) as session:
        hacs = get_hacs()
        hacs.session = session
        hacs.configuration = Configuration()
        hacs.configuration.token = TOKEN
        repository = dummy_repository_base()
        repository.ref = None
        await common_validate(repository)
        assert not repository.data.releases
Beispiel #24
0
async def _load_hacs_repository(aresponses, event_loop):
    hacs = get_hacs()
    aresponses.add(
        "api.github.com",
        "/rate_limit",
        "get",
        aresponses.Response(body=b"{}", headers=response_rate_limit_header),
    )
    aresponses.add(
        "api.github.com",
        "/repos/hacs/integration",
        "get",
        aresponses.Response(body=json.dumps(repository_data),
                            headers=response_rate_limit_header),
    )
    aresponses.add(
        "api.github.com",
        "/rate_limit",
        "get",
        aresponses.Response(body=b"{}", headers=response_rate_limit_header),
    )
    aresponses.add(
        "api.github.com",
        "/repos/test/test/git/trees/master",
        "get",
        aresponses.Response(
            body=json.dumps(tree_files_base_integration()),
            headers=response_rate_limit_header,
        ),
    )
    aresponses.add(
        "api.github.com",
        "/rate_limit",
        "get",
        aresponses.Response(body=b"{}", headers=response_rate_limit_header),
    )
    aresponses.add(
        "api.github.com",
        "/repos/test/test/releases",
        "get",
        aresponses.Response(body=json.dumps(release_data),
                            headers=response_rate_limit_header),
    )
    aresponses.add(
        "api.github.com",
        "/rate_limit",
        "get",
        aresponses.Response(body=b"{}", headers=response_rate_limit_header),
    )
    aresponses.add(
        "api.github.com",
        "/repos/test/test/contents/hacs.json",
        "get",
        aresponses.Response(body=json.dumps({"name": "test"}),
                            headers=response_rate_limit_header),
    )
    aresponses.add(
        "api.github.com",
        "/rate_limit",
        "get",
        aresponses.Response(body=b"{}", headers=response_rate_limit_header),
    )
    async with aiohttp.ClientSession(loop=event_loop) as session:
        hacs.session = session
        hacs.configuration = Configuration()
        hacs.configuration.token = TOKEN
        await load_hacs_repository()
def test_edge_configuration_only_pass_none_as_option():
    assert Configuration.from_dict({"token": "xxxxxxxxxx"}, None)
def test_edge_option_only_pass_empty_dict_as_configuration():
    with pytest.raises(HacsException):
        assert Configuration.from_dict({}, {"experimental": True})
def test_edge_options_true():
    with pytest.raises(HacsException):
        assert Configuration.from_dict({"options": True}, None)