Exemplo n.º 1
0
def test_single_file_repo():
    repository = dummy_repository_base()
    repository.content.single = True
    repository.data.file_name = "test.file"
    repository.tree = [
        AIOGithubTreeContent({
            "path": "test.file",
            "type": "blob"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "dir",
            "type": "tree"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "test.yaml",
            "type": "blob"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "readme.md",
            "type": "blob"
        }, "test/test", "master"),
    ]
    files = [x.path for x in gather_files_to_download(repository)]
    assert "readme.md" not in files
    assert "test.yaml" not in files
    assert "test.file" in files
Exemplo n.º 2
0
def test_gather_plugin_files_from_root():
    repository = dummy_repository_plugin()
    repository.content.path.remote = ""
    repository.tree = [
        AIOGithubTreeContent({
            "path": "test.js",
            "type": "blob"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "dir",
            "type": "tree"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "aaaa.js",
            "type": "blob"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "dist/test.js",
            "type": "blob"
        }, "test/test", "master"),
    ]
    find_file_name(repository)
    files = [x.path for x in gather_files_to_download(repository)]
    assert "test.js" in files
    assert "dir" not in files
    assert "aaaa.js" in files
    assert "dist/test.js" not in files
Exemplo n.º 3
0
def test_gather_netdaemon_files_base():
    repository = dummy_repository_netdaemon()
    repository.tree = [
        AIOGithubTreeContent({
            "path": "test.cs",
            "type": "blob"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "apps/test/test.cs",
            "type": "blob"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "apps/test/test.yaml",
            "type": "blob"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": ".github/file.file",
            "type": "blob"
        }, "test/test", "master"),
    ]
    files = [x.path for x in gather_files_to_download(repository)]
    assert ".github/file.file" not in files
    assert "test.cs" not in files
    assert "apps/test/test.cs" in files
    assert "apps/test/test.yaml" in files
Exemplo n.º 4
0
def test_gather_plugin_multiple_files_in_root():
    repository = dummy_repository_plugin()
    repository.content.path.remote = ""
    repository.data.file_name = "test.js"
    repository.tree = [
        AIOGithubTreeContent({
            "path": "test.js",
            "type": "blob"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "dep1.js",
            "type": "blob"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "dep2.js",
            "type": "blob"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "dep3.js",
            "type": "blob"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "info.md",
            "type": "blob"
        }, "test/test", "master"),
    ]
    files = [x.path for x in gather_files_to_download(repository)]
    assert "test.js" in files
    assert "dep1.js" in files
    assert "dep2.js" in files
    assert "dep3.js" in files
    assert "info.md" not in files
Exemplo n.º 5
0
def test_gather_plugin_files_from_dist():
    repository = dummy_repository_plugin()
    repository.content.path.remote = "dist"
    repository.data.file_name = "test.js"
    repository.tree = [
        AIOGithubTreeContent({
            "path": "test.js",
            "type": "blob"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "dist/image.png",
            "type": "blob"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "dist/test.js",
            "type": "blob"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "dist/subdir",
            "type": "tree"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "dist/subdir/file.file",
            "type": "blob"
        }, "test/test", "master"),
    ]
    files = [x.path for x in gather_files_to_download(repository)]
    assert "test.js" not in files
    assert "dist/image.png" in files
    assert "dist/subdir/file.file" in files
    assert "dist/subdir" not in files
    assert "dist/test.js" in files
def test_valid():
    tree = [
        AIOGithubTreeContent({"path": "test", "type": "tree"}, "test/test", "master"),
        AIOGithubTreeContent(
            {"path": "test/path", "type": "tree"}, "test/test", "master"
        ),
        AIOGithubTreeContent(
            {"path": "test/path/sub", "type": "tree"}, "test/test", "master"
        ),
    ]
    assert get_first_directory_in_directory(tree, "test") == "path"
def test_not_valid():
    tree = [
        AIOGithubTreeContent(
            {"path": ".github/path/file.file", "type": "tree"}, "test/test", "master"
        )
    ]
    assert get_first_directory_in_directory(tree, "test") is None
Exemplo n.º 8
0
def test_gather_plugin_different_card_name():
    repository = dummy_repository_plugin()
    repository.content.path.remote = ""
    repository.data.file_name = "card.js"
    repository.tree = [
        AIOGithubTreeContent(
            {"path": "card.js", "type": "blob"}, "test/test", "master"
        ),
        AIOGithubTreeContent(
            {"path": "info.md", "type": "blob"}, "test/test", "master"
        ),
    ]
    find_file_name(repository)
    files = [x.path for x in gather_files_to_download(repository)]
    assert "card.js" in files
    assert "info.md" not in files
def test_gather_files_to_download():
    repository = dummy_repository_base()
    repository.content.path.remote = ""
    dummyfile = {"path": "test/path/file.file", "type": "blob"}
    repository.tree = [AIOGithubTreeContent(dummyfile, "test/test", "master")]
    files = [x.path for x in gather_files_to_download(repository)]
    assert "test/path/file.file" in files
