57 lines
2.2 KiB
Python
Raw Normal View History

2024-12-30 01:59:08 -05:00
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import pytest
2025-01-25 04:07:53 -05:00
from graphrag_app.utils.common import (
2025-01-28 00:34:04 -05:00
desanitize_name,
2024-12-30 01:59:08 -05:00
sanitize_name,
validate_blob_container_name,
validate_index_file_exist,
)
def test_validate_blob_container_name():
2025-01-25 04:07:53 -05:00
"""Test the graphrag_app.utils.common.validate_blob_container_name function."""
2024-12-30 01:59:08 -05:00
# test valid container name
assert validate_blob_container_name("validcontainername") is None
# test invalid container name
with pytest.raises(ValueError):
validate_blob_container_name("invalidContainerName")
with pytest.raises(ValueError):
validate_blob_container_name(
"invalidcontainernameinvalidcontainernameinvalidcontainerinvalids"
)
with pytest.raises(ValueError):
validate_blob_container_name("*invalidContainerName")
with pytest.raises(ValueError):
validate_blob_container_name("invalid+ContainerName")
with pytest.raises(ValueError):
validate_blob_container_name("invalid--containername")
with pytest.raises(ValueError):
validate_blob_container_name("invalidcontainername-")
2025-01-28 00:34:04 -05:00
def test_desanitize_name(container_with_graphml_file):
"""Test the graphrag_app.utils.common.desanitize_name function."""
2024-12-30 01:59:08 -05:00
# test retrieving a valid container name
original_name = container_with_graphml_file
sanitized_name = sanitize_name(original_name)
2025-01-28 00:34:04 -05:00
assert desanitize_name(sanitized_name) == original_name
2024-12-30 01:59:08 -05:00
# test retrieving an invalid container name
2025-01-28 00:34:04 -05:00
assert desanitize_name("nonexistent-container") is None
2024-12-30 01:59:08 -05:00
def test_validate_index_file_exist(container_with_graphml_file):
2025-01-25 04:07:53 -05:00
"""Test the graphrag_app.utils.common.validate_index_file_exist function."""
2024-12-30 01:59:08 -05:00
original_name = container_with_graphml_file
sanitized_name = sanitize_name(original_name)
# test with a valid index and valid file
assert validate_index_file_exist(sanitized_name, "output/graph.graphml") is None
2024-12-30 01:59:08 -05:00
# test with a valid index and non-existent file
with pytest.raises(ValueError):
validate_index_file_exist(sanitized_name, "non-existent-file")
# test non-existent index and valid file
with pytest.raises(ValueError):
validate_index_file_exist("nonexistent-index", "output/graph.graphml")