Skip to content

Commit

Permalink
Organize lifecycle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pmbrull committed Nov 9, 2023
1 parent 4934c73 commit fff72b6
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions ingestion/tests/integration/ometa/test_ometa_life_cycle_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"""
OpenMetadata high-level API Table Life Cycle test
"""
import uuid
from unittest import TestCase

from metadata.generated.schema.api.data.createDatabase import CreateDatabaseRequest
Expand Down Expand Up @@ -100,6 +99,14 @@ class OMetaLifeCycleTest(TestCase):
)
service_type = "databaseService"

def create_table(self, name: str) -> Table:
create = CreateTableRequest(
name=name,
databaseSchema=self.create_schema_entity.fullyQualifiedName,
columns=[Column(name="id", dataType=DataType.BIGINT)],
)
return self.metadata.create_or_update(create)

@classmethod
def setUpClass(cls) -> None:
"""
Expand All @@ -122,22 +129,6 @@ def setUpClass(cls) -> None:

cls.create_schema_entity = cls.metadata.create_or_update(data=create_schema)

cls.entity = Table(
id=uuid.uuid4(),
name="test",
databaseSchema=EntityReference(
id=cls.create_schema_entity.id, type="databaseSchema"
),
fullyQualifiedName="test-service-lifecycle.test-db.test-schema.test",
columns=[Column(name="id", dataType=DataType.BIGINT)],
)

cls.create = CreateTableRequest(
name="test",
databaseSchema=cls.create_schema_entity.fullyQualifiedName,
columns=[Column(name="id", dataType=DataType.BIGINT)],
)

cls.life_cycle = LifeCycle(
created=AccessDetails(
timestamp=1693569600000, accessedBy=cls.created_user_ref
Expand Down Expand Up @@ -175,20 +166,18 @@ def test_create(self):
We can create a Table and we receive it back as Entity
"""

res = self.metadata.create_or_update(data=self.create)
res = self.create_table(name="test_create")

self.assertEqual(res.name, self.entity.name)
self.assertEqual(res.databaseSchema.id, self.entity.databaseSchema.id)
self.assertEqual(res.name, "test_create")
self.assertEqual(res.databaseSchema.id, self.create_schema_entity.id)
self.assertEqual(res.owner, None)

def test_ingest_life_cycle(self):
"""
Test the life cycle API
"""

table_entity = self.metadata.get_by_name(
entity=Table, fqn=self.entity.fullyQualifiedName
)
table_entity = self.create_table(name="test_ingest_life_cycle")

self.metadata.patch_life_cycle(entity=table_entity, life_cycle=self.life_cycle)

Expand All @@ -197,9 +186,13 @@ def test_life_cycle_get_methods(self):
We can fetch a Table by name/id and pass the field for lifeCycle
"""

# test the get_by_name api
entity = self.create_table(name="test_life_cycle_get_methods")
self.metadata.patch_life_cycle(entity=entity, life_cycle=self.life_cycle)

res = self.metadata.get_by_name(
entity=Table, fqn=self.entity.fullyQualifiedName, fields=["lifeCycle"]
entity=Table,
fqn="test-service-lifecycle.test-db.test-schema.test_life_cycle_get_methods",
fields=["lifeCycle"],
)
self.assertEqual(res.lifeCycle, self.life_cycle)

Expand All @@ -215,9 +208,8 @@ def test_update_life_cycle(self):
Only the latest information should get updated for the life cycle fields.
"""

table_entity = self.metadata.get_by_name(
entity=Table, fqn=self.entity.fullyQualifiedName
)
entity = self.create_table(name="test_update_life_cycle")

new_accessed = AccessDetails(
timestamp=1694015100000,
accessedBy=self.updated_user_ref,
Expand All @@ -228,14 +220,21 @@ def test_update_life_cycle(self):
accessedBy=self.updated_user_ref,
)

# We PATCH twice and review the results
self.metadata.patch_life_cycle(entity=entity, life_cycle=self.life_cycle)
self.metadata.patch_life_cycle(
entity=table_entity,
entity=entity,
life_cycle=LifeCycle(accessed=new_accessed, updated=new_updated),
)

res = self.metadata.get_by_name(
entity=Table, fqn=self.entity.fullyQualifiedName, fields=["lifeCycle"]
entity=Table,
fqn="test-service-lifecycle.test-db.test-schema.test_update_life_cycle",
fields=["lifeCycle"],
)
# Created is maintained from the first PATCH
self.assertEqual(self.life_cycle.created, res.lifeCycle.created)
# This comes from the second PATCH
self.assertEqual(new_accessed, res.lifeCycle.accessed)
# Second PATCH does not update the `updated` field since it's older in the first PATCH
self.assertNotEqual(new_updated, res.lifeCycle.updated)

0 comments on commit fff72b6

Please sign in to comment.