示例#1
0
 async def make_conn():
     return BaseConnector(loop=loop)
示例#2
0
def connector(loop):
    conn = BaseConnector(loop=loop)
    proto = mock.Mock()
    conn._conns['a'] = [(proto, 123)]
    yield conn
    conn.close()
示例#3
0
def connector(loop):
    conn = BaseConnector(loop=loop)
    transp = mock.Mock()
    conn._conns['a'] = [(transp, 'proto', 123)]
    return conn
示例#4
0
 def setUp(self):
     self.loop = asyncio.new_event_loop()
     asyncio.set_event_loop(None)
     self.connector = BaseConnector(loop=self.loop)
     self.transport = mock.Mock()
     self.protocol = mock.Mock()
def connector(loop):
    conn = BaseConnector(loop=loop)
    transp = mock.Mock()
    conn._conns["a"] = [(transp, "proto", 123)]
    return conn
示例#6
0
 def make_open_connector(self):
     conn = BaseConnector(loop=self.loop)
     transp = unittest.mock.Mock()
     conn._conns['a'] = [(transp, 'proto', 123)]
     return conn
示例#7
0
class TestCLientRequest(unittest.TestCase):

    def setUp(self):
        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(None)
        self.connector = BaseConnector(loop=self.loop)
        self.transport = mock.Mock()
        self.protocol = mock.Mock()

    def tearDown(self):
        self.connector.close()
        self.loop.stop()
        self.loop.run_forever()
        self.loop.close()

    def test_custom_req_rep(self):
        @asyncio.coroutine
        def go():
            conn = None

            class CustomResponse(ClientResponse):
                @asyncio.coroutine
                def start(self, connection, read_until_eof=False):
                    nonlocal conn
                    conn = connection
                    self.status = 123
                    self.reason = 'Test OK'
                    self.headers = CIMultiDictProxy(CIMultiDict())
                    self.cookies = SimpleCookie()
                    return

            called = False

            class CustomRequest(ClientRequest):

                def send(self, writer, reader):
                    resp = self.response_class(self.method,
                                               self.url,
                                               self.host,
                                               writer=self._writer,
                                               continue100=self._continue)
                    resp._post_init(self.loop)
                    self.response = resp
                    nonlocal called
                    called = True
                    return resp

            @asyncio.coroutine
            def create_connection(req):
                self.assertIsInstance(req, CustomRequest)
                return self.transport, self.protocol
            self.connector._create_connection = create_connection

            resp = yield from aiohttp.request('get',
                                              'http://example.com/path/to',
                                              request_class=CustomRequest,
                                              response_class=CustomResponse,
                                              connector=self.connector,
                                              loop=self.loop)
            self.assertIsInstance(resp, CustomResponse)
            self.assertTrue(called)
            resp.close()
            conn.close()

        self.loop.run_until_complete(go())
示例#8
0
def connector(loop):
    conn = BaseConnector(loop=loop)
    transp = mock.Mock()
    conn._conns['a'] = [(transp, 'proto', 123)]
    return conn
示例#9
0
def connector(loop):
    conn = BaseConnector(loop=loop)
    proto = mock.Mock()
    conn._conns['a'] = [(proto, 123)]
    return conn
示例#10
0
def connector(loop):
    conn = BaseConnector(loop=loop)
    proto = mock.Mock()
    conn._conns['a'] = [(proto, 123)]
    yield conn
    conn.close()
 def make_open_connector(self):
     conn = BaseConnector(loop=self.loop)
     transp = unittest.mock.Mock()
     conn._conns['a'] = [(transp, 'proto', 123)]
     return conn
示例#12
0
 def setUp(self):
     self.loop = asyncio.new_event_loop()
     asyncio.set_event_loop(None)
     self.connector = BaseConnector(loop=self.loop)
     self.transport = mock.Mock()
     self.protocol = mock.Mock()
示例#13
0
def function647(arg2195):
    var3554 = BaseConnector(loop=arg2195)
    var1840 = mock.Mock()
    var3554._conns['a'] = [(var1840, 123)]
    return var3554
示例#14
0
def connector(loop):
    conn = BaseConnector(loop=loop)
    proto = mock.Mock()
    conn._conns['a'] = [(proto, 123)]
    return conn