Пример #1
0
        def cb():
            def read():
                fut = asyncio.Future(loop=self._loop)
                with open(filename) as f:
                    fut.set_result(f.read().encode('utf-8'))
                return fut

            resp = ClientResponse('GET',
                                  yarl.URL(uri),
                                  writer=Mock(),
                                  timer=TimerNoop(),
                                  continue100=None,
                                  request_info=Mock(),
                                  traces=[],
                                  loop=self._loop,
                                  session=Mock())
            resp._headers = {'Content-Type': 'application/json'}

            resp.status = status
            resp.reason = Mock()
            resp.content = Mock()
            resp.content.read.side_effect = read
            resp.close = Mock()
            fut = asyncio.Future(loop=self._loop)
            fut.set_result(resp)
            return fut
Пример #2
0
        def cb():
            fut = asyncio.Future(loop=self._loop)
            resp = ClientResponse('GET',
                                  yarl.URL('foo'),
                                  writer=Mock(),
                                  timer=TimerNoop(),
                                  continue100=None,
                                  request_info=Mock(),
                                  traces=[],
                                  loop=self._loop,
                                  session=Mock())
            resp.status = status

            # setting this as aiohttp 3.5.4 is now checking if this value is not None
            # see aiohttp/client_reqrep.py:934
            resp.reason = http.client.responses[status]

            fut.set_result(resp)
            return fut