From 09ccc509e0feacbe77db6fc35ea6517ccce4e6f9 Mon Sep 17 00:00:00 2001
From: Christian Boettcher <c.boettcher@fz-juelich.de>
Date: Wed, 20 Apr 2022 09:52:00 +0200
Subject: [PATCH] add basic test for uuid validation

---
 src/datacat_integration/secrets.py | 4 ++--
 tests/test_secrets.py              | 6 +++++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/datacat_integration/secrets.py b/src/datacat_integration/secrets.py
index d79f11d..065ae5e 100644
--- a/src/datacat_integration/secrets.py
+++ b/src/datacat_integration/secrets.py
@@ -12,10 +12,10 @@ connection_backend_type = "airflow_connections"
 
 log = logging.getLogger(__name__)
 
-def validate_uuid(uuid_to_test: str, version=4):
+def validate_uuid(uuid_to_test: str):
     """Check if uuid_to_test id a valid UUID. Returns True if it is and false if it is not."""
     try:
-        uuid_obj = uuid.UUID(uuid_to_test, version=version)
+        uuid_obj = uuid.UUID(uuid_to_test)
     except ValueError:
         return False
     return str(uuid_obj) == uuid_to_test
diff --git a/tests/test_secrets.py b/tests/test_secrets.py
index 54a910d..f408922 100644
--- a/tests/test_secrets.py
+++ b/tests/test_secrets.py
@@ -1,8 +1,9 @@
 from unittest import TestCase
 import os, json
+import uuid
 from dotenv import load_dotenv
 
-from datacat_integration.secrets import DataCatConnectionWithSecrets, get_connection_with_secrets_from_entry, DatacatSecretsBackend
+from datacat_integration.secrets import DataCatConnectionWithSecrets, get_connection_with_secrets_from_entry, DatacatSecretsBackend, validate_uuid
 
 
 class TestSecretsBackend(TestCase):
@@ -26,6 +27,9 @@ class TestSecretsBackend(TestCase):
         self.assertEqual(conn.extra_dejson['some_public_extra'], "12345")
         self.assertEqual(conn.extra_dejson['some_other_extra_to_be_overwritten_by_secret'], "secret_67890")
 
+    def test_uuid_validation(self):
+        self.assertTrue(validate_uuid(str(uuid.uuid4())))
+        self.assertFalse(validate_uuid("wrong_uuid"))
     
     def test_no_error_on_missing_extra(self):
         get_connection_with_secrets_from_entry({"name" : "some-name", "url" : "some_url", "metadata" : {}}, {}, "test-connection", 'false_oid')
-- 
GitLab