Skip to content
Snippets Groups Projects
Commit 09ccc509 authored by Christian Boettcher's avatar Christian Boettcher
Browse files

add basic test for uuid validation

parent 60826e03
Branches
No related tags found
No related merge requests found
Pipeline #98077 passed
...@@ -12,10 +12,10 @@ connection_backend_type = "airflow_connections" ...@@ -12,10 +12,10 @@ connection_backend_type = "airflow_connections"
log = logging.getLogger(__name__) 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.""" """Check if uuid_to_test id a valid UUID. Returns True if it is and false if it is not."""
try: try:
uuid_obj = uuid.UUID(uuid_to_test, version=version) uuid_obj = uuid.UUID(uuid_to_test)
except ValueError: except ValueError:
return False return False
return str(uuid_obj) == uuid_to_test return str(uuid_obj) == uuid_to_test
......
from unittest import TestCase from unittest import TestCase
import os, json import os, json
import uuid
from dotenv import load_dotenv 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): class TestSecretsBackend(TestCase):
...@@ -26,6 +27,9 @@ 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_public_extra'], "12345")
self.assertEqual(conn.extra_dejson['some_other_extra_to_be_overwritten_by_secret'], "secret_67890") 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): 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') get_connection_with_secrets_from_entry({"name" : "some-name", "url" : "some_url", "metadata" : {}}, {}, "test-connection", 'false_oid')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment