Beispiel #1
0
    async def test_batch_full_response_call(self):
        bp = rpc.JsonBatchProxy(self.uri,
                                timeout=self.rpc_timeout,
                                full_response=True)

        bp.ping()
        bp.ping()
        bp.ping()
        self.assertEqual(len(bp), 3)

        response = await bp()
        self.assertIsInstance(response, http.HttpResponse)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(bp), 0)
Beispiel #2
0
    async def test_batch_error_response_call(self):
        bp = rpc.JsonBatchProxy(self.uri, timeout=self.rpc_timeout)

        call_id1 = bp.ping('wrong param')
        self.assertIsNotNone(call_id1)
        self.assertEqual(len(bp), 1)

        batch_generator = await bp()
        self.assertIsInstance(batch_generator, types.GeneratorType)
        self.assertEqual(len(bp), 0)

        for ind, batch_response in enumerate(batch_generator):
            self.assertEqual(ind, 0)
            self.assertEqual(call_id1, batch_response.id)
            self.assertIsInstance(batch_response.exception, rpc.InvalidParams)
            self.assertIsNone(batch_response.result)
Beispiel #3
0
    def test_batch_one_call(self):
        bp = rpc.JsonBatchProxy(self.uri, timeout=self.rpc_timeout)

        call_id1 = bp.ping()
        self.assertIsNotNone(call_id1)
        self.assertEqual(len(bp), 1)

        batch_generator = yield from bp
        self.assertIsInstance(batch_generator, types.GeneratorType)
        self.assertEqual(len(bp), 0)

        for ind, batch_response in enumerate(batch_generator):
            self.assertEqual(ind, 0)
            self.assertEqual(call_id1, batch_response.id)
            self.assertEqual(batch_response.result, 'pong')
            self.assertIsNone(batch_response.exception)
Beispiel #4
0
    async def test_batch_few_call(self):
        bp = rpc.JsonBatchProxy(self.uri, timeout=self.rpc_timeout)

        call_id1 = bp.ping()
        self.assertIsNotNone(call_id1)
        self.assertEqual(len(bp), 1)

        call_id2 = bp.calc.add(1, 1)
        self.assertIsNotNone(call_id2)
        self.assertEqual(len(bp), 2)

        batch_generator = await bp()
        self.assertIsInstance(batch_generator, types.GeneratorType)
        self.assertEqual(len(bp), 0)

        for ind, batch_response in enumerate(batch_generator):
            self.assertIn(ind, (0, 1))
            if call_id1 == batch_response.id:
                self.assertEqual(batch_response.result, 'pong')
                self.assertIsNone(batch_response.exception)
            elif call_id2 == batch_response.id:
                self.assertEqual(batch_response.result, 2)
                self.assertIsNone(batch_response.exception)