Exemplo n.º 1
0
async def test_download_content_integration(aresponses, tmp_path, event_loop):
    aresponses.add(
        "raw.githubusercontent.com",
        aresponses.ANY,
        "get",
        aresponses.Response(body="", headers=response_rate_limit_header),
    )
    aresponses.add(
        "raw.githubusercontent.com",
        aresponses.ANY,
        "get",
        aresponses.Response(body="", headers=response_rate_limit_header),
    )
    aresponses.add(
        "raw.githubusercontent.com",
        aresponses.ANY,
        "get",
        aresponses.Response(body="", headers=response_rate_limit_header),
    )
    aresponses.add(
        "raw.githubusercontent.com",
        aresponses.ANY,
        "get",
        aresponses.Response(body="", headers=response_rate_limit_header),
    )
    hacs = get_hacs()
    hacs.system.config_path = tmp_path
    repository = dummy_repository_integration()
    repository.domain = "test"
    repository.content.path.local = repository.localpath
    repository.content.path.remote = "custom_components/test"
    integration_files = [
        "__init__.py",
        "sensor.py",
        ".translations/en.json",
        "manifest.json",
    ]
    for integration_file in integration_files:
        repository.tree.append(
            AIOGithubTreeContent(
                {
                    "path": f"custom_components/test/{integration_file}",
                    "type": "blob"
                },
                "test/test",
                "master",
            ))

    async with aiohttp.ClientSession(loop=event_loop) as session:
        hacs.hass.loop = event_loop
        hacs.session = session
        await download_content(repository)
        for path in repository.tree:
            assert os.path.exists(
                f"{hacs.system.config_path}/{path.full_path}")
Exemplo n.º 2
0
async def test_reload_after_install():
    repository = dummy_repository_integration()

    await reload_after_install(repository)
    assert repository.pending_restart

    repository.manifest["config_flow"] = True
    await reload_after_install(repository)

    repository = dummy_repository_theme()
    await reload_after_install(repository)
Exemplo n.º 3
0
async def test_hacs_manifest_with_manifest():
    repository = dummy_repository_integration()
    repository.tree = [
        AIOGitHubAPIRepositoryTreeContent(
            {
                "path": "manifest.json",
                "type": "file"
            }, "test/test", "master")
    ]
    check = IntegrationManifest(repository)
    await check._async_run_check()
    assert not check.failed
Exemplo n.º 4
0
async def test_get_integration_manifest_missing_required_key(
        aresponses, event_loop):
    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",
        "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),
    )
    del integration_manifest["domain"]
    content = base64.b64encode(
        json.dumps(integration_manifest).encode("utf-8"))
    aresponses.add(
        "api.github.com",
        "/repos/test/test/contents/custom_components/test/manifest.json",
        "get",
        aresponses.Response(
            body=json.dumps({"content": content.decode("utf-8")}),
            headers=response_rate_limit_header,
        ),
    )

    async with aiohttp.ClientSession(loop=event_loop) as session:
        repository = dummy_repository_integration()
        repository.repository_object = await get_repository(
            session, TOKEN, "test/test")
        repository.content.path.remote = "custom_components/test"
        repository.tree = [
            AIOGithubTreeContent(
                {
                    "path": "custom_components/test/manifest.json",
                    "type": "blob"
                },
                "test/test",
                "master",
            )
        ]
        with pytest.raises(HacsException):
            await get_integration_manifest(repository)
Exemplo n.º 5
0
async def test_get_integration_manifest_format_issue(aresponses, event_loop):
    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",
        "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/contents/custom_components/test/manifest.json",
        "get",
        aresponses.Response(
            body=json.dumps({"content": {
                "wrong": "format"
            }}),
            headers=response_rate_limit_header,
        ),
    )

    async with aiohttp.ClientSession(loop=event_loop) as session:
        repository = dummy_repository_integration()
        repository.repository_object = await get_repository(
            session, TOKEN, "test/test")
        repository.content.path.remote = "custom_components/test"
        repository.tree = [
            AIOGithubTreeContent(
                {
                    "path": "custom_components/test/manifest.json",
                    "type": "blob"
                },
                "test/test",
                "master",
            )
        ]
        with pytest.raises(HacsException):
            await get_integration_manifest(repository)
async def test_async_run_repository_checks():
    hacs = get_hacs()
    repository = dummy_repository_integration()
    await async_run_repository_checks(repository)

    hacs.action = True
    hacs.system.running = True
    repository.tree = []
    with pytest.raises(SystemExit):
        await async_run_repository_checks(repository)

    hacs.action = False
    SHARE["rules"] = {}
    await async_run_repository_checks(repository)
    hacs.system.running = False
Exemplo n.º 7
0
async def test_get_integration_manifest_no_file(aresponses, event_loop):
    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",
        "get",
        aresponses.Response(body=json.dumps(repository_data),
                            headers=response_rate_limit_header),
    )

    async with aiohttp.ClientSession(loop=event_loop) as session:
        repository = dummy_repository_integration()
        repository.repository_object = await get_repository(
            session, TOKEN, "test/test")
        repository.content.path.remote = "custom_components/test"
        with pytest.raises(HacsException):
            await get_integration_manifest(repository)
Exemplo n.º 8
0
async def test_installation(aresponses, event_loop):
    repository = dummy_repository_integration()
    await repository.async_pre_install()
    await repository.async_post_installation()
Exemplo n.º 9
0
async def test_hacs_manifest_no_manifest():
    repository = dummy_repository_integration()
    check = IntegrationManifest(repository)
    await check._async_run_check()
    assert check.failed