2
2
# Copyright 2022 Atlan Pte. Ltd.
3
3
import logging
4
4
import time
5
- from typing import Generator , List , Optional
5
+ from typing import Generator , List , Optional , Tuple
6
6
7
7
import pytest
8
8
23
23
BadgeComparisonOperator ,
24
24
BadgeConditionColor ,
25
25
)
26
+ from pyatlan .model .group import AtlanGroup , CreateGroupResponse
26
27
from pyatlan .model .search import DSL , Bool , Exists , IndexSearchRequest , Term
27
28
from pyatlan .model .typedef import AttributeDef , CustomMetadataDef , EnumDef
28
29
from tests .integration .client import delete_asset
29
30
from tests .integration .glossary_test import create_glossary , create_term
31
+ from tests .integration .admin_test import create_group , delete_group
30
32
31
33
LOGGER = logging .getLogger (__name__ )
32
34
79
81
CM_ATTR_QUALITY_SQL_RENAMED = to_snake_case (CM_ATTR_QUALITY_SQL )
80
82
CM_ATTR_QUALITY_TYPE_RENAMED = to_snake_case (CM_ATTR_QUALITY_TYPE )
81
83
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"
84
86
85
87
_removal_epoch : Optional [int ]
86
88
@@ -358,23 +360,52 @@ def term(
358
360
delete_asset (client , guid = t .guid , asset_type = AtlasGlossaryTerm )
359
361
360
362
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
364
390
365
391
366
392
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 ],
368
397
):
369
398
raci_attrs = term .get_custom_metadata (CM_RACI )
370
399
_validate_raci_empty (raci_attrs )
400
+ group1 , group2 = _get_groups (client )
371
401
setattr (raci_attrs , CM_ATTR_RACI_RESPONSIBLE_RENAMED , [FIXED_USER ])
372
402
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 ])
374
405
client .update_custom_metadata_attributes (term .guid , raci_attrs )
375
406
t = client .retrieve_minimal (guid = term .guid , asset_type = AtlasGlossaryTerm )
376
407
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 ))
378
409
379
410
380
411
def test_add_term_cm_ipr (
@@ -422,7 +453,7 @@ def test_update_term_cm_ipr(
422
453
t = client .retrieve_minimal (guid = term .guid , asset_type = AtlasGlossaryTerm )
423
454
assert t
424
455
_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 ))
426
457
_validate_dq_attributes (t .get_custom_metadata (name = CM_QUALITY ))
427
458
428
459
@@ -431,14 +462,16 @@ def test_replace_term_cm_raci(
431
462
client : AtlanClient , cm_raci : CustomMetadataDef , term : AtlasGlossaryTerm
432
463
):
433
464
raci = term .get_custom_metadata (CM_RACI )
465
+ group1 , group2 = _get_groups (client )
434
466
# 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 ] )
436
468
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 ])
438
471
client .replace_custom_metadata (term .guid , raci )
439
472
t = client .retrieve_minimal (guid = term .guid , asset_type = AtlasGlossaryTerm )
440
473
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 ))
442
475
_validate_ipr_attributes (t .get_custom_metadata (name = CM_IPR ), mandatory = False )
443
476
_validate_dq_attributes (t .get_custom_metadata (name = CM_QUALITY ))
444
477
@@ -450,7 +483,7 @@ def test_replace_term_cm_ipr(
450
483
client .replace_custom_metadata (term .guid , term .get_custom_metadata (CM_IPR ))
451
484
t = client .retrieve_minimal (guid = term .guid , asset_type = AtlasGlossaryTerm )
452
485
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 ))
454
487
_validate_dq_attributes (t .get_custom_metadata (name = CM_QUALITY ))
455
488
_validate_ipr_empty (t .get_custom_metadata (name = CM_IPR ))
456
489
@@ -695,9 +728,11 @@ def test_update_replacing_cm(
695
728
client : AtlanClient ,
696
729
):
697
730
raci = term .get_custom_metadata (CM_RACI )
731
+ group1 , group2 = _get_groups (client )
698
732
setattr (raci , CM_ATTR_RACI_RESPONSIBLE_RENAMED , [FIXED_USER ])
699
733
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 ])
701
736
setattr (raci , CM_ATTR_RACI_EXTRA_RENAMED , "something extra..." )
702
737
to_update = AtlasGlossaryTerm .create_for_modification (
703
738
qualified_name = term .qualified_name , name = term .name , glossary_guid = glossary .guid
@@ -719,7 +754,7 @@ def test_update_replacing_cm(
719
754
assert not x .is_incomplete
720
755
assert x .qualified_name == term .qualified_name
721
756
raci = x .get_custom_metadata (CM_RACI )
722
- _validate_raci_attributes (raci )
757
+ _validate_raci_attributes (client , raci )
723
758
assert getattr (raci , CM_ATTR_RACI_EXTRA_RENAMED ) == "something extra..."
724
759
_validate_ipr_empty (x .get_custom_metadata (CM_IPR ))
725
760
_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():
735
770
CustomMetadataCache .get_custom_metadata (name = "Bogs" , asset_type = Table )
736
771
737
772
738
- def _validate_raci_attributes (cma : CustomMetadata ):
773
+ def _validate_raci_attributes (client : AtlanClient , cma : CustomMetadata ):
739
774
assert cma
740
775
# Note: MUST access the getter / setter, not the underlying store
741
776
responsible = getattr (cma , CM_ATTR_RACI_RESPONSIBLE_RENAMED )
742
777
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 )
743
781
assert responsible
744
782
assert len (responsible ) == 1
745
783
assert FIXED_USER in responsible
746
784
assert accountable
747
785
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 ]
749
788
750
789
751
- def _validate_raci_attributes_replacement (cma : CustomMetadata ):
790
+ def _validate_raci_attributes_replacement (client : AtlanClient , cma : CustomMetadata ):
752
791
assert cma
753
792
# Note: MUST access the getter / setter, not the underlying store
754
793
responsible = getattr (cma , CM_ATTR_RACI_RESPONSIBLE_RENAMED )
755
794
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 ]
757
800
assert accountable
758
801
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 ]
760
804
761
805
762
806
def _validate_raci_empty (raci_attrs : CustomMetadata ):
0 commit comments