示例#1
0
    async def test_receive_base_read_body_as_string_no_content_empty_string(
            self):
        sut = ReceiveResponse()
        sut.streams = []

        result = sut.read_body_as_str()

        self.assertEqual("", result)
    async def test_signal_response_returns_false_when_no_uuid(self):
        pending_requests: Dict[UUID, Future[ReceiveResponse]] = {}
        manager = RequestManager(pending_requests=pending_requests)
        request_id: UUID = uuid4()
        response = ReceiveResponse()
        signal = await manager.signal_response(request_id=request_id,
                                               response=response)

        self.assertFalse(signal)
    async def test_signal_response_response(self):
        pending_requests: Dict[UUID, Future[ReceiveResponse]] = {}
        request_id: UUID = uuid4()
        pending_requests[request_id] = Future()

        manager = RequestManager(pending_requests=pending_requests)
        response = ReceiveResponse()

        _ = await manager.signal_response(request_id=request_id,
                                          response=response)

        self.assertEqual(response, pending_requests[request_id].result())
    async def test_get_response_returns_response(self):
        pending_requests: Dict[UUID, Future[ReceiveResponse]] = {}
        request_id: UUID = uuid4()

        manager = RequestManager(pending_requests=pending_requests)
        test_response = ReceiveResponse()

        async def set_response():
            nonlocal manager
            nonlocal request_id
            nonlocal test_response

            while True:
                signal = await manager.signal_response(request_id,
                                                       response=test_response)
                if signal:
                    break
                await asyncio.sleep(2)

        ensure_future(set_response())
        response = await manager.get_response(request_id)

        self.assertEqual(test_response, response)
示例#5
0
    async def test_receive_response_none_properties(self):
        sut = ReceiveResponse()

        self.assertEqual(0, sut.status_code)
示例#6
0
    async def test_receive_response_empty_streams(self):
        sut = ReceiveResponse()

        self.assertIsNotNone(sut.streams)
        self.assertEqual(0, len(sut.streams))