Skip to content

Commit f98b3c7

Browse files
avazquezrdrjarry
authored andcommitted
tests: include test for Session.validate()
Datastore validation must be performed, but changes are not applied nor discarded.
1 parent e252aee commit f98b3c7

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

tests/test_session.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,31 @@ def test_session_set_item(self):
9595
def iface(name, field):
9696
return "/sysrepo-example:conf/network/interface[name=%r]/%s" % (name, field)
9797

98+
def assert_data():
99+
with self.conn.start_session("running") as new_sess:
100+
data = new_sess.get_data("/sysrepo-example:conf")
101+
self.assertEqual(
102+
data,
103+
{
104+
"conf": {
105+
"network": {
106+
"interface": [
107+
{
108+
"name": "eth0",
109+
"address": "1.2.3.4/24",
110+
"up": True,
111+
},
112+
{
113+
"name": "eth1",
114+
"address": "4.3.2.1/24",
115+
"up": False,
116+
},
117+
]
118+
}
119+
}
120+
},
121+
)
122+
98123
with self.conn.start_session("running") as sess:
99124
sess.replace_config({}, "sysrepo-example")
100125
sess.set_item(iface("eth0", "address"), "1.2.3.4/24")
@@ -104,23 +129,11 @@ def iface(name, field):
104129
sess.apply_changes()
105130
sess.set_item(iface("eth2", "address"), "8.8.8.8/24")
106131
sess.set_item(iface("eth2", "up"), True)
132+
sess.validate()
133+
assert_data()
107134
sess.discard_changes()
108135

109-
with self.conn.start_session("running") as sess:
110-
data = sess.get_data("/sysrepo-example:conf")
111-
self.assertEqual(
112-
data,
113-
{
114-
"conf": {
115-
"network": {
116-
"interface": [
117-
{"name": "eth0", "address": "1.2.3.4/24", "up": True},
118-
{"name": "eth1", "address": "4.3.2.1/24", "up": False},
119-
]
120-
}
121-
}
122-
},
123-
)
136+
assert_data()
124137

125138
def test_get_netconf_id_and_get_user_are_only_available_in_implicit_session(self):
126139
with self.conn.start_session("running") as sess:

0 commit comments

Comments
 (0)