2022-01-10 09:36:08 +01:00
|
|
|
# Copyright 2021 Collate
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
"""
|
|
|
|
OpenMetadata utils tests
|
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
|
|
|
|
|
|
|
from metadata.generated.schema.entity.data.mlmodel import MlModel
|
|
|
|
from metadata.generated.schema.type import basic
|
2022-03-30 08:54:47 +02:00
|
|
|
from metadata.ingestion.ometa.utils import format_name, get_entity_type, model_str
|
2022-07-23 12:31:26 +02:00
|
|
|
from metadata.utils.connections import render_query_header
|
2022-01-10 09:36:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
class OMetaUtilsTest(TestCase):
|
|
|
|
def test_format_name(self):
|
|
|
|
"""
|
|
|
|
Check we are properly formatting names
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.assertEqual(format_name("random"), "random")
|
|
|
|
self.assertEqual(format_name("ran dom"), "ran_dom")
|
|
|
|
self.assertEqual(format_name("ran_(dom"), "ran__dom")
|
|
|
|
|
|
|
|
def test_get_entity_type(self):
|
|
|
|
"""
|
|
|
|
Check that we return a string or the class name
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.assertEqual(get_entity_type("hello"), "hello")
|
|
|
|
self.assertEqual(get_entity_type(MlModel), "mlmodel")
|
|
|
|
|
2022-03-30 08:54:47 +02:00
|
|
|
def test_model_str(self):
|
2022-01-10 09:36:08 +01:00
|
|
|
"""
|
|
|
|
Return Uuid as str
|
|
|
|
"""
|
|
|
|
|
2022-03-30 08:54:47 +02:00
|
|
|
self.assertEqual(model_str("random"), "random")
|
2022-01-10 09:36:08 +01:00
|
|
|
self.assertEqual(
|
2022-03-30 08:54:47 +02:00
|
|
|
model_str(basic.Uuid(__root__="9fc58e81-7412-4023-a298-59f2494aab9d")),
|
2022-01-10 09:36:08 +01:00
|
|
|
"9fc58e81-7412-4023-a298-59f2494aab9d",
|
|
|
|
)
|
2022-03-30 08:54:47 +02:00
|
|
|
|
|
|
|
self.assertEqual(
|
|
|
|
model_str(basic.EntityName(__root__="EntityName")), "EntityName"
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
model_str(basic.FullyQualifiedEntityName(__root__="FQDN")), "FQDN"
|
|
|
|
)
|
2022-07-23 12:31:26 +02:00
|
|
|
|
|
|
|
def test_render_query_headers_builds_the_right_string(self) -> None:
|
|
|
|
assert (
|
|
|
|
render_query_header("0.0.1")
|
|
|
|
== '/* {"app": "OpenMetadata", "version": "0.0.1"} */'
|
|
|
|
)
|