Skip to content

Commit 0dbabad

Browse files
committed
Adds group custom metadata properties to tests
Signed-off-by: Christopher Grote <[email protected]>
1 parent 08d596c commit 0dbabad

File tree

1 file changed

+65
-21
lines changed

1 file changed

+65
-21
lines changed

tests/integration/custom_metadata_test.py

Lines changed: 65 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright 2022 Atlan Pte. Ltd.
33
import logging
44
import time
5-
from typing import Generator, List, Optional
5+
from typing import Generator, List, Optional, Tuple
66

77
import pytest
88

@@ -23,10 +23,12 @@
2323
BadgeComparisonOperator,
2424
BadgeConditionColor,
2525
)
26+
from pyatlan.model.group import AtlanGroup, CreateGroupResponse
2627
from pyatlan.model.search import DSL, Bool, Exists, IndexSearchRequest, Term
2728
from pyatlan.model.typedef import AttributeDef, CustomMetadataDef, EnumDef
2829
from tests.integration.client import delete_asset
2930
from tests.integration.glossary_test import create_glossary, create_term
31+
from tests.integration.admin_test import create_group, delete_group
3032

3133
LOGGER = logging.getLogger(__name__)
3234

@@ -79,8 +81,8 @@
7981
CM_ATTR_QUALITY_SQL_RENAMED = to_snake_case(CM_ATTR_QUALITY_SQL)
8082
CM_ATTR_QUALITY_TYPE_RENAMED = to_snake_case(CM_ATTR_QUALITY_TYPE)
8183

82-
GROUP_NAME1 = f"{PREFIX}1"
83-
GROUP_NAME2 = f"{PREFIX}2"
84+
GROUP_NAME1 = f"{CM_PREFIX}1"
85+
GROUP_NAME2 = f"{CM_PREFIX}2"
8486

8587
_removal_epoch: Optional[int]
8688

