Skip to content

Commit bd53fb7

Browse files
committed
feat: add features_human with raw-key fallback for unknown features
1 parent 4c0386f commit bd53fb7

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/didww/resources/did_group.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33

44

55
class DidGroup(DidwwApiModel):
6+
FEATURES = {
7+
"voice_in": "Voice IN",
8+
"voice_out": "Voice OUT",
9+
"t38": "T.38 Fax",
10+
"sms_in": "SMS IN",
11+
"p2p": "P2P SMS",
12+
"a2p": "A2P SMS",
13+
"emergency": "Emergency",
14+
"cnam_out": "CNAM OUT",
15+
}
16+
617
prefix = SafeAttributeField("prefix")
718
features = EnumListAttributeField("features", Feature)
819
is_metered = SafeAttributeField("is_metered")
@@ -20,6 +31,12 @@ class DidGroup(DidwwApiModel):
2031
class Meta:
2132
type = "did_groups"
2233

34+
@property
35+
def features_human(self):
36+
"""Map feature keys to human-readable labels, falling back to raw key for unknown features."""
37+
raw_features = self.attributes.get("features") or []
38+
return [self.FEATURES.get(f, f) for f in raw_features]
39+
2340

2441
class DidGroupRepository(ReadOnlyRepository):
2542
_resource_class = DidGroup

tests/resources/test_did_group.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from didww.enums import Feature, IdentityType, AreaLevel
2+
from didww.resources.did_group import DidGroup
23
from tests.conftest import my_vcr
34
from didww.query_params import QueryParams
45

@@ -11,6 +12,35 @@ def test_new_features_enum_values(self):
1112
assert Feature.CNAM_OUT.value == "cnam_out"
1213

1314

15+
class TestDidGroupFeaturesHuman:
16+
def test_features_human_maps_known_features(self):
17+
dg = DidGroup()
18+
dg.attributes["features"] = ["t38", "voice_in"]
19+
assert dg.features_human == ["T.38 Fax", "Voice IN"]
20+
21+
def test_features_human_falls_back_to_raw_key_for_unknown(self):
22+
dg = DidGroup()
23+
dg.attributes["features"] = ["voice_in", "future_unknown_feature"]
24+
assert dg.features_human == ["Voice IN", "future_unknown_feature"]
25+
26+
def test_features_human_empty_list(self):
27+
dg = DidGroup()
28+
dg.attributes["features"] = []
29+
assert dg.features_human == []
30+
31+
def test_features_human_none(self):
32+
dg = DidGroup()
33+
assert dg.features_human == []
34+
35+
def test_features_human_all_known_features(self):
36+
dg = DidGroup()
37+
dg.attributes["features"] = ["voice_in", "voice_out", "t38", "sms_in", "p2p", "a2p", "emergency", "cnam_out"]
38+
assert dg.features_human == [
39+
"Voice IN", "Voice OUT", "T.38 Fax", "SMS IN",
40+
"P2P SMS", "A2P SMS", "Emergency", "CNAM OUT",
41+
]
42+
43+
1444
class TestDidGroup:
1545
@my_vcr.use_cassette("did_groups/list.yaml")
1646
def test_list_did_groups(self, client):

0 commit comments

Comments
 (0)