Ejemplo n.º 1
0
    def test_the_pump_should_dispatch_a_command_processor(self):
        """
            Given that I have a message pump for a channel
             When I read a message from that channel
             Then the message should be dispatched to a handler
        """
        handler = MyCommandHandler()
        request = MyCommand()
        channel = Mock(spec=Channel)
        command_processor = Mock(spec=CommandProcessor)

        message_pump = MessagePump(command_processor, channel, map_to_message)

        header = BrightsideMessageHeader(uuid4(), request.__class__.__name__, BrightsideMessageType.command)
        body = BrightsideMessageBody(JsonRequestSerializer(request=request).serialize_to_json(),
                                     BrightsideMessageBodyType.application_json)
        message = BrightsideMessage(header, body)

        quit_message = BrightsideMessageFactory.create_quit_message()

        # add messages to that when channel is called it returns first message then qui tmessage
        response_queue = [message, quit_message]
        channel_spec = {"receive.side_effect" : response_queue}
        channel.configure_mock(**channel_spec)

        message_pump.run()

        channel_calls = [call.receive(), call.receive]
        channel.assert_has_calls(channel_calls)
        cp_calls = [call.send(request)]
        command_processor.assert_has_calls(cp_calls)
Ejemplo n.º 2
0
 def stop(self):
     self._queue.put(BrightsideMessageFactory.create_quit_message())
     self._state = ChannelState.stopping
Ejemplo n.º 3
0
 def stop(self):
     self._queue.put(BrightsideMessageFactory.create_quit_message())
     self._state = ChannelState.stopping