Ejemplo n.º 1
0
    async def test_drain_replies(self, *, c):
        an_account = Account(id="1", name="aName", active=False)
        responses = [
            ReqRepResponse(key="key1", value="value1", correlation_id="id1"),
            ReqRepResponse(key="key2", value="value2", correlation_id="id2"),
            ReqRepResponse.from_data(
                json.loads(
                    ReqRepResponse(key="key3",
                                   value=an_account,
                                   correlation_id="id3").dumps())),
        ]
        channel = Mock(
            stream=Mock(return_value=self._response_stream(responses)), )
        p1 = Mock()
        p2 = Mock()
        p3 = Mock()
        p4 = Mock()
        c._waiting["id1"] = {p1, p2}
        c._waiting["id2"] = {p3}
        c._waiting["id3"] = {p4}

        await c._drain_replies(channel)

        p1.fulfill.assert_called_once_with("id1", "value1")
        p2.fulfill.assert_called_once_with("id1", "value1")
        p3.fulfill.assert_called_once_with("id2", "value2")
        p4.fulfill.assert_called_once_with("id3", an_account)
Ejemplo n.º 2
0
    async def test_drain_replies(self, *, c):
        responses = [
            ReqRepResponse(key='key1', value='value1', correlation_id='id1'),
            ReqRepResponse(key='key2', value='value2', correlation_id='id2'),
        ]
        channel = Mock(
            stream=Mock(return_value=self._response_stream(responses)), )
        p1 = Mock()
        p2 = Mock()
        p3 = Mock()
        c._waiting['id1'] = {p1, p2}
        c._waiting['id2'] = {p3}

        await c._drain_replies(channel)

        p1.fulfill.assert_called_once_with('id1', 'value1')
        p2.fulfill.assert_called_once_with('id1', 'value1')
        p3.fulfill.assert_called_once_with('id2', 'value2')
Ejemplo n.º 3
0
    async def test_drain_replies(self, *, c):
        responses = [
            ReqRepResponse(key="key1", value="value1", correlation_id="id1"),
            ReqRepResponse(key="key2", value="value2", correlation_id="id2"),
        ]
        channel = Mock(
            stream=Mock(return_value=self._response_stream(responses)), )
        p1 = Mock()
        p2 = Mock()
        p3 = Mock()
        c._waiting["id1"] = {p1, p2}
        c._waiting["id2"] = {p3}

        await c._drain_replies(channel)

        p1.fulfill.assert_called_once_with("id1", "value1")
        p2.fulfill.assert_called_once_with("id1", "value1")
        p3.fulfill.assert_called_once_with("id2", "value2")
Ejemplo n.º 4
0
 async def test_reply(self, *, agent):
     agent.app = Mock(
         name='app',
         autospec=App,
         send=AsyncMock(),
     )
     req = ReqRepRequest('value', 'reply_to', 'correlation_id')
     await agent._reply('key', 'reply', req)
     agent.app.send.assert_called_once_with(
         req.reply_to,
         key=None,
         value=ReqRepResponse(
             key='key',
             value='reply',
             correlation_id=req.correlation_id,
         ),
     )
Ejemplo n.º 5
0
 async def test_reply(self, *, agent):
     agent.app = Mock(
         name="app",
         autospec=App,
         send=AsyncMock(),
     )
     req = ReqRepRequest("value", "reply_to", "correlation_id")
     await agent._reply("key", "reply", req.reply_to, req.correlation_id)
     agent.app.send.assert_called_once_with(
         req.reply_to,
         key=None,
         value=ReqRepResponse(
             key="key",
             value="reply",
             correlation_id=req.correlation_id,
         ),
     )