Skip to content

Commit e5e31b9

Browse files
authored
tests: add test case for delete operation
1 parent 716e946 commit e5e31b9

3 files changed

Lines changed: 43 additions & 35 deletions

File tree

tests/integration/path.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import gnmi.proto
2+
import gnmi.proto.legacy
3+
4+
5+
def create_legacy_path(path) -> gnmi.proto.legacy.Path:
6+
elements = [gnmi.proto.legacy.PathElem(name=e) for e in path.split("/")]
7+
return gnmi.proto.legacy.Path(elem=elements)
8+
9+
10+
def create_path(path) -> gnmi.proto.Path:
11+
elements = [gnmi.proto.PathElem(name=e) for e in path.split("/")]
12+
return gnmi.proto.Path(elem=elements)

tests/integration/test_integration_gnmi.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77

88
# noinspection SpellCheckingInspection
9+
from tests.integration.path import create_path
910
from tests.integration.validation import (
1011
validate_default_interfaces_get,
1112
validate_response_get,
@@ -46,16 +47,7 @@ async def test_integration_get(service):
4647

4748
async def test_integration_update_set_string(service):
4849
new_password = str(uuid.uuid4())
49-
path = gnmi.proto.Path(
50-
elem=[
51-
gnmi.proto.PathElem(name="system"),
52-
gnmi.proto.PathElem(name="aaa"),
53-
gnmi.proto.PathElem(name="authentication"),
54-
gnmi.proto.PathElem(name="admin-user"),
55-
gnmi.proto.PathElem(name="config"),
56-
gnmi.proto.PathElem(name="admin-password"),
57-
],
58-
)
50+
path = create_path("system/aaa/authentication/admin-user/config/admin-password")
5951
update = gnmi.proto.Update(
6052
path=path, val=gnmi.proto.TypedValue(string_val=new_password)
6153
)
@@ -68,9 +60,7 @@ async def test_integration_update_set_string(service):
6860

6961
async def test_integration_update_set_json(service):
7062
config = {"config": {"timezone-name": "Europe/Berlin"}}
71-
path = gnmi.proto.Path(
72-
elem=[gnmi.proto.PathElem(name="system"), gnmi.proto.PathElem(name="clock")],
73-
)
63+
path = create_path("system/clock")
7464
update = gnmi.proto.Update(
7565
path=path, val=gnmi.proto.TypedValue(json_ietf_val=json.dumps(config).encode())
7666
)
@@ -79,3 +69,12 @@ async def test_integration_update_set_json(service):
7969

8070
response = await service.get(path=path,)
8171
validate_response_get(response=response, value=config)
72+
73+
74+
async def test_integration_delete(service):
75+
path = create_path("system/clock/config/timezone-name")
76+
77+
await service.set(delete=[path])
78+
79+
response = await service.get(path=create_path("system/clock"),)
80+
validate_response_get(response=response, value={})

tests/integration/test_integration_legacy.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pytest
88
from grpc._channel import _InactiveRpcError # noqa
99

10+
from tests.integration.path import create_legacy_path
1011
from tests.integration.validation import (
1112
validate_default_interfaces_get,
1213
validate_response_get,
@@ -29,13 +30,7 @@ def test_integration_legacy_capabilities(service_legacy):
2930

3031
def test_integration__legacy_get(service_legacy, metadata_legacy):
3132
response = service_legacy.Get(
32-
gnmi.proto.legacy.GetRequest(
33-
path=[
34-
gnmi.proto.legacy.Path(
35-
elem=[gnmi.proto.legacy.PathElem(name="interfaces")]
36-
)
37-
],
38-
),
33+
gnmi.proto.legacy.GetRequest(path=[create_legacy_path("interfaces")],),
3934
metadata=metadata_legacy,
4035
)
4136

@@ -57,15 +52,8 @@ def _update(
5752

5853
def test_integration_legacy_update_set_string(service_legacy, metadata_legacy):
5954
new_password = str(uuid.uuid4())
60-
path = gnmi.proto.legacy.Path(
61-
elem=[
62-
gnmi.proto.legacy.PathElem(name="system"),
63-
gnmi.proto.legacy.PathElem(name="aaa"),
64-
gnmi.proto.legacy.PathElem(name="authentication"),
65-
gnmi.proto.legacy.PathElem(name="admin-user"),
66-
gnmi.proto.legacy.PathElem(name="config"),
67-
gnmi.proto.legacy.PathElem(name="admin-password"),
68-
],
55+
path = create_legacy_path(
56+
"system/aaa/authentication/admin-user/config/admin-password"
6957
)
7058
update = gnmi.proto.legacy.Update(
7159
path=path, val=gnmi.proto.legacy.TypedValue(string_val=new_password)
@@ -80,12 +68,7 @@ def test_integration_legacy_update_set_string(service_legacy, metadata_legacy):
8068

8169
def test_integration_legacy_update_set_json(service_legacy, metadata_legacy):
8270
config = {"config": {"timezone-name": "Europe/Berlin"}}
83-
path = gnmi.proto.legacy.Path(
84-
elem=[
85-
gnmi.proto.legacy.PathElem(name="system"),
86-
gnmi.proto.legacy.PathElem(name="clock"),
87-
],
88-
)
71+
path = create_legacy_path("system/clock")
8972
update = gnmi.proto.legacy.Update(
9073
path=path,
9174
val=gnmi.proto.legacy.TypedValue(json_ietf_val=json.dumps(config).encode()),
@@ -96,3 +79,17 @@ def test_integration_legacy_update_set_json(service_legacy, metadata_legacy):
9679
gnmi.proto.legacy.GetRequest(path=[path],), metadata=metadata_legacy,
9780
)
9881
validate_response_get(response=response, value=config)
82+
83+
84+
def test_integration_legacy_delete(service_legacy, metadata_legacy):
85+
path = create_legacy_path("system/clock/config/timezone-name")
86+
87+
service_legacy.Set(
88+
gnmi.proto.legacy.SetRequest(delete=[path]), metadata=metadata_legacy
89+
)
90+
91+
response = service_legacy.Get(
92+
gnmi.proto.legacy.GetRequest(path=[create_legacy_path("system/clock")],),
93+
metadata=metadata_legacy,
94+
)
95+
validate_response_get(response=response, value={})

0 commit comments

Comments
 (0)