test/api: split client connector from server

Add a connect_server() that is a drop-in replacement for start_server(),
which allows failing tests to be converted into something to connect to
an already running server instance with a single line change.
Useful for setting a breakpoint in the server against the test.
This commit is contained in:
Dan Bungert 2021-10-07 11:33:14 -06:00
parent 8bcb6b79b3
commit 3ce9e193cc
1 changed files with 10 additions and 1 deletions

View File

@ -41,7 +41,7 @@ def json_print(json_data):
print(json.dumps(json_data, indent=4))
class Server:
class Client:
def __init__(self, session):
self.session = session
@ -85,6 +85,8 @@ class Server:
await asyncio.sleep(.5)
raise Exception('timeout on server startup')
class Server(Client):
async def server_shutdown(self, immediate=True):
try:
await self.post('/shutdown', mode='POWEROFF', immediate=immediate)
@ -127,6 +129,13 @@ async def start_server(*args, **kwargs):
await server.close()
@contextlib.asynccontextmanager
async def connect_server(*args, **kwargs):
conn = aiohttp.UnixConnector(path=socket_path)
async with aiohttp.ClientSession(connector=conn) as session:
yield Client(session)
class TestBitlocker(TestAPI):
@timeout(5)
async def test_has_bitlocker(self):