|
| 1 | +import pytest |
| 2 | +import os |
| 3 | +from xpipe_client.clients import Client, AsyncClient |
| 4 | + |
| 5 | + |
| 6 | +@pytest.fixture |
| 7 | +def sync_local_client(): |
| 8 | + return Client() |
| 9 | + |
| 10 | + |
| 11 | +@pytest.fixture |
| 12 | +async def async_local_client(): |
| 13 | + async with AsyncClient() as async_client: |
| 14 | + yield async_client |
| 15 | + |
| 16 | + |
| 17 | +def test_sync_local_login(sync_local_client: Client): |
| 18 | + assert sync_local_client.session is None |
| 19 | + sync_local_client.renew_session() |
| 20 | + assert sync_local_client.session is not None |
| 21 | + |
| 22 | + |
| 23 | +async def test_async_local_login(async_local_client: AsyncClient): |
| 24 | + assert async_local_client.session is None |
| 25 | + await async_local_client.renew_session() |
| 26 | + assert async_local_client.session is not None |
| 27 | + |
| 28 | + |
| 29 | +def test_sync_apikey_login(): |
| 30 | + apikey = os.environ.get("XPIPE_APIKEY", None) |
| 31 | + assert apikey is not None |
| 32 | + client = Client(token=apikey) |
| 33 | + assert client.session is None |
| 34 | + client.renew_session() |
| 35 | + assert client.session is not None |
| 36 | + |
| 37 | + |
| 38 | +async def test_async_apikey_login(): |
| 39 | + apikey = os.environ.get("XPIPE_APIKEY", None) |
| 40 | + assert apikey is not None |
| 41 | + client = AsyncClient(token=apikey) |
| 42 | + assert client.session is None |
| 43 | + await client.renew_session() |
| 44 | + assert client.session is not None |
| 45 | + |
| 46 | + |
| 47 | +def test_connection_query(sync_local_client: Client): |
| 48 | + connections = sync_local_client.connection_query(connections="") |
| 49 | + assert len(connections) > 0 |
| 50 | + assert connections[0].get("connection", None) is not None |
| 51 | + |
| 52 | + |
| 53 | +async def test_async_connection_query(async_local_client: AsyncClient): |
| 54 | + connections = await async_local_client.connection_query(connections="") |
| 55 | + assert len(connections) > 0 |
| 56 | + assert connections[0].get("connection", None) is not None |
| 57 | + |
| 58 | + |
| 59 | +def test_shell_start(sync_local_client: Client): |
| 60 | + local_connection = sync_local_client.connection_query(connections="")[0]["connection"] |
| 61 | + sync_local_client.shell_start(local_connection) |
| 62 | + |
| 63 | + |
| 64 | +async def test_async_shell_start(async_local_client: AsyncClient): |
| 65 | + connections = await async_local_client.connection_query(connections="") |
| 66 | + local_connection = connections[0]["connection"] |
| 67 | + await async_local_client.shell_start(local_connection) |
| 68 | + |
| 69 | + |
| 70 | +def test_shell_stop(sync_local_client: Client): |
| 71 | + local_connection = sync_local_client.connection_query(connections="")[0]["connection"] |
| 72 | + sync_local_client.shell_start(local_connection) |
| 73 | + sync_local_client.shell_stop(local_connection) |
| 74 | + |
| 75 | + |
| 76 | +async def test_async_shell_stop(async_local_client: AsyncClient): |
| 77 | + connections = await async_local_client.connection_query(connections="") |
| 78 | + local_connection = connections[0]["connection"] |
| 79 | + await async_local_client.shell_start(local_connection) |
| 80 | + await async_local_client.shell_stop(local_connection) |
| 81 | + |
| 82 | + |
| 83 | +def test_shell_exec(sync_local_client: Client): |
| 84 | + local_connection = sync_local_client.connection_query(connections="")[0]["connection"] |
| 85 | + sync_local_client.shell_start(local_connection) |
| 86 | + retval = sync_local_client.shell_exec(local_connection, "echo hello world") |
| 87 | + assert retval == {'exitCode': 0, "stdout": "hello world", "stderr": ""} |
| 88 | + sync_local_client.shell_stop(local_connection) |
| 89 | + |
| 90 | + |
| 91 | +async def test_async_shell_exec(async_local_client: AsyncClient): |
| 92 | + local_connection = (await async_local_client.connection_query(connections=""))[0]["connection"] |
| 93 | + await async_local_client.shell_start(local_connection) |
| 94 | + retval = await async_local_client.shell_exec(local_connection, "echo hello world") |
| 95 | + assert retval == {'exitCode': 0, "stdout": "hello world", "stderr": ""} |
| 96 | + await async_local_client.shell_stop(local_connection) |
0 commit comments