Python aiohttp.test_utils.unused_port() Examples

The following are 10 code examples of aiohttp.test_utils.unused_port(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module aiohttp.test_utils , or try the search function .
Example #1
Source File: fake.py    From raven-aiohttp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, *, side_effect=None, loop):
        self.loop = loop

        if side_effect is None:
            side_effect = {
                'status': 200,
            }

        self._side_effect = side_effect
        self._slop_factor = 0

        self.app = web.Application(loop=loop)
        self.setup_routes()

        self.port = unused_port()

        self.hits = defaultdict(lambda: 0) 
Example #2
Source File: _server.py    From schemathesis with MIT License 5 votes vote down vote up
def run(target: Callable, port: Optional[int] = None, timeout: float = 0.05, **kwargs: Any) -> int:
    """Start a thread with the given aiohttp application."""
    if port is None:
        port = unused_port()
    server_thread = threading.Thread(target=target, kwargs={"port": port, **kwargs})
    server_thread.daemon = True
    server_thread.start()
    sleep(timeout)
    return port 
Example #3
Source File: test_utils.py    From aiosocks with Apache License 2.0 5 votes vote down vote up
def __init__(self, loop, write_buff):
        self._loop = loop
        self._write_buff = write_buff
        self._transports = []
        self._srv = None
        self.port = unused_port() 
Example #4
Source File: test_utils.py    From aiosocks with Apache License 2.0 5 votes vote down vote up
def __init__(self, loop):
        self._loop = loop
        self._transports = []
        self._futures = []
        self._srv = None
        self.port = unused_port() 
Example #5
Source File: test_ws_transport.py    From aries-cloudagent-python with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        self.message_results = []
        self.port = unused_port()
        self.session = None
        self.transport = WsTransport("0.0.0.0", self.port, self.create_session)
        self.transport.wire_format = JsonWireFormat()
        self.result_event = None
        super(TestWsTransport, self).setUp() 
Example #6
Source File: test_http_transport.py    From aries-cloudagent-python with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        self.message_results = []
        self.port = unused_port()
        self.session = None
        self.transport = HttpTransport(
            "0.0.0.0", self.port, self.create_session, max_message_size=65535
        )
        self.transport.wire_format = JsonWireFormat()
        self.result_event = None
        self.response_message = None
        super(TestHttpTransport, self).setUp() 
Example #7
Source File: test_cloudfare.py    From aiohttp-remotes with MIT License 5 votes vote down vote up
def start(self):
        port = unused_port()
        self.runner = web.AppRunner(self.app)
        await self.runner.setup()
        site = web.TCPSite(self.runner, '127.0.0.1', port,
                           ssl_context=self.ssl_context)
        await site.start()
        return {'www.cloudflare.com': port} 
Example #8
Source File: resources_aiotransmission.py    From stig with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        self.host = 'localhost'
        self.port = unused_port()
        self.app = web.Application()
        self.app.router.add_route(method='POST',
                                  path='/{path:.*}',
                                  handler=self.handle_POST)
        self.handler = None
        self.server = None
        self.response = None
        self.requests = []
        self.auth = None 
Example #9
Source File: fakeserver.py    From pubgate with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def start(self):
        self.port = port = unused_port()
        self.runner = web.AppRunner(self.app)
        await self.runner.setup()
        site = web.TCPSite(self.runner, '127.0.0.1', port)
        await site.start()
        return port 
Example #10
Source File: fake_hmip_server.py    From homematicip-rest-api with GNU General Public License v3.0 5 votes vote down vote up
def start(self):
        if self.port is None:
            self.port = unused_port()
        self.handler = self.app.make_handler()
        self.server = await self.loop.create_server(
            self.handler, "127.0.0.1", self.port, ssl=self.ssl_context
        )
        # return the base url and port which need to be resolved/mocked.
        resolver = FakeResolver({self.base_url: self.port}, loop=self.loop)
        connector = aiohttp.TCPConnector(
            loop=self.loop, resolver=resolver, verify_ssl=False
        )

        return connector