Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose app property for TestClient #2901

Merged
merged 9 commits into from
Apr 2, 2018
1 change: 1 addition & 0 deletions CHANGES/2891.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
expose property `app` for TestClient
4 changes: 4 additions & 0 deletions aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ def port(self):
def server(self):
return self._server

@property
def app(self):
return getattr(self._server, "app", None)

@property
def session(self):
"""An internal aiohttp.ClientSession.
Expand Down
21 changes: 13 additions & 8 deletions docs/client_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ The client session supports the context manager protocol for self closing.
autoping=True,\
heartbeat=None,\
origin=None, \
headers=None, \
proxy=None, proxy_auth=None, ssl=None, \
verify_ssl=None, fingerprint=None, \
ssl_context=None, proxy_headers=None, \
Expand All @@ -500,18 +501,22 @@ The client session supports the context manager protocol for self closing.

:param bool autoclose: Automatically close websocket connection on close
message from server. If *autoclose* is False
them close procedure has to be handled manually
them close procedure has to be handled manually.
``True`` by default

:param bool autoping: automatically send *pong* on *ping*
message from server
message from server. ``True`` by default

:param float heartbeat: Send *ping* message every *heartbeat*
seconds and wait *pong* response, if
*pong* response is not received then
close connection. The timer is reset on any data
reception.
reception.(optional)

:param str origin: Origin header to send to server
:param str origin: Origin header to send to server(optional)

:param dict headers: HTTP Headers to send with
the request (optional)

:param str proxy: Proxy URL, :class:`str` or :class:`~yarl.URL` (optional)

Expand Down Expand Up @@ -560,16 +565,16 @@ The client session supports the context manager protocol for self closing.
authority channel, supported SSL options etc.

.. versionadded:: 2.3

.. deprecated:: 3.0

Use ``ssl=ssl_context``

:param dict proxy_headers: HTTP headers to send to the proxy if the
parameter proxy has been provided.

.. versionadded:: 2.3

.. deprecated:: 3.0

Use ``ssl=ssl_context``

:param int compress: Enable Per-Message Compress Extension support.
0 for disable, 9 to 15 for window bit support.
Default value is 0.
Expand Down
6 changes: 6 additions & 0 deletions docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,12 @@ Test Client
:class:`BaseTestServer` test server instance used in conjunction
with client.

.. attribute:: app

An alias for :attr:`self.server.app`. return ``None`` if
``self.server`` is not :class:`TestServer`
instance(e.g. :class:`RawTestServer` instance for test low-level server).

.. attribute:: session

An internal :class:`aiohttp.ClientSession`.
Expand Down
18 changes: 18 additions & 0 deletions tests/test_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import aiohttp
from aiohttp import web
from aiohttp.test_utils import AioHTTPTestCase
from aiohttp.test_utils import RawTestServer as _RawTestServer
from aiohttp.test_utils import TestClient as _TestClient
from aiohttp.test_utils import TestServer as _TestServer
from aiohttp.test_utils import (loop_context, make_mocked_request,
Expand Down Expand Up @@ -214,6 +215,23 @@ async def test_test_client_props(loop):
async with client:
assert isinstance(client.port, int)
assert client.server is not None
assert client.app is not None
assert client.port is None


async def test_test_client_raw_server_props(loop):

async def hello(request):
return web.Response(body=_hello_world_bytes)

client = _TestClient(_RawTestServer(hello, host='127.0.0.1', loop=loop),
loop=loop)
assert client.host == '127.0.0.1'
assert client.port is None
async with client:
assert isinstance(client.port, int)
assert client.server is not None
assert client.app is None
assert client.port is None


Expand Down