Skip to content

Commit d421608

Browse files
committed
Fix tests
1 parent 0b6ab37 commit d421608

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

tests/sip/test_types.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,8 @@ def test_uri__absent(self):
394394

395395
def test_uri__unparseable(self):
396396
"""Return None when the URI-like string is not valid for any parser."""
397-
assert CallerID("sip:@invalid").uri is None
398-
399-
def test_user__tel_number(self):
400-
"""Return the tel number as user for a tel: CallerID."""
401-
assert CallerID("tel:+15551234567").user == "+15551234567"
397+
with pytest.raises(ValueError):
398+
assert CallerID("sip:@invalid").uri
402399

403400
def test_host__tel_absent(self):
404401
"""Return None for host when the CallerID is a tel URI."""

voip/sip/types.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,15 @@ def uri(self) -> SipURI | None:
249249

250250
@property
251251
def user(self) -> str | None:
252-
"""SIP user part or telephone number."""
253-
return self.uri.user if self.uri else None
252+
"""SIP user part (phone number or username)."""
253+
if m := re.search(r"sips?:([^@>;\s]+)@", self):
254+
return m.group(1)
254255

255256
@property
256-
def host(self) -> str | ipaddress.IPv4Address | ipaddress.IPv6Address | None:
257+
def host(self) -> str | None:
257258
"""Carrier domain extracted from the SIP URI."""
258-
return self.uri.host if self.uri else None
259+
if m := re.search(r"sips?:[^@>;\s]+@([^>;)\s,]+)", self):
260+
return m.group(1)
259261

260262
@property
261263
def tag(self) -> str | None:

0 commit comments

Comments
 (0)