'Test encoding and decoding of an introduction request'

def test_encode_decode_intro_request(self):

    message = MockObject()
    meta_msg = self.market_community.get_meta_message(u'dispersy-introduction-request')
    bloomfilter = BloomFilter(0.005, 30, prefix='    ')
    intro_payload = MarketIntroPayload.Implementation(meta_msg, ('127.0.0.1', 1324), ('127.0.0.1', 1234), ('127.0.0.1', 1234), True, u'public', None, 3, bloomfilter)
    message.payload = intro_payload
    packet_str = ''.join(self.conversion._encode_introduction_request(message))
    self.assertTrue(packet_str)
    placeholder = self.get_placeholder_msg(u'dispersy-introduction-request')
    (_, decoded) = self.conversion._decode_introduction_request(placeholder, 0, packet_str)
    self.assertTrue(decoded)
    self.assertRaises(DropPacket, self.conversion._decode_introduction_request, placeholder, 0, 'abc')
    self.assertRaises(DropPacket, self.conversion._decode_introduction_request, placeholder, 0, (packet_str + 'b'))
    intro_payload = MarketIntroPayload.Implementation(meta_msg, ('127.0.0.1', 1324), ('127.0.0.1', 1234), ('127.0.0.1', 1234), True, u'public', None, 3, None)
    message.payload = intro_payload
    packet_str = ''.join(self.conversion._encode_introduction_request(message))
    self.assertRaises(DropPacket, self.conversion._decode_introduction_request, placeholder, 0, (packet_str + 'a'))
    bf_encoding = (pack('!BH', 3, 0) + 'aa')
    self.assertRaises(DropPacket, self.conversion._decode_introduction_request, placeholder, 0, (packet_str + bf_encoding))
