Skip to content

Commit 0bcc99d

Browse files
Aryamanz29claude
andcommitted
test: add v9 unit tests for STRING vs RICH_TEXT attribute creation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7b24d9a commit 0bcc99d

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright 2022 Atlan Pte. Ltd.
3+
from unittest.mock import patch
4+
5+
import pytest
6+
7+
from pyatlan.client.atlan import AtlanClient
8+
from pyatlan.errors import AtlanError
9+
from pyatlan.model.enums import AtlanCustomAttributePrimitiveType
10+
from pyatlan_v9.model.typedef import AttributeDef
11+
12+
13+
@pytest.fixture(autouse=True)
14+
def set_env(monkeypatch):
15+
monkeypatch.setenv("ATLAN_API_KEY", "test-api-key")
16+
monkeypatch.setenv("ATLAN_BASE_URL", "https://test.atlan.com")
17+
18+
19+
@pytest.fixture()
20+
def client():
21+
return AtlanClient()
22+
23+
24+
class TestV9AttributeDef:
25+
def test_string_and_rich_text_are_distinct_enum_members(self):
26+
"""Test that STRING and RICH_TEXT are distinct enum members (not aliases)"""
27+
assert (
28+
AtlanCustomAttributePrimitiveType.STRING
29+
is not AtlanCustomAttributePrimitiveType.RICH_TEXT
30+
)
31+
assert (
32+
AtlanCustomAttributePrimitiveType.STRING
33+
!= AtlanCustomAttributePrimitiveType.RICH_TEXT
34+
)
35+
assert (
36+
AtlanCustomAttributePrimitiveType.STRING.value
37+
!= AtlanCustomAttributePrimitiveType.RICH_TEXT.value
38+
)
39+
40+
def test_string_attribute_is_not_rich_text(self, client: AtlanClient):
41+
"""Test that STRING attributes do NOT have is_rich_text set"""
42+
with patch("pyatlan_v9.model.typedef._get_all_qualified_names") as mock_get_qa:
43+
mock_get_qa.return_value = set()
44+
attr_def = AttributeDef.creator(
45+
client=client,
46+
display_name="Plain String",
47+
attribute_type=AtlanCustomAttributePrimitiveType.STRING,
48+
)
49+
50+
assert attr_def.options
51+
assert attr_def.options.is_rich_text is False
52+
assert attr_def.options.primitive_type == "string"
53+
assert attr_def.type_name == "string"
54+
55+
def test_rich_text_attribute_creation(self, client: AtlanClient):
56+
"""Test that RICH_TEXT attributes are created with correct options"""
57+
with patch("pyatlan_v9.model.typedef._get_all_qualified_names") as mock_get_qa:
58+
mock_get_qa.return_value = set()
59+
attr_def = AttributeDef.creator(
60+
client=client,
61+
display_name="Rich Content",
62+
attribute_type=AtlanCustomAttributePrimitiveType.RICH_TEXT,
63+
description="Test rich text attribute",
64+
)
65+
66+
assert attr_def.display_name == "Rich Content"
67+
assert attr_def.type_name == AtlanCustomAttributePrimitiveType.STRING.value
68+
assert attr_def.description == "Test rich text attribute"
69+
assert attr_def.options
70+
assert attr_def.options.is_rich_text is True
71+
assert attr_def.options.multi_value_select is False
72+
73+
def test_rich_text_cannot_be_multi_valued(self, client: AtlanClient):
74+
"""Test that RICH_TEXT attributes cannot be multi-valued"""
75+
with patch("pyatlan_v9.model.typedef._get_all_qualified_names") as mock_get_qa:
76+
mock_get_qa.return_value = set()
77+
with pytest.raises(AtlanError) as exc_info:
78+
AttributeDef.creator(
79+
client=client,
80+
display_name="Invalid Rich Text",
81+
attribute_type=AtlanCustomAttributePrimitiveType.RICH_TEXT,
82+
multi_valued=True,
83+
)
84+
85+
error = exc_info.value
86+
assert "ATLAN-PYTHON-400-076" in str(error)
87+
88+
def test_rich_text_options_configuration(self, client: AtlanClient):
89+
"""Test that RICH_TEXT options are configured correctly"""
90+
with patch("pyatlan_v9.model.typedef._get_all_qualified_names") as mock_get_qa:
91+
mock_get_qa.return_value = set()
92+
attr_def = AttributeDef.creator(
93+
client=client,
94+
display_name="Rich Text Field",
95+
attribute_type=AtlanCustomAttributePrimitiveType.RICH_TEXT,
96+
)
97+
98+
options = attr_def.options
99+
assert options is not None
100+
assert options.primitive_type == AtlanCustomAttributePrimitiveType.STRING.value
101+
assert options.is_rich_text is True
102+
assert options.multi_value_select is False

0 commit comments

Comments
 (0)