def test_tuple_identifier(self): """ Tests we can create an AVP with a (vendor, code) tuple """ # This will resolve to the Username AVP self._compare_avp( avp.AVP((avp.VendorId.DEFAULT, 1), 'a username'), avp.UTF8StringAVP(1, value='a username', vendor=avp.VendorId.DEFAULT, flags=avp.FLAG_MANDATORY, name='User-Name')) self._compare_avp( avp.AVP((avp.VendorId.TGPP, 701), b'msisdn'), avp.OctetStringAVP(701, value=b'msisdn', vendor=avp.VendorId.TGPP, flags=avp.FLAG_MANDATORY | avp.FLAG_VENDOR, name='MSISDN')) # Unknown AVPs default to unknown AVP self._compare_avp( avp.AVP((0xfac3b00c, 1), b'wut'), avp.UnknownAVP(1, value=b'wut', vendor=0xfac3b00c, flags=0, name='Unknown-AVP'))
def test_octet_strings(self): """ Tests we can encode and decode octet strings """ self._compare_avp( avp.UnknownAVP(0, b'hello\x23'), memoryview(b'\x00\x00\x00\x00\x00\x00\x00\x0ehello#\x00\x00')) # Unicode strings won't load with self.assertRaises(CodecException): avp.OctetStringAVP(0, u'hello')