Skip to content

Commit 8534615

Browse files
committed
[tests/fix] Fixed cm test and updated models validate_required_fields() method
1 parent 018536a commit 8534615

9 files changed

Lines changed: 19 additions & 8 deletions

File tree

pyatlan/model/assets/badge.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Badge(Asset, type_name="Badge"):
2828
def creator(
2929
cls,
3030
*,
31+
client: AtlanClient,
3132
name: StrictStr,
3233
cm_name: str,
3334
cm_attribute: str,
@@ -36,6 +37,7 @@ def creator(
3637
return cls(
3738
status=EntityStatus.ACTIVE,
3839
attributes=Badge.Attributes.create(
40+
client=client,
3941
name=name,
4042
cm_name=cm_name,
4143
cm_attribute=cm_attribute,
@@ -48,6 +50,7 @@ def creator(
4850
def create(
4951
cls,
5052
*,
53+
client: AtlanClient,
5154
name: StrictStr,
5255
cm_name: str,
5356
cm_attribute: str,
@@ -62,6 +65,7 @@ def create(
6265
stacklevel=2,
6366
)
6467
return cls.creator(
68+
client=client,
6569
name=name,
6670
cm_name=cm_name,
6771
cm_attribute=cm_attribute,
@@ -141,8 +145,8 @@ def create(
141145
badge_conditions: List[BadgeCondition],
142146
) -> Badge.Attributes:
143147
validate_required_fields(
144-
["name", "cm_name", "cm_attribute", "badge_conditions"],
145-
[name, cm_name, cm_attribute, badge_conditions],
148+
["client", "name", "cm_name", "cm_attribute", "badge_conditions"],
149+
[client, name, cm_name, cm_attribute, badge_conditions],
146150
)
147151
cm_id = client.custom_metadata_cache.get_id_for_name(cm_name)
148152
cm_attr_id = client.custom_metadata_cache.get_attr_id_for_name(

pyatlan/model/assets/collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def creator(
103103
client: AtlanClient,
104104
name: str,
105105
) -> Collection.Attributes:
106-
validate_required_fields(["name"], [name])
106+
validate_required_fields(["client", "name"], [client, name])
107107
return Collection.Attributes(
108108
name=name,
109109
qualified_name=Collection._generate_qualified_name(client),

pyatlan/model/assets/connection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ def creator(
4343
host: Optional[str] = None,
4444
port: Optional[int] = None,
4545
) -> Connection:
46-
validate_required_fields(["name", "connector_type"], [name, connector_type])
46+
validate_required_fields(
47+
["client", "name", "connector_type"], [client, name, connector_type]
48+
)
4749
if not admin_users and not admin_groups and not admin_roles:
4850
raise ValueError(
4951
"One of admin_user, admin_groups or admin_roles is required"

pyatlan/model/assets/purpose.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def create_metadata_policy(
6565
all_users: bool = False,
6666
) -> AuthPolicy:
6767
validate_required_fields(
68-
["name", "purpose_id", "policy_type", "actions"],
69-
[name, purpose_id, policy_type, actions],
68+
["client", "name", "purpose_id", "policy_type", "actions"],
69+
[client, name, purpose_id, policy_type, actions],
7070
)
7171
target_found = False
7272
policy = AuthPolicy._AuthPolicy__create(name=name) # type: ignore[attr-defined]
@@ -121,7 +121,8 @@ def create_data_policy(
121121
all_users: bool = False,
122122
) -> AuthPolicy:
123123
validate_required_fields(
124-
["name", "purpose_id", "policy_type"], [name, purpose_id, policy_type]
124+
["client", "name", "purpose_id", "policy_type"],
125+
[client, name, purpose_id, policy_type],
125126
)
126127
policy = AuthPolicy._AuthPolicy__create(name=name) # type: ignore[attr-defined]
127128
policy.policy_actions = {DataAction.SELECT.value}

pyatlan/model/custom_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ def __init__(
118118
client: AtlanClient,
119119
business_attributes: Optional[Dict[str, Any]],
120120
):
121+
self._client = client
121122
self._metadata: Optional[Dict[str, CustomMetadataDict]] = None
122123
self._business_attributes = business_attributes
123124
self._modified = False
124125
if self._business_attributes is None:
125126
return
126127
self._metadata = {}
127-
self._client = client
128128
for cm_id, cm_attributes in self._business_attributes.items():
129129
try:
130130
cm_name = self._client.custom_metadata_cache.get_name_for_id(cm_id)

pyatlan/samples/custom_metadata/deploy_branded_cm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def create_badge():
7979
custom metadata structure.
8080
"""
8181
badge = Badge.create(
82+
client=client,
8283
name="Rating",
8384
cm_name=CUSTOM_METADATA_NAME,
8485
cm_attribute="Rating",

pyatlan/samples/events/lambda_scorer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def _create_cm_if_not_exists(client: AtlanClient) -> Optional[str]:
7171
client.typedef.create(cm_def)
7272
logger.info("Created DaaP custom metadata structure.")
7373
badge = Badge.create(
74+
client=client,
7475
name=CM_ATTR_DAAP_SCORE,
7576
cm_name=CM_DAAP,
7677
cm_attribute=CM_ATTR_DAAP_SCORE,

tests/integration/custom_metadata_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,7 @@ def test_add_badge_cm_dq(
11171117
cm_dq: CustomMetadataDef,
11181118
):
11191119
badge = Badge.create(
1120+
client=client,
11201121
name=CM_ATTR_QUALITY_COUNT,
11211122
cm_name=CM_QUALITY,
11221123
cm_attribute=CM_ATTR_QUALITY_COUNT,

tests/unit/model/badge_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def test_create_when_required_parameters_are_missing_raises_value_error(
7070
):
7171
with pytest.raises(ValueError, match=message):
7272
Badge.create(
73+
client=client,
7374
name=name,
7475
cm_name=cm_name,
7576
cm_attribute=cm_attribute,

0 commit comments

Comments
 (0)