def test_set_rport_to_true(): via = ViaHeader( 'SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;rport=1234;maddr=x.com' ) via.set_param(PARAM_RPORT, True) assert via.assemble( ) == 'SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;rport;maddr=x.com' assert via.rport is True
def test_set_param_received_ipv4(): via = ViaHeader( 'SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;received=1.1.1.1;maddr=x.com' ) via.set_param(PARAM_RECEIVED, '2.2.2.2') assert via.received == ipaddress.IPv4Address('2.2.2.2') via = ViaHeader( 'SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;received=1.1.1.1;maddr=x.com' ) via.set_param(PARAM_RECEIVED, ipaddress.IPv4Address('2.2.2.2')) assert via.received == ipaddress.IPv4Address('2.2.2.2')
def test_set_param_received_ipv6(): via = ViaHeader( 'SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;received=1.1.1.1;maddr=x.com' ) via.set_param(PARAM_RECEIVED, '[::1]') assert via.assemble( ) == 'SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;received=[::1];maddr=x.com' assert via.received == ipaddress.IPv6Address('::1') via = ViaHeader( 'SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;received=1.1.1.1;maddr=x.com' ) via.set_param(PARAM_RECEIVED, ipaddress.IPv6Address('::1')) assert via.assemble( ) == 'SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;received=[::1];maddr=x.com' assert via.received == ipaddress.IPv6Address('::1')
def test_set_rport_error(rport): via = ViaHeader( 'SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;rport=4321;maddr=x.com' ) with pytest.raises(ViaHeaderError): via.set_param(PARAM_RPORT, rport)
def test_set_received_error(rec_str): via = ViaHeader( 'SIP/2.0/TCP 192.168.1.1:5090;branch=branch_v;ttl=200;received=1.1.1.1;maddr=x.com' ) with pytest.raises(ViaHeaderError): via.set_param(PARAM_RECEIVED, rec_str)