Skip to content

Commit 4d96713

Browse files
committed
fix: add public type property to AuthenticationMethod base class
The _type class attribute was private, causing AttributeError when examples or user code accessed auth.type. Add a @Property that exposes it as a read-only public attribute.
1 parent 644cba0 commit 4d96713

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/didww/resources/authentication_method.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ class AuthenticationMethod:
66
def __init__(self, **kwargs):
77
self._attributes = kwargs
88

9+
@property
10+
def type(self):
11+
return self._type
12+
913
def _attr(self, key):
1014
return self._attributes.get(key)
1115

tests/resources/test_voice_out_trunk.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,18 @@ def test_to_jsonapi_roundtrip(self):
201201
auth = IpOnlyAuthenticationMethod(allowed_sip_ips=["10.0.0.0/8"], tech_prefix="")
202202
serialized = auth.to_jsonapi()
203203
assert serialized == {"type": "ip_only", "attributes": {"allowed_sip_ips": ["10.0.0.0/8"], "tech_prefix": ""}}
204+
205+
def test_type_property_on_known_subclass(self):
206+
auth = IpOnlyAuthenticationMethod(allowed_sip_ips=["203.0.113.0/24"])
207+
assert auth.type == "ip_only"
208+
209+
def test_type_property_on_credentials_and_ip(self):
210+
auth = CredentialsAndIpAuthenticationMethod(
211+
allowed_sip_ips=["203.0.113.0/24"], username="u", password="p",
212+
)
213+
assert auth.type == "credentials_and_ip"
214+
215+
def test_type_property_on_generic(self):
216+
data = {"type": "future_auth", "attributes": {"key": "val"}}
217+
auth = AuthenticationMethod.from_jsonapi(data)
218+
assert auth.type == "future_auth"

0 commit comments

Comments
 (0)