Пример #1
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
Пример #2
0
def test_netdaemon_backup():
    repository = dummy_repository_netdaemon()
    repository.content.path.local = repository.localpath
    os.makedirs(repository.content.path.local, exist_ok=True)
    backup = BackupNetDaemon(repository)

    with open(f"{repository.content.path.local}/dummy_file.yaml",
              "w") as dummy:
        dummy.write("test: test")
    with open(f"{repository.content.path.local}/dummy_file.yaml",
              "r") as dummy:
        content = dummy.read()
        assert content == "test: test"

    assert not os.path.exists(backup.backup_path)
    backup.create()
    backup.create()
    assert os.path.exists(backup.backup_path)
    with open(f"{repository.content.path.local}/dummy_file.yaml",
              "w") as dummy:
        dummy.write("tests: tests")
    with open(f"{repository.content.path.local}/dummy_file.yaml",
              "r") as dummy:
        content = dummy.read()
        assert content == "tests: tests"
    backup.restore()
    backup.cleanup()
    assert not os.path.exists(backup.backup_path)
    with open(f"{repository.content.path.local}/dummy_file.yaml",
              "r") as dummy:
        content = dummy.read()
        assert content == "test: test"