Skip to content

Commit

Permalink
tests: add test case for delete operation
Browse files Browse the repository at this point in the history
  • Loading branch information
TribuneX authored Aug 7, 2020
1 parent 716e946 commit e5e31b9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 35 deletions.
12 changes: 12 additions & 0 deletions tests/integration/path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import gnmi.proto
import gnmi.proto.legacy


def create_legacy_path(path) -> gnmi.proto.legacy.Path:
elements = [gnmi.proto.legacy.PathElem(name=e) for e in path.split("/")]
return gnmi.proto.legacy.Path(elem=elements)


def create_path(path) -> gnmi.proto.Path:
elements = [gnmi.proto.PathElem(name=e) for e in path.split("/")]
return gnmi.proto.Path(elem=elements)
25 changes: 12 additions & 13 deletions tests/integration/test_integration_gnmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest

# noinspection SpellCheckingInspection
from tests.integration.path import create_path
from tests.integration.validation import (
validate_default_interfaces_get,
validate_response_get,
Expand Down Expand Up @@ -46,16 +47,7 @@ async def test_integration_get(service):

async def test_integration_update_set_string(service):
new_password = str(uuid.uuid4())
path = gnmi.proto.Path(
elem=[
gnmi.proto.PathElem(name="system"),
gnmi.proto.PathElem(name="aaa"),
gnmi.proto.PathElem(name="authentication"),
gnmi.proto.PathElem(name="admin-user"),
gnmi.proto.PathElem(name="config"),
gnmi.proto.PathElem(name="admin-password"),
],
)
path = create_path("system/aaa/authentication/admin-user/config/admin-password")
update = gnmi.proto.Update(
path=path, val=gnmi.proto.TypedValue(string_val=new_password)
)
Expand All @@ -68,9 +60,7 @@ async def test_integration_update_set_string(service):

async def test_integration_update_set_json(service):
config = {"config": {"timezone-name": "Europe/Berlin"}}
path = gnmi.proto.Path(
elem=[gnmi.proto.PathElem(name="system"), gnmi.proto.PathElem(name="clock")],
)
path = create_path("system/clock")
update = gnmi.proto.Update(
path=path, val=gnmi.proto.TypedValue(json_ietf_val=json.dumps(config).encode())
)
Expand All @@ -79,3 +69,12 @@ async def test_integration_update_set_json(service):

response = await service.get(path=path,)
validate_response_get(response=response, value=config)


async def test_integration_delete(service):
path = create_path("system/clock/config/timezone-name")

await service.set(delete=[path])

response = await service.get(path=create_path("system/clock"),)
validate_response_get(response=response, value={})
41 changes: 19 additions & 22 deletions tests/integration/test_integration_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest
from grpc._channel import _InactiveRpcError # noqa

from tests.integration.path import create_legacy_path
from tests.integration.validation import (
validate_default_interfaces_get,
validate_response_get,
Expand All @@ -29,13 +30,7 @@ def test_integration_legacy_capabilities(service_legacy):

def test_integration__legacy_get(service_legacy, metadata_legacy):
response = service_legacy.Get(
gnmi.proto.legacy.GetRequest(
path=[
gnmi.proto.legacy.Path(
elem=[gnmi.proto.legacy.PathElem(name="interfaces")]
)
],
),
gnmi.proto.legacy.GetRequest(path=[create_legacy_path("interfaces")],),
metadata=metadata_legacy,
)

Expand All @@ -57,15 +52,8 @@ def _update(

def test_integration_legacy_update_set_string(service_legacy, metadata_legacy):
new_password = str(uuid.uuid4())
path = gnmi.proto.legacy.Path(
elem=[
gnmi.proto.legacy.PathElem(name="system"),
gnmi.proto.legacy.PathElem(name="aaa"),
gnmi.proto.legacy.PathElem(name="authentication"),
gnmi.proto.legacy.PathElem(name="admin-user"),
gnmi.proto.legacy.PathElem(name="config"),
gnmi.proto.legacy.PathElem(name="admin-password"),
],
path = create_legacy_path(
"system/aaa/authentication/admin-user/config/admin-password"
)
update = gnmi.proto.legacy.Update(
path=path, val=gnmi.proto.legacy.TypedValue(string_val=new_password)
Expand All @@ -80,12 +68,7 @@ def test_integration_legacy_update_set_string(service_legacy, metadata_legacy):

def test_integration_legacy_update_set_json(service_legacy, metadata_legacy):
config = {"config": {"timezone-name": "Europe/Berlin"}}
path = gnmi.proto.legacy.Path(
elem=[
gnmi.proto.legacy.PathElem(name="system"),
gnmi.proto.legacy.PathElem(name="clock"),
],
)
path = create_legacy_path("system/clock")
update = gnmi.proto.legacy.Update(
path=path,
val=gnmi.proto.legacy.TypedValue(json_ietf_val=json.dumps(config).encode()),
Expand All @@ -96,3 +79,17 @@ def test_integration_legacy_update_set_json(service_legacy, metadata_legacy):
gnmi.proto.legacy.GetRequest(path=[path],), metadata=metadata_legacy,
)
validate_response_get(response=response, value=config)


def test_integration_legacy_delete(service_legacy, metadata_legacy):
path = create_legacy_path("system/clock/config/timezone-name")

service_legacy.Set(
gnmi.proto.legacy.SetRequest(delete=[path]), metadata=metadata_legacy
)

response = service_legacy.Get(
gnmi.proto.legacy.GetRequest(path=[create_legacy_path("system/clock")],),
metadata=metadata_legacy,
)
validate_response_get(response=response, value={})

0 comments on commit e5e31b9

Please sign in to comment.