예제 #1
0
 async def test_on_new_message(self):
     await cli.on_new_message(
         cli.Message(
             body="Foo",
             content_type="text/plain",
             content_encoding="gzip",
             queue=asyncmock.Mock(),
         ))
예제 #2
0
    def test_receiver__config_not_found(self, monkeypatch, event_loop):
        mock_factories = asyncmock.Mock()
        mock_factories.get_receiver.side_effect = NotFound

        monkeypatch.setattr(cli, "factory", mock_factories)

        actual = cli.receiver("foo", loop=event_loop)

        assert actual == -1
        mock_factories.get_receiver.assert_called_with("foo")
예제 #3
0
    def test_send(self, monkeypatch, event_loop):
        mock_factories = asyncmock.Mock()
        mock_factories.get_sender.return_value = mock_sender = asyncmock.AsyncMock(
        )

        monkeypatch.setattr(cli, "factory", mock_factories)

        cli.send("foo", "bar", loop=event_loop)

        mock_factories.get_sender.assert_called_with("bar")
        mock_sender.send.assert_called_with(data="foo")
예제 #4
0
    def test_receiver(self, monkeypatch, event_loop):
        mock_factories = asyncmock.Mock()
        mock_factories.get_receiver.return_value = mock_receiver = asyncmock.AsyncMock(
        )
        mock_receiver.new_message.bind.not_async = True

        monkeypatch.setattr(cli, "factory", mock_factories)

        cli.receiver("foo", loop=event_loop)

        mock_factories.get_receiver.assert_called_with("foo")
        mock_receiver.listen.assert_called()
        mock_receiver.new_message.bind.assert_called_with(cli.on_new_message)
예제 #5
0
    def test_send__queue_not_found(self, monkeypatch, event_loop):
        mock_factories = asyncmock.Mock()
        mock_factories.get_sender.return_value = mock_sender = asyncmock.AsyncMock(
        )
        mock_sender.send.side_effect = QueueNotFound

        monkeypatch.setattr(cli, "factory", mock_factories)

        actual = cli.send("foo", "bar", loop=event_loop)

        assert actual == -2
        mock_factories.get_sender.assert_called_with("bar")
        mock_sender.send.assert_called_with(data="foo")
예제 #6
0
    def test_receiver__queue_not_found(self, monkeypatch, event_loop):
        mock_factories = asyncmock.Mock()
        mock_factories.get_receiver.return_value = mock_receiver = asyncmock.AsyncMock(
        )
        mock_receiver.listen.side_effect = QueueNotFound
        mock_receiver.new_message.bind.not_async = True

        monkeypatch.setattr(cli, "factory", mock_factories)

        actual = cli.receiver("foo", loop=event_loop)

        assert actual == -2
        mock_factories.get_receiver.assert_called_with("foo")
        mock_receiver.listen.assert_called()
예제 #7
0
    def test_configure(self, monkeypatch, event_loop):
        mock_factories = asyncmock.Mock()
        mock_factories.message_sender_factory.available = ["foo"]
        mock_factories.message_sender_factory.create.return_value = (
            mock_sender) = asyncmock.AsyncMock()
        mock_factories.message_receiver_factory.available = ["bar"]
        mock_factories.message_receiver_factory.create.return_value = (
            mock_receiver) = asyncmock.AsyncMock()

        monkeypatch.setattr(cli, "factory", mock_factories)

        cli.configure(loop=event_loop)

        mock_factories.message_sender_factory.create.assert_called_with("foo")
        mock_sender.configure.assert_called()
        mock_factories.message_receiver_factory.create.assert_called_with(
            "bar")
        mock_receiver.configure.assert_called()