@@ -330,6 +330,29 @@ def test_excludes_read_only_fields(self):
330330 assert attrs ["status" ] == "Active"
331331 assert "authentication_method" in attrs
332332
333+ def test_patch_only_authentication_method_when_reassigned (self ):
334+ """PATCH must send only authentication_method when it is the only changed field."""
335+ from didww .resources .authentication_method import CredentialsAndIpAuthenticationMethod
336+ trunk = VoiceOutTrunk .build ("abc-123" )
337+ assert len (trunk ._dirty_attrs ) == 0
338+
339+ trunk .authentication_method = CredentialsAndIpAuthenticationMethod (
340+ allowed_sip_ips = ["192.0.2.10/32" ],
341+ tech_prefix = "99" ,
342+ )
343+
344+ assert "authentication_method" in trunk ._dirty_attrs
345+ doc = trunk .to_jsonapi (include_id = True , dirty_only = True )
346+ assert doc ["id" ] == "abc-123"
347+ assert doc ["type" ] == "voice_out_trunks"
348+ attrs = doc ["attributes" ]
349+ assert "authentication_method" in attrs
350+ assert attrs ["authentication_method" ]["type" ] == "credentials_and_ip"
351+ assert attrs ["authentication_method" ]["attributes" ]["allowed_sip_ips" ] == ["192.0.2.10/32" ]
352+ assert attrs ["authentication_method" ]["attributes" ]["tech_prefix" ] == "99"
353+ # No other attributes should be present
354+ assert set (attrs .keys ()) == {"authentication_method" }
355+
333356
334357# ---------------------------------------------------------------------------
335358# Dirty-only PATCH serialization tests
0 commit comments