Skip to content

Commit

Permalink
Merge branch 'main' into APP-5657
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryamanz29 authored Mar 3, 2025
2 parents b98ee89 + 831ab2d commit 395c9ed
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pyatlan/client/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1341,13 +1341,15 @@ def append_terms(
results = (
FluentSearch()
.select()
.where(Asset.TYPE_NAME.eq(asset_type.__name__))
.where(asset_type.GUID.eq(guid))
.execute(client=client)
)
elif qualified_name:
results = (
FluentSearch()
.select()
.where(Asset.TYPE_NAME.eq(asset_type.__name__))
.where(asset_type.QUALIFIED_NAME.eq(qualified_name))
.execute(client=client)
)
Expand Down Expand Up @@ -1418,13 +1420,15 @@ def replace_terms(
results = (
FluentSearch()
.select()
.where(Asset.TYPE_NAME.eq(asset_type.__name__))
.where(asset_type.GUID.eq(guid))
.execute(client=client)
)
elif qualified_name:
results = (
FluentSearch()
.select()
.where(Asset.TYPE_NAME.eq(asset_type.__name__))
.where(asset_type.QUALIFIED_NAME.eq(qualified_name))
.execute(client=client)
)
Expand Down Expand Up @@ -1497,13 +1501,15 @@ def remove_terms(
results = (
FluentSearch()
.select()
.where(Asset.TYPE_NAME.eq(asset_type.__name__))
.where(asset_type.GUID.eq(guid))
.execute(client=client)
)
elif qualified_name:
results = (
FluentSearch()
.select()
.where(Asset.TYPE_NAME.eq(asset_type.__name__))
.where(asset_type.QUALIFIED_NAME.eq(qualified_name))
.execute(client=client)
)
Expand Down
107 changes: 107 additions & 0 deletions tests/integration/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
AtlasGlossaryTerm,
Connection,
Database,
Schema,
Table,
)
from pyatlan.model.audit import AuditSearchRequest, AuditSearchResults
Expand Down Expand Up @@ -139,6 +140,23 @@ def database(
delete_asset(client, guid=db.guid, asset_type=Database)


@pytest.fixture()
def schema_with_db_qn(
client: AtlanClient,
database: Database,
) -> Generator[Schema, None, None]:
assert database.qualified_name
schema_name = TestId.make_unique("my_schema")
to_create = Schema.create(
name=schema_name, database_qualified_name=database.qualified_name
)
to_create.qualified_name = database.qualified_name
result = client.asset.save(to_create)
sch = result.assets_created(asset_type=Schema)[0]
yield sch
delete_asset(client, guid=sch.guid, asset_type=Schema)


@pytest.fixture()
def current_user(client: AtlanClient) -> UserMinimalResponse:
return client.user.get_current()
Expand Down Expand Up @@ -321,6 +339,30 @@ def test_append_terms_using_ref_by_guid_for_term(
assert database.assigned_terms[0].guid == term1.guid


def test_append_terms_with_same_qn(
client: AtlanClient,
term1: AtlasGlossaryTerm,
database: Database,
schema_with_db_qn: Schema,
):
time.sleep(5)
assert schema_with_db_qn.qualified_name == database.qualified_name
assert (
database := client.asset.append_terms(
qualified_name=database.qualified_name,
asset_type=Database,
terms=[AtlasGlossaryTerm.ref_by_guid(guid=term1.guid)],
)
)
assert (
schema_with_db_qn := client.asset.append_terms(
qualified_name=schema_with_db_qn.qualified_name,
asset_type=Schema,
terms=[AtlasGlossaryTerm.ref_by_guid(guid=term1.guid)],
)
)


def test_replace_a_term(
client: AtlanClient,
term1: AtlasGlossaryTerm,
Expand Down Expand Up @@ -350,6 +392,26 @@ def test_replace_a_term(
assert database.assigned_terms[0].guid == term2.guid


def test_replace_terms_with_same_qn(
client: AtlanClient,
term2: AtlasGlossaryTerm,
database: Database,
schema_with_db_qn: Schema,
):
time.sleep(5)
assert schema_with_db_qn.qualified_name == database.qualified_name
assert (
database := client.asset.replace_terms(
guid=database.guid, asset_type=Database, terms=[term2]
)
)
assert (
schema_with_db_qn := client.asset.replace_terms(
guid=schema_with_db_qn.guid, asset_type=Schema, terms=[term2]
)
)


def test_replace_all_term(
client: AtlanClient,
term1: AtlasGlossaryTerm,
Expand Down Expand Up @@ -411,6 +473,51 @@ def test_remove_term(
assert database.assigned_terms[0].guid == term2.guid


def test_remove_terms_with_same_qn(
client: AtlanClient,
term1: AtlasGlossaryTerm,
term2: AtlasGlossaryTerm,
database: Database,
schema_with_db_qn: Schema,
):
time.sleep(5)
assert schema_with_db_qn.qualified_name == database.qualified_name
assert (
database := client.asset.append_terms(
qualified_name=database.qualified_name,
asset_type=Database,
terms=[
AtlasGlossaryTerm.ref_by_guid(guid=term1.guid),
AtlasGlossaryTerm.ref_by_guid(guid=term2.guid),
],
)
)
assert (
database := client.asset.remove_terms(
guid=database.guid,
asset_type=Database,
terms=[AtlasGlossaryTerm.ref_by_guid(term1.guid)],
)
)
assert (
schema_with_db_qn := client.asset.append_terms(
qualified_name=schema_with_db_qn.qualified_name,
asset_type=Schema,
terms=[
AtlasGlossaryTerm.ref_by_guid(guid=term1.guid),
AtlasGlossaryTerm.ref_by_guid(guid=term2.guid),
],
)
)
assert (
schema_with_db_qn := client.asset.remove_terms(
guid=schema_with_db_qn.guid,
asset_type=Schema,
terms=[AtlasGlossaryTerm.ref_by_guid(term1.guid)],
)
)


def test_find_connections_by_name(client: AtlanClient):
connections = client.asset.find_connections_by_name(
name="development",
Expand Down

0 comments on commit 395c9ed

Please sign in to comment.