예제 #1
0
 def test_callback(self, aiohttp_session_mock):
     aiohttp_session_mock.request.return_value = [0]
     request = aiohttp_.Request(aiohttp_session_mock)
     request.add_callback(lambda x: 2)
     response = request.send(1, 2, {})
     assert inspect.isgenerator(response)
     assert list(response) == [0]
     try:
         next(response)
     except StopIteration as err:
         err.value == 2
     else:
         assert False
예제 #2
0
    def test_request_send(self, aiohttp_session_mock):
        # Setup
        import asyncio

        @asyncio.coroutine
        def request(*args, **kwargs):
            return 0

        aiohttp_session_mock.request = request
        client = aiohttp_.AiohttpClient(aiohttp_session_mock)
        request = aiohttp_.Request(client)

        # Run
        response = request.send(1, 2, {})
        loop = asyncio.get_event_loop()
        value = loop.run_until_complete(asyncio.ensure_future(response))

        # Verify
        assert value == 0
예제 #3
0
    def test_callback(self, aiohttp_session_mock):
        # Setup
        import asyncio

        @asyncio.coroutine
        def request(*args, **kwargs):
            return 2

        aiohttp_session_mock.request = request
        client = aiohttp_.AiohttpClient(aiohttp_session_mock)
        client._sync_callback_adapter = asyncio.coroutine
        request = aiohttp_.Request(client)

        # Run
        request.add_callback(lambda x: 2)
        response = request.send(1, 2, {})
        loop = asyncio.get_event_loop()
        value = loop.run_until_complete(asyncio.ensure_future(response))

        # Verify
        assert value == 2
예제 #4
0
 def test_request_send(self, aiohttp_session_mock):
     aiohttp_session_mock.request.return_value = [0]
     request = aiohttp_.Request(aiohttp_session_mock)
     response = request.send(1, 2, {})
     assert inspect.isgenerator(response)
     assert list(response) == [0]