-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: support validating specified values in get
- Loading branch information
Showing
1 changed file
with
19 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
import json | ||
from typing import Union | ||
from typing import Any, Dict, Union | ||
|
||
import gnmi.proto | ||
import gnmi.proto.legacy | ||
|
||
|
||
def validate_default_interfaces_get( | ||
response: Union[gnmi.proto.GetResponse, gnmi.proto.legacy.GetResponse] | ||
def validate_response_get( | ||
response: Union[gnmi.proto.GetResponse, gnmi.proto.legacy.GetResponse], | ||
value: Union[str, Dict[str, Any]], | ||
): | ||
assert len(response.notification) == 1 | ||
|
||
notification = response.notification.pop() | ||
assert len(notification.update) == 1 | ||
|
||
update = notification.update.pop() | ||
assert update.val.json_val | ||
assert json.loads(update.val.json_val.decode("utf-8")) == { | ||
"interface": {"admin": {"config": {"name": "admin"}, "name": "admin"}} | ||
} | ||
|
||
if isinstance(value, str): | ||
assert update.val.string_val == value | ||
else: | ||
assert update.val.json_val | ||
assert json.loads(update.val.json_val.decode("utf-8")) == value | ||
|
||
|
||
def validate_default_interfaces_get( | ||
response: Union[gnmi.proto.GetResponse, gnmi.proto.legacy.GetResponse], | ||
): | ||
validate_response_get( | ||
response=response, | ||
value={"interface": {"admin": {"config": {"name": "admin"}, "name": "admin"}}}, | ||
) |