veilid/veilid-python/tests/test_basic.py

61 lines
1.6 KiB
Python
Raw Normal View History

2023-06-15 20:22:54 -04:00
# Basic veilid tests
2023-06-14 16:33:14 -04:00
2023-06-17 14:34:09 -04:00
import socket
2024-03-02 11:32:08 -05:00
import json
import dataclasses
2023-06-17 14:34:09 -04:00
2023-06-14 16:33:14 -04:00
import pytest
2023-06-17 14:34:09 -04:00
import veilid
2023-06-17 14:37:39 -04:00
from .conftest import simple_update_callback
2023-06-14 16:33:14 -04:00
2023-06-17 14:34:09 -04:00
2023-06-14 16:33:14 -04:00
@pytest.mark.asyncio
2023-06-18 18:47:39 -04:00
async def test_connect(api_connection: veilid.VeilidAPI):
2023-06-17 14:34:09 -04:00
pass
2023-06-14 16:33:14 -04:00
2023-06-16 11:57:55 -04:00
@pytest.mark.asyncio
2023-06-18 18:47:39 -04:00
async def test_get_node_id(api_connection: veilid.VeilidAPI):
2023-06-17 14:34:09 -04:00
state = await api_connection.get_state()
node_ids = state.config.config.network.routing_table.node_id
assert len(node_ids) >= 1
for node_id in node_ids:
assert node_id[4] == ":"
2023-06-16 11:57:55 -04:00
2023-06-14 16:33:14 -04:00
@pytest.mark.asyncio
async def test_fail_connect():
2023-06-17 14:34:09 -04:00
with pytest.raises(socket.gaierror) as exc:
2023-07-22 13:06:46 -04:00
await veilid.json_api_connect("fuahwelifuh32luhwafluehawea", 1, simple_update_callback)
2023-06-17 14:34:09 -04:00
assert exc.value.errno == socket.EAI_NONAME
2023-06-14 16:33:14 -04:00
@pytest.mark.asyncio
2023-06-18 18:47:39 -04:00
async def test_version(api_connection: veilid.VeilidAPI):
2023-06-17 14:34:09 -04:00
v = await api_connection.veilid_version()
print(f"veilid_version: {v.__dict__}")
assert v.__dict__.keys() >= {"_major", "_minor", "_patch"}
2023-06-16 11:57:55 -04:00
2023-06-17 14:34:09 -04:00
vstr = await api_connection.veilid_version_string()
print(f"veilid_version_string: {vstr}")
2024-03-02 11:32:08 -05:00
@pytest.mark.asyncio
async def test_config(api_connection: veilid.VeilidAPI):
cfgstr = await api_connection.default_veilid_config()
print(f"default_veilid_config:\n{cfgstr}")
cfgjson = json.loads(cfgstr)
veilidConfigInstance = veilid.VeilidConfig(**cfgjson)
cfgstr2 = json.dumps(dataclasses.asdict(veilidConfigInstance))
cfgjson2 = json.loads(cfgstr2)
veilidConfigInstance2 = veilid.VeilidConfig(**cfgjson2)
assert veilidConfigInstance == veilidConfigInstance2