Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

test(api): add unit tests for uuid_utils.is_valid_uuid (#45255)

TINGyu1236448d812b938af6
diff --git a/api/tests/unit_tests/core/tools/utils/test_uuid_utils.py b/api/tests/unit_tests/core/tools/utils/test_uuid_utils.py
new file mode 100644
index 00000000000..8b4c06314ad
--- /dev/null
+++ b/api/tests/unit_tests/core/tools/utils/test_uuid_utils.py
@@ -0,0 +1,32 @@
+import pytest
+
+from core.tools.utils.uuid_utils import is_valid_uuid
+
+
+ "value",
+ [
+ pytest.param("123e4567-e89b-12d3-a456-426614174000", id="canonical-hyphenated"),
+ pytest.param("123E4567-E89B-12D3-A456-426614174000", id="uppercase"),
+ pytest.param("123e4567e89b12d3a456426614174000", id="no-hyphens"),
+ pytest.param("{123e4567-e89b-12d3-a456-426614174000}", id="braced"),
+ pytest.param("urn:uuid:123e4567-e89b-12d3-a456-426614174000", id="urn-prefixed"),
+ ],
+)
+def test_is_valid_uuid_accepts_supported_formats(value: str) -> None:
+ assert is_valid_uuid(value) is True
+
+
+ "value",
+ [
+ pytest.param(None, id="none"),
+ pytest.param("", id="empty-string"),
+ pytest.param("not-a-uuid", id="plain-words"),
+ pytest.param("123e4567-e89b-12d3-a456-4266141740000", id="one-hex-too-many"),
+ pytest.param("123e4567-e89b-12d3-a456-42661417400", id="one-hex-missing"),
+ pytest.param("zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz", id="non-hex-characters"),
+ ],
+)
+def test_is_valid_uuid_rejects_invalid_values(value: str | None) -> None:
+ assert is_valid_uuid(value) is False