def when_BasicGetOK_arrives_with_content(self): method = spec.BasicGetOK(123, False, 'my.exchange', 'routing.key', 0) self.server.send_method(self.channel.id, method) header = message.get_header_payload(self.expected_message, spec.BasicGet.method_type[0]) self.server.send_frame(frames.ContentHeaderFrame(self.channel.id, header)) body = message.get_frame_payloads(self.expected_message, 100)[0] self.server.send_frame(frames.ContentBodyFrame(self.channel.id, body)) self.tick()
def deliver_msg(self): method = spec.BasicDeliver(self.consumer.tag, 123, False, 'my.exchange', 'routing.key') self.server.send_method(self.channel.id, method) header = message.get_header_payload(self.expected_message, spec.BasicGet.method_type[0]) self.server.send_frame(frames.ContentHeaderFrame(self.channel.id, header)) body = message.get_frame_payloads(self.expected_message, 100)[0] self.server.send_frame(frames.ContentBodyFrame(self.channel.id, body)) self.tick()
def return_msg(self): method = spec.BasicReturn(123, "you messed up", "the.exchange", "the.routing.key") self.server.send_frame(frames.MethodFrame(self.channel.id, method)) header = message.get_header_payload(self.expected_message, spec.BasicGet.method_type[0]) self.server.send_frame(frames.ContentHeaderFrame(self.channel.id, header)) body = message.get_frame_payloads(self.expected_message, 100)[0] self.server.send_frame(frames.ContentBodyFrame(self.channel.id, body)) self.tick()
def given_a_content_header_frame(self): self.raw = ( b'\x02\x00\x01\x00\x00\x00\x25' # regular frame header b'\x00\x32\x00\x00' # class id 50; weight is always 0 b'\x00\x00\x00\x00\x00\x00\x00\x64' # body length 100 b'\xA0\x00' # property_flags 0b1010000000000000 b'\x03yes\x00\x00\x00\x0F\x04someS\x00\x00\x00\x05value' # property list b'\xCE') expected_payload = message.ContentHeaderPayload(50, 100, [ amqptypes.ShortStr('yes'), None, amqptypes.Table({'some': 'value'}), None, None, None, None, None, None, None, None, None, None]) self.expected_frame = frames.ContentHeaderFrame(1, expected_payload)
def it_should_send_a_BasicPublish_method_followed_by_a_header_and_the_body( self): expected_method = spec.BasicPublish(0, self.exchange.name, 'routing.key', True, False) header_payload = message.ContentHeaderPayload(60, 4, [ 'application/json', 'utf-8', {}, 2, 5, self.correlation_id, 'me', 'tomorrow', self.message_id, self.timestamp, 'telegram', 'benjamin', 'asynqptests' ]) expected_header = frames.ContentHeaderFrame(self.channel.id, header_payload) expected_body = frames.ContentBodyFrame(self.channel.id, b'body') self.server.should_have_received_frames([ frames.MethodFrame(self.channel.id, expected_method), expected_header, expected_body ], any_order=False)
def given_I_received_a_message(self): self.delivery_tag = 12487 msg = asynqp.Message('body', timestamp=datetime(2014, 5, 5)) task = asyncio.async(self.queue.get()) self.tick() method = spec.BasicGetOK(self.delivery_tag, False, 'my.exchange', 'routing.key', 0) self.server.send_method(self.channel.id, method) header = message.get_header_payload(msg, spec.BasicGet.method_type[0]) self.server.send_frame(frames.ContentHeaderFrame(self.channel.id, header)) body = message.get_frame_payloads(msg, 100)[0] self.server.send_frame(frames.ContentBodyFrame(self.channel.id, body)) self.tick() self.msg = task.result()
def given_a_content_header_frame(self): payload = message.ContentHeaderPayload(50, 100, [amqptypes.Octet(3), None, amqptypes.Table({'some': 'value'})]) self.frame = frames.ContentHeaderFrame(1, payload)