Skip to content

Commit 97e8d13

Browse files
committed
[refactor + tests] Refactored and updated unit tests
1 parent cb6fcc2 commit 97e8d13

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

pyatlan/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ class ErrorCode(Enum):
484484
INVALID_PARAMETER_VALUE = (
485485
400,
486486
"ATLAN-PYTHON-400-051",
487-
"{0} is an invalid value for {1} should be in {2}.",
488-
"Check that value you are using is valid.",
487+
"Invalid value(s) {0} provided for '{1}'. Expected one or more of the supported {2}.",
488+
"Verify that each value corresponds to a valid SDK asset type.",
489489
InvalidRequestError,
490490
)
491491
ASSET_CAN_NOT_BE_ARCHIVED = (

pyatlan/model/typedef.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
import sys
55
import time
6-
from typing import Any, Callable, ClassVar, Dict, List, Optional, Set, cast
6+
from typing import Any, Callable, ClassVar, Dict, List, Optional, Set, Union, cast
77

88
from pydantic.v1 import Field, PrivateAttr
99

@@ -652,7 +652,7 @@ def applicable_entity_types(self, entity_types: EntityTypes):
652652
self.options.applicable_entity_types = json.dumps(list(entity_types))
653653

654654
@property
655-
def applicable_asset_types(self) -> AssetTypes:
655+
def applicable_asset_types(self) -> Union[Set[str], AssetTypes]:
656656
"""
657657
Asset type names to which to restrict the attribute.
658658
Only assets of one of these types will have this attribute available.
@@ -663,25 +663,27 @@ def applicable_asset_types(self) -> AssetTypes:
663663
return set()
664664

665665
@applicable_asset_types.setter
666-
def applicable_asset_types(self, asset_types):
666+
def applicable_asset_types(self, asset_types: Union[Set[str], AssetTypes]):
667667
if self.options is None:
668668
raise ErrorCode.MISSING_OPTIONS.exception_with_parameters()
669+
669670
if not isinstance(asset_types, set):
670671
raise ErrorCode.INVALID_PARAMETER_TYPE.exception_with_parameters(
671672
"applicable_asset_types", AssetTypes
672673
)
673-
invalid_types = set()
674-
for asset_type in asset_types:
674+
675+
# Validate asset type names against SDK asset classes
676+
invalid_types = {
677+
asset_type
678+
for asset_type in asset_types
675679
if not getattr(
676680
sys.modules.get("pyatlan.model.assets", {}), asset_type, None
677-
):
678-
invalid_types.add(asset_type)
679-
681+
)
682+
}
680683
if invalid_types:
681684
raise ErrorCode.INVALID_PARAMETER_VALUE.exception_with_parameters(
682-
asset_types, "applicable_asset_types", "SDK asset types"
685+
invalid_types, "applicable_asset_types", "SDK asset types"
683686
)
684-
685687
self.options.applicable_asset_types = json.dumps(list(asset_types))
686688

687689
@property
@@ -835,7 +837,7 @@ def create(
835837
multi_valued: bool = False,
836838
options_name: Optional[str] = None,
837839
applicable_connections: Optional[Set[str]] = None,
838-
applicable_asset_types: Optional[AssetTypes] = None,
840+
applicable_asset_types: Optional[Union[Set[str], AssetTypes]] = None,
839841
applicable_glossaries: Optional[Set[str]] = None,
840842
applicable_glossary_types: Optional[GlossaryTypes] = None,
841843
applicable_other_asset_types: Optional[OtherAssetTypes] = None,

tests/unit/constants.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@
699699
(
700700
APPLICABLE_ASSET_TYPES,
701701
{"Bogus"},
702-
"ATLAN-PYTHON-400-051 {'Bogus'} is an invalid value for applicable_asset_types should be in ",
702+
"ATLAN-PYTHON-400-051 Invalid value(s) {'Bogus'} provided for 'applicable_asset_types'.",
703703
),
704704
(
705705
APPLICABLE_GLOSSARY_TYPES,
@@ -709,7 +709,7 @@
709709
(
710710
APPLICABLE_GLOSSARY_TYPES,
711711
{"Bogus"},
712-
"ATLAN-PYTHON-400-051 {'Bogus'} is an invalid value for applicable_glossary_types should be in ",
712+
"ATLAN-PYTHON-400-051 Invalid value(s) {'Bogus'} provided for 'applicable_glossary_types'.",
713713
),
714714
(
715715
APPLICABLE_DOMAIN_TYPES,
@@ -719,7 +719,7 @@
719719
(
720720
APPLICABLE_DOMAIN_TYPES,
721721
{"Bogus"},
722-
"ATLAN-PYTHON-400-051 {'Bogus'} is an invalid value for applicable_domain_types should be in ",
722+
"ATLAN-PYTHON-400-051 Invalid value(s) {'Bogus'} provided for 'applicable_domain_types'.",
723723
),
724724
(
725725
APPLICABLE_OTHER_ASSET_TYPES,
@@ -729,7 +729,7 @@
729729
(
730730
APPLICABLE_OTHER_ASSET_TYPES,
731731
{"Bogus"},
732-
"ATLAN-PYTHON-400-051 {'Bogus'} is an invalid value for applicable_other_asset_types should be in ",
732+
"ATLAN-PYTHON-400-051 Invalid value(s) {'Bogus'} provided for 'applicable_other_asset_types'.",
733733
),
734734
(
735735
APPLICABLE_ENTITY_TYPES,

0 commit comments

Comments
 (0)