-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathtest_gnmi_plugin.py
More file actions
50 lines (45 loc) · 1.55 KB
/
test_gnmi_plugin.py
File metadata and controls
50 lines (45 loc) · 1.55 KB
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
import sys
from pathlib import Path
import pytest
plugin_src = Path(__file__).parent.parent / "src"
sys.path.insert(0, str(plugin_src))
core_src = Path(__file__).parent.parent.parent.parent.parent / "core" / "src"
sys.path.insert(0, str(core_src))
from utcp.utcp_client import UtcpClient
from utcp_gnmi import register
@pytest.mark.asyncio
async def test_register_manual_and_tools():
register()
client = await UtcpClient.create(config={
"manual_call_templates": [
{
"name": "routerA",
"call_template_type": "gnmi",
"target": "localhost:50051",
"use_tls": False,
"operation": "get"
}
]
})
tools = await client.config.tool_repository.get_tools()
names = [t.name for t in tools]
assert any(n.startswith("routerA.") for n in names)
assert any(n.endswith("subscribe") for n in names)
def test_serializer_roundtrip():
from utcp_gnmi.gnmi_call_template import GnmiCallTemplateSerializer
serializer = GnmiCallTemplateSerializer()
data = {
"name": "routerB",
"call_template_type": "gnmi",
"target": "localhost:50051",
"use_tls": False,
"metadata": {"authorization": "Bearer token"},
"metadata_fields": ["tenant-id"],
"operation": "set",
"stub_module": "gnmi_pb2_grpc",
"message_module": "gnmi_pb2"
}
obj = serializer.validate_dict(data)
out = serializer.to_dict(obj)
assert out["call_template_type"] == "gnmi"
assert out["operation"] == "set"