forked from viamrobotics/viam-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_provisioning_client.py
80 lines (67 loc) · 2.9 KB
/
test_provisioning_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import pytest
from grpclib.testing import ChannelFor
from viam.app.provisioning_client import ProvisioningClient
from viam.proto.provisioning import GetSmartMachineStatusResponse, NetworkInfo, ProvisioningInfo, CloudConfig
from .mocks.services import MockProvisioning
ID = "id"
MODEL = "model"
MANUFACTURER = "acme"
PROVISIONING_INFO = ProvisioningInfo(fragment_id=ID, model=MODEL, manufacturer=MANUFACTURER)
HAS_CREDENTIALS = True
IS_ONLINE = True
NETWORK_TYPE = "type"
SSID = "ssid"
ERROR = "error"
ERRORS = [ERROR]
PSK = "psk"
SECRET = "secret"
APP_ADDRESS = "address"
NETWORK_INFO_LATEST = NetworkInfo(
type=NETWORK_TYPE,
ssid=SSID,
security="security",
signal=12,
connected=IS_ONLINE,
last_error=ERROR,
)
NETWORK_INFO = [NETWORK_INFO_LATEST]
SMART_MACHINE_STATUS_RESPONSE = GetSmartMachineStatusResponse(
provisioning_info=PROVISIONING_INFO,
has_smart_machine_credentials=HAS_CREDENTIALS,
is_online=IS_ONLINE,
latest_connection_attempt=NETWORK_INFO_LATEST,
errors=ERRORS
)
CLOUD_CONFIG = CloudConfig(id=ID, secret=SECRET, app_address=APP_ADDRESS)
AUTH_TOKEN = "auth_token"
PROVISIONING_SERVICE_METADATA = {"authorization": f"Bearer {AUTH_TOKEN}"}
@pytest.fixture(scope="function")
def service() -> MockProvisioning:
return MockProvisioning(smart_machine_status=SMART_MACHINE_STATUS_RESPONSE, network_info=NETWORK_INFO)
class TestClient:
@pytest.mark.asyncio
async def test_get_network_list(self, service: MockProvisioning):
async with ChannelFor([service]) as channel:
client = ProvisioningClient(channel, PROVISIONING_SERVICE_METADATA)
network_info = await client.get_network_list()
assert network_info == NETWORK_INFO
@pytest.mark.asyncio
async def test_get_smart_machine_status(self, service: MockProvisioning):
async with ChannelFor([service]) as channel:
client = ProvisioningClient(channel, PROVISIONING_SERVICE_METADATA)
smart_machine_status = await client.get_smart_machine_status()
assert smart_machine_status == SMART_MACHINE_STATUS_RESPONSE
@pytest.mark.asyncio
async def test_set_network_credentials(self, service: MockProvisioning):
async with ChannelFor([service]) as channel:
client = ProvisioningClient(channel, PROVISIONING_SERVICE_METADATA)
await client.set_network_credentials(network_type=NETWORK_TYPE, ssid=SSID, psk=PSK)
assert service.network_type == NETWORK_TYPE
assert service.ssid == SSID
assert service.psk == PSK
@pytest.mark.asyncio
async def test_set_smart_machine_credentials(self, service: MockProvisioning):
async with ChannelFor([service]) as channel:
client = ProvisioningClient(channel, PROVISIONING_SERVICE_METADATA)
await client.set_smart_machine_credentials(cloud_config=CLOUD_CONFIG)
assert service.cloud_config == CLOUD_CONFIG