@@ -736,7 +736,7 @@ def test_xml_config(xml_safe_data_model, xml_safe_data):
736
736
# convert InstanceValue to an XML-encoded string
737
737
xml_obj = inst .to_xml ()
738
738
xml_text = ET .tostring (xml_obj ).decode ("utf-8" )
739
- # assert(xml_text == expected_xml_stripped) # fails, see Issue #87
739
+ assert (xml_text == expected_xml_stripped )
740
740
741
741
# convert XML-encoded string back to an InstanceValue
742
742
parser = XMLParser (expected_xml_stripped )
@@ -754,7 +754,6 @@ def test_xml_config(xml_safe_data_model, xml_safe_data):
754
754
755
755
756
756
757
-
758
757
def test_xml_rpc (data_model ):
759
758
'''
760
759
Encodes known "raw data" RPC input & outputs to an XML strings and back again.
@@ -800,7 +799,7 @@ def test_xml_rpc(data_model):
800
799
801
800
# convert raw object to an InstanceValue
802
801
# - an ObjectValue, not a RootNode as per DataModel.from_raw()
803
- input_inst_val = sn_rpc .from_raw (input_obj , allow_nodata = True )
802
+ input_inst_val = sn_rpc .from_raw (input_obj )
804
803
assert (str (input_inst_val ) == str (input_obj ))
805
804
806
805
# convert InstanceValue to an Instance (a RootNode)
@@ -817,7 +816,7 @@ def test_xml_rpc(data_model):
817
816
# - an ObjectValue, not a RootNode as per DataModel.from_xml()
818
817
parser = XMLParser (input_xml_text )
819
818
input_xml_et_obj2 = parser .root
820
- input_inst_val2 = sn_rpc .from_xml (input_xml_et_obj2 , isroot = True , allow_nodata = True )
819
+ input_inst_val2 = sn_rpc .from_xml (input_xml_et_obj2 )
821
820
assert (input_inst_val2 == input_inst_val )
822
821
823
822
# convert InstanceValue back to an Instance (a RootNode)
@@ -837,7 +836,7 @@ def test_xml_rpc(data_model):
837
836
838
837
# convert raw object to an InstanceValue
839
838
# - an ObjectValue, not a RootNode as per DataModel.from_raw()
840
- output_inst_val = sn_rpc .from_raw (output_obj , allow_nodata = True )
839
+ output_inst_val = sn_rpc .from_raw (output_obj )
841
840
assert (str (output_inst_val ) == str (output_obj ))
842
841
843
842
# convert InstanceValue to an Instance (a RootNode)
@@ -854,7 +853,7 @@ def test_xml_rpc(data_model):
854
853
# - an ObjectValue, not a RootNode as per DataModel.from_xml()
855
854
parser = XMLParser (output_xml_text )
856
855
output_xml_et_obj2 = parser .root
857
- output_inst_val2 = sn_rpc .from_xml (output_xml_et_obj2 , isroot = True , allow_nodata = True )
856
+ output_inst_val2 = sn_rpc .from_xml (output_xml_et_obj2 )
858
857
assert (output_inst_val2 == output_inst_val )
859
858
860
859
# convert InstanceValue back to an Instance (a RootNode)
@@ -867,7 +866,6 @@ def test_xml_rpc(data_model):
867
866
assert (output_rv2 == output_obj )
868
867
869
868
870
-
871
869
def test_xml_action (data_model ):
872
870
'''
873
871
Encodes known "raw data" Action input & outputs to an XML strings and back again.
@@ -887,7 +885,7 @@ def test_xml_action(data_model):
887
885
888
886
output_xml_stripped = strip_pretty (output_xml_pretty )
889
887
890
- # get the schema node for the 'action'
888
+ # get the schema node for the 'action'
891
889
sn_action = data_model .get_schema_node ("/test:contA/listA/contD/acA" )
892
890
assert (type (sn_action ) == RpcActionNode )
893
891
@@ -903,7 +901,7 @@ def test_xml_action(data_model):
903
901
904
902
# convert raw object to an InstanceValue
905
903
# - an ObjectValue, not a RootNode as per DataModel.from_raw()
906
- output_inst_val = sn_action .from_raw (output_obj , allow_nodata = True )
904
+ output_inst_val = sn_action .from_raw (output_obj )
907
905
assert (str (output_inst_val ) == str (output_obj ))
908
906
909
907
# convert InstanceValue to an Instance (a RootNode)
@@ -920,7 +918,7 @@ def test_xml_action(data_model):
920
918
# - an ObjectValue, not a RootNode as per DataModel.from_xml()
921
919
parser = XMLParser (output_xml_text )
922
920
output_xml_et_obj2 = parser .root
923
- output_inst_val2 = sn_action .from_xml (output_xml_et_obj2 , isroot = True , allow_nodata = True )
921
+ output_inst_val2 = sn_action .from_xml (output_xml_et_obj2 )
924
922
assert (output_inst_val2 == output_inst_val )
925
923
926
924
# convert InstanceValue back to an Instance (a RootNode)
@@ -946,76 +944,28 @@ def test_xml_notification(data_model):
946
944
sn_notif = data_model .get_schema_node ("/testb:noA" )
947
945
assert (type (sn_notif ) == NotificationNode )
948
946
949
- #######
950
- # NOA #
951
- #######
947
+ #########
948
+ # NOTIF # (most common?)
949
+ #########
952
950
953
- noA_obj = {
954
- "testb:leafO" : True
951
+ notif_obj = {
952
+ "testb:noA" : {
953
+ "leafO" : True
954
+ }
955
955
}
956
- noA_xml_pretty = """
957
- <leafO xmlns="http://example.com/testb">true</leafO>
956
+ notif_xml_pretty = """
957
+ <noa xmlns="http://example.com/testb">
958
+ <leafO>true</leafO>
959
+ </noa>
958
960
"""
959
- noA_xml_stripped = strip_pretty (noA_xml_pretty )
960
-
961
- # convert raw object to an InstanceValue
962
- # - an ObjectValue, not a RootNode as per DataModel.from_raw()
963
- noA_inst_val = sn_notif .from_raw (noA_obj , allow_nodata = True )
964
- assert (str (noA_inst_val ) == str (noA_obj ))
961
+ notif_xml_stripped = strip_pretty (notif_xml_pretty )
965
962
966
- # convert InstanceValue to an Instance (a RootNode)
967
- noA_inst = RootNode (noA_inst_val , sn_notif , data_model .schema_data , noA_inst_val .timestamp )
968
- noA_inst .validate (ctype = ContentType .all )
969
- assert (noA_inst .raw_value () == noA_obj )
970
963
971
- # convert Instance to an XML-encoded string and compare to known-good
972
- noA_xml_et_obj = noA_inst .to_xml ()
973
- noA_xml_text = ET .tostring (noA_xml_et_obj ).decode ("utf-8" )
974
- assert (noA_xml_text == noA_xml_stripped )
964
+ # convert raw object to an InstanceValue, an ObjectValue, not a RootNode as per DataModel.from_raw()
965
+ notif_inst_val = data_model .schema .from_raw (notif_obj ) # , force_namespace=True) #)
975
966
976
- # convert noa's XML-encoded string back to an InstanceValue
977
- # - an ObjectValue, not a RootNode as per DataModel.from_xml()
978
- parser = XMLParser (noA_xml_text )
979
- noA_xml_et_obj2 = parser .root
980
- noA_inst_val2 = sn_notif .from_xml (noA_xml_et_obj2 , isroot = True , allow_nodata = True )
981
- assert (noA_inst_val2 == noA_inst_val )
967
+ assert (str (notif_inst_val ) == str (notif_obj ))
982
968
983
- # convert InstanceValue back to an Instance (a RootNode)
984
- noA_inst2 = RootNode (noA_inst_val2 , sn_notif , data_model .schema_data , noA_inst_val2 .timestamp )
985
- noA_inst2 .validate (ctype = ContentType .all )
986
- assert (noA_inst2 .raw_value () == noA_obj )
987
-
988
- # convert Instance to raw value and ensure same
989
- noA_rv2 = noA_inst2 .raw_value ()
990
- assert (noA_rv2 == noA_obj )
991
-
992
-
993
-
994
-
995
- # Commenting out since none work
996
- #
997
- # #########
998
- # # NOTIF # (most common?)
999
- # #########
1000
- #
1001
- # notif_obj = {
1002
- # "testb:noA" : {
1003
- # "leafO" : True
1004
- # }
1005
- # }
1006
- # notif_xml_pretty = """
1007
- # <noa xmlns="http://example.com/testb">
1008
- # <leafO>true</leafO>
1009
- # </noa>
1010
- # """
1011
- # notif_xml_stripped = strip_pretty(notif_xml_pretty)
1012
- #
1013
- #
1014
- # # convert raw object to an InstanceValue, an ObjectValue, not a RootNode as per DataModel.from_raw()
1015
- # notif_inst_val = sn_notif.from_raw(notif_obj, allow_nodata=True)
1016
- # assert(str(notif_inst_val) == str(notif_obj))
1017
- #
1018
- #
1019
969
# ###################
1020
970
# # JSON - RESTCONF # (per RFC 8040)
1021
971
# ###################
@@ -1159,7 +1109,7 @@ def test_top_level_nodes(data_model):
1159
1109
# #print("root = " + str(root))
1160
1110
#
1161
1111
# sn = data_model.get_schema_node("/")
1162
- # instval = sn.from_raw(rv, allow_nodata=True )
1112
+ # instval = sn.from_raw(rv)
1163
1113
# #print("instval = " + str(instval))
1164
1114
#
1165
1115
# inst = RootNode(instval, sn, data_model.schema_data, instval.timestamp)
0 commit comments