Exemplo n.º 10
0
def test_gather_content_in_root_theme():
    repository = dummy_repository_theme()
    repository.data.content_in_root = True
    repository.content.path.remote = ""
    repository.data.file_name = "test.yaml"
    repository.tree = [
        AIOGithubTreeContent(
            {"path": "test.yaml", "type": "blob"}, "test/test", "master"
        ),
        AIOGithubTreeContent({"path": "dir", "type": "tree"}, "test/test", "master"),
        AIOGithubTreeContent(
            {"path": "test2.yaml", "type": "blob"}, "test/test", "master"
        ),
    ]
    files = [x.path for x in gather_files_to_download(repository)]
    assert "test2.yaml" not in files
    assert "test.yaml" in files
Exemplo n.º 11
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.º 12
0
def test_find_file_name_dist():
    repository = dummy_repository_plugin()
    repository.tree = [
        AIOGithubTreeContent({
            "path": "dist/test.js",
            "type": "blob"
        }, "test/test", "master")
    ]
    find_file_name(repository)
    assert repository.data.file_name == "test.js"
    assert repository.content.path.remote == "dist"
Exemplo n.º 13
0
def test_find_file_name_base_theme():
    repository = dummy_repository_theme()
    repository.tree = [
        AIOGithubTreeContent({
            "path": "themes/test.yaml",
            "type": "blob"
        }, "test/test", "master")
    ]
    find_file_name(repository)
    assert repository.data.file_name == "test.yaml"
    assert repository.data.name == "test"
Exemplo n.º 14
0
def test_find_file_name_base_python_script():
    repository = dummy_repository_python_script()
    repository.tree = [
        AIOGithubTreeContent({
            "path": "python_scripts/test.py",
            "type": "blob"
        }, "test/test", "master")
    ]
    find_file_name(repository)
    assert repository.data.file_name == "test.py"
    assert repository.data.name == "test"
Exemplo n.º 15
0
def test_gather_appdaemon_files_with_subdir():
    repository = dummy_repository_appdaemon()
    repository.data.file_name = "test.py"
    repository.tree = [
        AIOGithubTreeContent(
            {"path": "test.py", "type": "blob"}, "test/test", "master"
        ),
        AIOGithubTreeContent(
            {"path": "apps/test/test.py", "type": "blob"}, "test/test", "master"
        ),
        AIOGithubTreeContent(
            {"path": "apps/test/core/test.py", "type": "blob"}, "test/test", "master"
        ),
        AIOGithubTreeContent(
            {"path": "apps/test/devices/test.py", "type": "blob"}, "test/test", "master"
        ),
        AIOGithubTreeContent(
            {"path": "apps/test/test/test.py", "type": "blob"}, "test/test", "master"
        ),
        AIOGithubTreeContent(
            {"path": ".github/file.file", "type": "blob"}, "test/test", "master"
        ),
    ]
    files = [x.path for x in gather_files_to_download(repository)]
    assert ".github/file.file" not in files
    assert "test.py" not in files
    assert "apps/test/test.py" in files
    assert "apps/test/devices/test.py" in files
    assert "apps/test/test/test.py" in files
    assert "apps/test/core/test.py" in files
def test_valid_objects():
    tree = [
        AIOGithubTreeContent({
            "path": "test/file.file",
            "type": "blob"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "test/newfile.file",
            "type": "blob"
        }, "test/test", "master"),
        AIOGithubTreeContent({
            "path": "test/file.png",
            "type": "blob"
        }, "test/test", "master"),
    ]
    files = [
        x.filename for x in filter_content_return_one_of_type(
            tree, "test", "file", "full_path")
    ]
    assert "file.file" in files
    assert "newfile.file" not in files
    assert "file.png" in files
Exemplo n.º 17
0
def test_find_file_release_no_asset():
    repository = dummy_repository_plugin()
    repository.releases.objects = [
        AIOGithubRepositoryRelease({
            "tag_name": "3",
            "assets": []
        })
    ]
    repository.tree = [
        AIOGithubTreeContent({
            "path": "test.js",
            "type": "blob"
        }, "test/test", "master")
    ]
    find_file_name(repository)
    assert repository.data.file_name == "test.js"
    assert repository.content.path.remote == ""
Exemplo n.º 18
0
async def test_download_content(aresponses, tmp_path, event_loop):
    aresponses.add(
        "raw.githubusercontent.com",
        "/test/test/master/test/path/file.file",
        "get",
        aresponses.Response(body="test", headers=response_rate_limit_header),
    )

    repository = dummy_repository_base()
    repository.content.path.remote = ""
    repository.content.path.local = tmp_path
    repository.tree = [
        AIOGithubTreeContent({
            "path": "test/path/file.file",
            "type": "blob"
        }, "test/test", "master")
    ]
    async with aiohttp.ClientSession(loop=event_loop) as session:
        hacs = get_hacs()
        hacs.hass.loop = event_loop
        hacs.session = session
        await download_content(repository)
        assert os.path.exists(
            f"{repository.content.path.local}/test/path/file.file")