def test_qvalue(): alice_no_qvalue = ContactHeader("Alice <sip:[email protected]>") alice1 = ContactHeader("Alice <sip:[email protected]>;q=1.0") assert QValue('1.0') == alice1.get_qvalue() alice1.set_qvalue(QValue('0.1')) assert QValue('0.1') == alice1.get_qvalue() assert QValue('0.13') == alice_no_qvalue.get_qvalue(default=QValue('0.13'))
def add_to_contact_list(contact_list_string, accumulator): if contact_list_string.startswith(STAR): raise ContactHeaderListError( f'Cannot parse contact list {contact_list_string}: multiple contacts and ' f'star are invalid') try: contact = ContactHeader(contact_list_string) except Exception as e: raise ContactHeaderListError( f'Cannot parse contact list {contact_list_string}: {e}') accumulator.append(contact) if not contact.rest.lstrip(): return accumulator if contact.rest.startswith(','): ContactHeaderList.add_to_contact_list(contact.rest[1:], accumulator)
def test_set_param_error(name, value): alice = ContactHeader("Alice <sip:[email protected]>") with pytest.raises(ContactHeaderError): alice.set_param(name, value)
def test_set_param(): alice = ContactHeader("Alice <sip:[email protected]>") alice.set_param('expires', '30') assert alice.get_expires(None) == 30 alice.set_param('q', '0.1') assert alice.get_qvalue(None) == QValue('0.1') assert alice.get_expires(None) == 30 alice.set_param('myparam', 'Value') assert alice == ContactHeader( 'Alice <sip:[email protected]>;expires=30;q=0.1;myparam=Value') assert alice.get_param('MyParam') == 'Value'
def test_uri(): alice = ContactHeader('Alice <sip:[email protected]>') assert Uri('sip:[email protected]') == alice.uri
def test_expires(): alice = ContactHeader('Alice <sip:[email protected]>;expires=20') assert alice.get_expires() == 20 alice.set_expires(30) assert alice.get_expires() == 30 assert "Alice <sip:[email protected]>;expires=30" == alice.assemble() alice_no_expires = ContactHeader("Alice <sip:[email protected]>") assert alice_no_expires.get_expires() is None assert alice_no_expires.get_expires(21) == 21 alice45 = ContactHeader("Alice <sip:[email protected]>;Expires=45") assert alice45.get_expires() == 45
def test_parse_error(value): with pytest.raises(ContactHeaderError): ContactHeader(value)
def test_rebuild(value): contact = ContactHeader(value) rebuilt_contact = ContactHeader(contact.assemble()) assert contact == rebuilt_contact