def test_str(self): # Test both branches but don't assert the actual content because its # not worth it frame = ContentFrame(42, 'payload') str(frame) frame = ContentFrame(42, 8675309) str(frame)
def test_write_frame(self): w = mock() expect( mock(content_frame, 'Writer') ).args('buffer').returns( w ) expect( w.write_octet ).args( 3 ).returns( w ) expect( w.write_short ).args( 42 ).returns( w ) expect( w.write_long ).args( 5 ).returns( w ) expect( w.write ).args( 'hello' ).returns( w ) expect( w.write_octet ).args( 0xce ) frame = ContentFrame(42, 'hello') frame.write_frame( 'buffer' )
def test_create_frames(self): itr = ContentFrame.create_frames(42, 'helloworld', 13) frame = itr.next() assert_true( isinstance(frame, ContentFrame) ) assert_equals( 42, frame.channel_id ) assert_equals( 'hello', frame.payload ) frame = itr.next() assert_true( isinstance(frame, ContentFrame) ) assert_equals( 42, frame.channel_id ) assert_equals( 'world', frame.payload ) assert_raises(StopIteration, itr.next)
def publish(self, msg, exchange, routing_key, mandatory=False, immediate=False, ticket=None): ''' publish a message. ''' args = Writer() args.write_short(ticket or self.default_ticket).\ write_shortstr(exchange).\ write_shortstr(routing_key).\ write_bits(mandatory, immediate) self.send_frame( MethodFrame(self.channel_id, 60, 40, args) ) self.send_frame( HeaderFrame(self.channel_id, 60, 0, len(msg), msg.properties) ) frame_max = self.channel.connection.frame_max for frame in ContentFrame.create_frames(self.channel_id, msg.body, frame_max): self.send_frame( frame )
def test_init(self): expect(Frame.__init__).args( is_a(ContentFrame), 42 ) frame = ContentFrame(42, 'payload') assert_equals( 'payload', frame._payload )
def test_parse(self): frame = ContentFrame.parse(42, 'payload') assert_true( isinstance(frame, ContentFrame) ) assert_equals( 42, frame.channel_id ) assert_equals( 'payload', frame.payload )
def test_payload(self): klass = ContentFrame(42, 'payload') assert_equals( 'payload', klass.payload )
def test_type(self): assert_equals(3, ContentFrame.type() )