Skip to content

Commit 8ab2f4f

Browse files
committed
Add integration test for Badge
1 parent 529dcf0 commit 8ab2f4f

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

pyatlan/cache/custom_metadata_cache.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def refresh_cache(cls) -> None:
7272
attr_id = str(attr.name)
7373
attr_name = str(attr.display_name)
7474
# Use a renamed attribute everywhere
75-
attr_renamed = to_snake_case(attr_name.replace(" ", ""))
75+
attr_renamed = to_snake_case(attr_name)
7676
cls.map_attr_id_to_name[type_id][attr_id] = attr_renamed
7777
if attr.options and attr.options.is_archived:
7878
cls.archived_attr_ids[attr_id] = attr_renamed

pyatlan/model/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def to_snake_case(value):
4949
res.append(c.lower())
5050
else:
5151
res.append(c)
52-
return "".join(res)
52+
return "".join(res).replace(" _", "_").replace(" ", "_")
5353

5454

5555
class ClassificationName:

tests/integration/custom_metadata_test.py

+49-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# Copyright 2022 Atlan Pte. Ltd.
3+
import logging
34
import time
45
from typing import Generator, List, Optional
56

@@ -8,16 +9,25 @@
89
from pyatlan.cache.custom_metadata_cache import CustomMetadataCache
910
from pyatlan.client.atlan import AtlanClient
1011
from pyatlan.error import NotFoundError
11-
from pyatlan.model.assets import AtlasGlossary, AtlasGlossaryTerm, Table
12+
from pyatlan.model.assets import (
13+
AtlasGlossary,
14+
AtlasGlossaryTerm,
15+
Badge,
16+
BadgeCondition,
17+
Table,
18+
)
1219
from pyatlan.model.core import CustomMetadata, to_snake_case
13-
from pyatlan.model.enums import AtlanCustomAttributePrimitiveType, AtlanTypeCategory
20+
from pyatlan.model.enums import (
21+
AtlanCustomAttributePrimitiveType,
22+
AtlanTypeCategory,
23+
BadgeComparisonOperator,
24+
BadgeConditionColor,
25+
)
1426
from pyatlan.model.search import DSL, Bool, Exists, IndexSearchRequest, Term
1527
from pyatlan.model.typedef import AttributeDef, CustomMetadataDef, EnumDef
1628
from tests.integration.client import delete_asset
1729
from tests.integration.glossary_test import create_glossary, create_term
1830

19-
import logging
20-
2131
LOGGER = logging.getLogger(__name__)
2232

2333
PREFIX = "psdk-"
@@ -287,7 +297,8 @@ def cm_dq(
287297
client,
288298
name=CM_QUALITY,
289299
attribute_defs=attribute_defs,
290-
logo="https://github.com/great-expectations/great_expectations/raw/develop/docs/docusaurus/static/img/gx-mark-160.png",
300+
logo="https://github.com/great-expectations/great_expectations/raw/develop/docs/docusaurus/static/img/"
301+
"gx-mark-160.png",
291302
locked=False,
292303
)
293304
yield cm
@@ -512,7 +523,6 @@ def test_search_by_specific_accountable(
512523
anchor = t.attributes.anchor
513524
assert anchor
514525
assert anchor.name == glossary.name
515-
return t
516526

517527

518528
@pytest.mark.order(
@@ -879,3 +889,36 @@ def _validate_raci_structure(
879889
if total_expected > 4:
880890
return attributes[total_expected - 1]
881891
return None
892+
893+
894+
def test_add_badge_cm_dq(
895+
client: AtlanClient,
896+
cm_dq: CustomMetadataDef,
897+
):
898+
badge = Badge.create(
899+
name=CM_ATTR_QUALITY_COUNT,
900+
cm_name=CM_QUALITY,
901+
cm_attribute=CM_ATTR_QUALITY_COUNT_RENAMED,
902+
badge_conditions=[
903+
BadgeCondition.create(
904+
badge_condition_operator=BadgeComparisonOperator.GTE,
905+
badge_condition_value="5",
906+
badge_condition_colorhex=BadgeConditionColor.GREEN,
907+
),
908+
BadgeCondition.create(
909+
badge_condition_operator=BadgeComparisonOperator.LT,
910+
badge_condition_value="5",
911+
badge_condition_colorhex=BadgeConditionColor.YELLOW,
912+
),
913+
BadgeCondition.create(
914+
badge_condition_operator=BadgeComparisonOperator.LTE,
915+
badge_condition_value="2",
916+
badge_condition_colorhex=BadgeConditionColor.RED,
917+
),
918+
],
919+
)
920+
badge.user_description = "How many data quality checks ran against this asset."
921+
response = client.upsert(badge)
922+
assert (badges := response.assets_created(asset_type=Badge))
923+
assert len(badges) == 1
924+
client.purge_entity_by_guid(badges[0].guid)

0 commit comments

Comments
 (0)