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_process_frames_drops_non_close_methods_when_emergency_closing( self): c = Channel(mock(), None, self._CLASS_MAP) c._emergency_close_pending = True c._connection = mock() c._connection.logger = mock() f0 = MethodFrame(1, 30, 40) f1 = HeaderFrame(1, 30, 0, 0) f2 = ContentFrame(1, "payload") f3_basic_close = MethodFrame(1, 20, 40) f4_basic_close_ok = MethodFrame(1, 20, 41) f5 = MethodFrame(1, 90, 11) c._frame_buffer = deque( [f0, f1, f2, f3_basic_close, f4_basic_close_ok, f5]) expect(c.dispatch).args(f0).times(0) expect(c.dispatch).args(f1).times(0) expect(c.dispatch).args(f2).times(0) expect(c.dispatch).args(f3_basic_close).times(1) expect(c.dispatch).args(f4_basic_close_ok).times(1) expect(c.dispatch).args(f5).times(0) expect(c.logger.warn).times(4) c.process_frames() assert_equals(0, len(c._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 test_send_frame_when_not_closed_and_flow_control(self): conn = mock() c = Channel(conn, 32, {}) c._active = False method = MethodFrame(1, 2, 3) heartbeat = HeartbeatFrame() header = HeaderFrame(1, 2, 3, 4) content = ContentFrame(1, 'foo') expect(conn.send_frame).args(method) expect(conn.send_frame).args(heartbeat) c.send_frame(method) c.send_frame(heartbeat) assert_raises(Channel.Inactive, c.send_frame, header) assert_raises(Channel.Inactive, c.send_frame, content)
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)) f_max = self.channel.connection.frame_max for f in ContentFrame.create_frames(self.channel_id, msg.body, f_max): self.send_frame(f)
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())