Exemplo n.º 1
0
def test_reference_validate(temp_repo_static, reference, valid):
    arca = Arca(base_dir=BASE_DIR)

    relative_path = Path("test_file.txt")

    if valid:
        arca.static_filename(temp_repo_static.url, temp_repo_static.branch, relative_path, reference=reference)
    else:
        with pytest.raises(ValueError):
            arca.static_filename(temp_repo_static.url, temp_repo_static.branch, relative_path, reference=reference)
Exemplo n.º 2
0
def test_static_files(temp_repo_static, file_location):
    arca = Arca(base_dir=BASE_DIR)

    filepath = temp_repo_static.file_path
    if file_location:
        new_filepath = temp_repo_static.repo_path / file_location / "test_file.txt"
        new_filepath.parent.mkdir(exist_ok=True, parents=True)

        filepath.replace(new_filepath)

        temp_repo_static.repo.index.add([str(new_filepath)])
        temp_repo_static.repo.index.remove([str(filepath)])
        temp_repo_static.repo.index.commit("Initial")

        filepath = new_filepath

    relative_path = Path(file_location) / "test_file.txt"
    nonexistent_relative_path = Path(file_location) / "test_file2.txt"

    result = arca.static_filename(temp_repo_static.url, temp_repo_static.branch, relative_path)

    assert filepath.read_text() == result.read_text()

    result = arca.static_filename(temp_repo_static.url, temp_repo_static.branch, str(relative_path))

    assert filepath.read_text() == result.read_text()

    with pytest.raises(FileOutOfRangeError):
        arca.static_filename(temp_repo_static.url, temp_repo_static.branch, "../file.txt")

    with pytest.raises(FileNotFoundError):
        arca.static_filename(temp_repo_static.url, temp_repo_static.branch, nonexistent_relative_path)