@@ -358,23 +360,52 @@ def term(
358360
delete_asset(client, guid=t.guid, asset_type=AtlasGlossaryTerm)
359361

360362

361-
# TODO: create the groups, once they're modeled in the SDK...
362-
# @pytest.fixure
363-
# def groups(client: AtlanClient) -> Generator[List[], None, None]:
363+
@pytest.fixture(scope="module")
364+
def groups(
365+
client: AtlanClient,
366+
glossary: AtlasGlossary,
367+
term: AtlasGlossaryTerm,
368+
cm_raci: CustomMetadataDef,
369+
cm_ipr: CustomMetadataDef,
370+
cm_dq: CustomMetadataDef,
371+
) -> Generator[List[CreateGroupResponse], None, None]:
372+
g1 = create_group(client, GROUP_NAME1)
373+
g2 = create_group(client, GROUP_NAME2)
374+
created = [g1, g2]
375+
yield created
376+
delete_group(client, g1.group)
377+
delete_group(client, g2.group)
378+
379+
380+
def _get_groups(client: AtlanClient) -> Tuple[AtlanGroup, AtlanGroup]:
381+
candidates = client.get_group_by_name(GROUP_NAME1)
382+
assert candidates
383+
assert len(candidates) == 1
384+
group1 = candidates[0]
385+
candidates = client.get_group_by_name(GROUP_NAME2)
386+
assert candidates
387+
assert len(candidates) == 1
388+
group2 = candidates[0]
389+
return group1, group2
364390

365391

366392
def test_add_term_cm_raci(
367-
client: AtlanClient, cm_raci: CustomMetadataDef, term: AtlasGlossaryTerm
393+
client: AtlanClient,
394+
cm_raci: CustomMetadataDef,
395+
term: AtlasGlossaryTerm,
396+
groups: List[AtlanGroup],
368397
):
369398
raci_attrs = term.get_custom_metadata(CM_RACI)
370399
_validate_raci_empty(raci_attrs)
400+
group1, group2 = _get_groups(client)
371401
setattr(raci_attrs, CM_ATTR_RACI_RESPONSIBLE_RENAMED, [FIXED_USER])
372402
setattr(raci_attrs, CM_ATTR_RACI_ACCOUNTABLE_RENAMED, FIXED_USER)
373-
# TODO: set Consulted and Informed once groups are available
403+
setattr(raci_attrs, CM_ATTR_RACI_CONSULTED_RENAMED, [group1.name])
404+
setattr(raci_attrs, CM_ATTR_RACI_INFORMED_RENAMED, [group1.name, group2.name])
374405
client.update_custom_metadata_attributes(term.guid, raci_attrs)
375406
t = client.retrieve_minimal(guid=term.guid, asset_type=AtlasGlossaryTerm)
376407
assert t
377-
_validate_raci_attributes(t.get_custom_metadata(name=CM_RACI))
408+
_validate_raci_attributes(client, t.get_custom_metadata(name=CM_RACI))
378409

379410

380411
def test_add_term_cm_ipr(
@@ -422,7 +453,7 @@ def test_update_term_cm_ipr(
422453
t = client.retrieve_minimal(guid=term.guid, asset_type=AtlasGlossaryTerm)
423454
assert t
424455
_validate_ipr_attributes(t.get_custom_metadata(name=CM_IPR), mandatory=False)
425-
_validate_raci_attributes(t.get_custom_metadata(name=CM_RACI))
456+
_validate_raci_attributes(client, t.get_custom_metadata(name=CM_RACI))
426457
_validate_dq_attributes(t.get_custom_metadata(name=CM_QUALITY))
427458

428459

@@ -431,14 +462,16 @@ def test_replace_term_cm_raci(
431462
client: AtlanClient, cm_raci: CustomMetadataDef, term: AtlasGlossaryTerm
432463
):
433464
raci = term.get_custom_metadata(CM_RACI)
465+
group1, group2 = _get_groups(client)
434466
# Note: MUST access the getter / setter, not the underlying store
435-
setattr(raci, CM_ATTR_RACI_RESPONSIBLE_RENAMED, None)
467+
setattr(raci, CM_ATTR_RACI_RESPONSIBLE_RENAMED, [FIXED_USER])
436468
setattr(raci, CM_ATTR_RACI_ACCOUNTABLE_RENAMED, FIXED_USER)
437-
# TODO: replace consulted or informed (not yet defined, waiting on groups support)
469+
setattr(raci, CM_ATTR_RACI_CONSULTED_RENAMED, None)
470+
setattr(raci, CM_ATTR_RACI_INFORMED_RENAMED, [group1.name, group2.name])
438471
client.replace_custom_metadata(term.guid, raci)
439472
t = client.retrieve_minimal(guid=term.guid, asset_type=AtlasGlossaryTerm)
440473
assert t
441-
_validate_raci_attributes_replacement(t.get_custom_metadata(name=CM_RACI))
474+
_validate_raci_attributes_replacement(client, t.get_custom_metadata(name=CM_RACI))
442475
_validate_ipr_attributes(t.get_custom_metadata(name=CM_IPR), mandatory=False)
443476
_validate_dq_attributes(t.get_custom_metadata(name=CM_QUALITY))
444477

@@ -450,7 +483,7 @@ def test_replace_term_cm_ipr(
450483
client.replace_custom_metadata(term.guid, term.get_custom_metadata(CM_IPR))
451484
t = client.retrieve_minimal(guid=term.guid, asset_type=AtlasGlossaryTerm)
452485
assert t
453-
_validate_raci_attributes_replacement(t.get_custom_metadata(name=CM_RACI))
486+
_validate_raci_attributes_replacement(client, t.get_custom_metadata(name=CM_RACI))
454487
_validate_dq_attributes(t.get_custom_metadata(name=CM_QUALITY))
455488
_validate_ipr_empty(t.get_custom_metadata(name=CM_IPR))
456489

@@ -695,9 +728,11 @@ def test_update_replacing_cm(
695728
client: AtlanClient,
696729
):
697730
raci = term.get_custom_metadata(CM_RACI)
731+
group1, group2 = _get_groups(client)
698732
setattr(raci, CM_ATTR_RACI_RESPONSIBLE_RENAMED, [FIXED_USER])
699733
setattr(raci, CM_ATTR_RACI_ACCOUNTABLE_RENAMED, FIXED_USER)
700-
# TODO: set consulted and informed once groups are available
734+
setattr(raci, CM_ATTR_RACI_CONSULTED_RENAMED, [group1.name])
735+
setattr(raci, CM_ATTR_RACI_INFORMED_RENAMED, [group1.name, group2.name])
701736
setattr(raci, CM_ATTR_RACI_EXTRA_RENAMED, "something extra...")
702737
to_update = AtlasGlossaryTerm.create_for_modification(
703738
qualified_name=term.qualified_name, name=term.name, glossary_guid=glossary.guid
@@ -719,7 +754,7 @@ def test_update_replacing_cm(
719754
assert not x.is_incomplete
720755
assert x.qualified_name == term.qualified_name
721756
raci = x.get_custom_metadata(CM_RACI)
722-
_validate_raci_attributes(raci)
757+
_validate_raci_attributes(client, raci)
723758
assert getattr(raci, CM_ATTR_RACI_EXTRA_RENAMED) == "something extra..."
724759
_validate_ipr_empty(x.get_custom_metadata(CM_IPR))
725760
_validate_dq_empty(x.get_custom_metadata(CM_QUALITY))
@@ -735,28 +770,37 @@ def test_get_custom_metadata_when_name_is_invalid_then_raises_not_found_error():
735770
CustomMetadataCache.get_custom_metadata(name="Bogs", asset_type=Table)
736771

737772

738-
def _validate_raci_attributes(cma: CustomMetadata):
773+
def _validate_raci_attributes(client: AtlanClient, cma: CustomMetadata):
739774
assert cma
740775
# Note: MUST access the getter / setter, not the underlying store
741776
responsible = getattr(cma, CM_ATTR_RACI_RESPONSIBLE_RENAMED)
742777
accountable = getattr(cma, CM_ATTR_RACI_ACCOUNTABLE_RENAMED)
778+
consulted = getattr(cma, CM_ATTR_RACI_CONSULTED_RENAMED)
779+
informed = getattr(cma, CM_ATTR_RACI_INFORMED_RENAMED)
780+
group1, group2 = _get_groups(client)
743781
assert responsible
744782
assert len(responsible) == 1
745783
assert FIXED_USER in responsible
746784
assert accountable
747785
assert accountable == FIXED_USER
748-
# TODO: validate consulted and informed, once groups are included
786+
assert consulted == [group1.name]
787+
assert informed == [group1.name, group2.name]
749788

750789

751-
def _validate_raci_attributes_replacement(cma: CustomMetadata):
790+
def _validate_raci_attributes_replacement(client: AtlanClient, cma: CustomMetadata):
752791
assert cma
753792
# Note: MUST access the getter / setter, not the underlying store
754793
responsible = getattr(cma, CM_ATTR_RACI_RESPONSIBLE_RENAMED)
755794
accountable = getattr(cma, CM_ATTR_RACI_ACCOUNTABLE_RENAMED)
756-
assert not responsible
795+
consulted = getattr(cma, CM_ATTR_RACI_CONSULTED_RENAMED)
796+
informed = getattr(cma, CM_ATTR_RACI_INFORMED_RENAMED)
797+
group1, group2 = _get_groups(client)
798+
assert responsible
799+
assert responsible == [FIXED_USER]
757800
assert accountable
758801
assert accountable == FIXED_USER
759-
# TODO: validate consulted and informed, once groups are included
802+
assert not consulted
803+
assert informed == [group1.name, group2.name]
760804

761805

762806
def _validate_raci_empty(raci_attrs: CustomMetadata):

0 commit comments

Comments
 (0)