@@ -125,7 +125,8 @@ def test_response(self):
125
125
}
126
126
127
127
resp = mock .create_autospec (Response )
128
- resp .content = json .dumps (data )
128
+ resp .text = json .dumps (data )
129
+ resp .encoding = 'utf-8'
129
130
model = self .d ('GenericResource' , resp )
130
131
self .assertEqual (model .properties ['platformFaultDomainCount' ], 3 )
131
132
self .assertEqual (model .location , 'westus' )
@@ -749,37 +750,38 @@ def test_non_obj_deserialization(self):
749
750
Test direct deserialization of simple types.
750
751
"""
751
752
response_data = mock .create_autospec (Response )
753
+ response_data .encoding = 'utf-8'
752
754
753
- response_data .content = json . dumps ({})
755
+ response_data .text = ''
754
756
response = self .d ("[str]" , response_data )
755
757
self .assertIsNone (response )
756
758
757
- response_data .content = ""
759
+ response_data .text = json . dumps ({})
758
760
response = self .d ("[str]" , response_data )
759
761
self .assertIsNone (response )
760
762
761
- response_data .content = None
763
+ response_data .text = ""
762
764
response = self .d ("[str]" , response_data )
763
765
self .assertIsNone (response )
764
766
765
767
message = ["a" ,"b" ,"b" ]
766
- response_data .content = json .dumps (message )
768
+ response_data .text = json .dumps (message )
767
769
response = self .d ("[str]" , response_data )
768
770
self .assertEqual (response , message )
769
771
770
- response_data .content = json .dumps (12345 )
772
+ response_data .text = json .dumps (12345 )
771
773
with self .assertRaises (DeserializationError ):
772
774
response = self .d ("[str]" , response_data )
773
775
774
- response_data .content = True
776
+ response_data .text = 'true'
775
777
response = self .d ('bool' , response_data )
776
778
self .assertEqual (response , True )
777
779
778
- response_data .content = json .dumps (1 )
780
+ response_data .text = json .dumps (1 )
779
781
response = self .d ('bool' , response_data )
780
782
self .assertEqual (response , True )
781
783
782
- response_data .content = json .dumps ("true1" )
784
+ response_data .text = json .dumps ("true1" )
783
785
with self .assertRaises (DeserializationError ):
784
786
response = self .d ('bool' , response_data )
785
787
@@ -790,7 +792,8 @@ def test_obj_with_no_attr(self):
790
792
"""
791
793
792
794
response_data = mock .create_autospec (Response )
793
- response_data .content = json .dumps ({"a" :"b" })
795
+ response_data .text = json .dumps ({"a" :"b" })
796
+ response_data .encoding = 'utf-8'
794
797
795
798
class EmptyResponse (Model ):
796
799
_attribute_map = {}
@@ -805,7 +808,8 @@ def test_obj_with_malformed_map(self):
805
808
Test deserializing an object with a malformed attributes_map.
806
809
"""
807
810
response_data = mock .create_autospec (Response )
808
- response_data .content = json .dumps ({"a" :"b" })
811
+ response_data .text = json .dumps ({"a" :"b" })
812
+ response_data .encoding = 'utf-8'
809
813
810
814
class BadResponse (Model ):
811
815
_attribute_map = None
@@ -845,7 +849,7 @@ def test_attr_none(self):
845
849
846
850
response_data .status_code = None
847
851
response_data .headers = {'client-request-id' :None , 'etag' :None }
848
- response_data .content = None
852
+ response_data .text = ''
849
853
850
854
response = self .d (self .TestObj , response_data )
851
855
self .assertIsNone (response )
@@ -857,19 +861,20 @@ def test_attr_int(self):
857
861
response_data = mock .create_autospec (Response )
858
862
response_data .status_code = 200
859
863
response_data .headers = {'client-request-id' :"123" , 'etag' :456.3 }
860
- response_data .content = None
864
+ response_data .text = ''
861
865
862
866
response = self .d (self .TestObj , response_data )
863
867
self .assertIsNone (response )
864
868
865
869
message = {'AttrB' :'1234' }
866
- response_data .content = json .dumps (message )
870
+ response_data .text = json .dumps (message )
871
+ response_data .encoding = 'utf-8'
867
872
response = self .d (self .TestObj , response_data )
868
873
self .assertTrue (hasattr (response , 'attr_b' ))
869
874
self .assertEqual (response .attr_b , int (message ['AttrB' ]))
870
875
871
876
with self .assertRaises (DeserializationError ):
872
- response_data .content = json .dumps ({'AttrB' :'NotANumber' })
877
+ response_data .text = json .dumps ({'AttrB' :'NotANumber' })
873
878
response = self .d (self .TestObj , response_data )
874
879
875
880
def test_attr_str (self ):
@@ -880,23 +885,24 @@ def test_attr_str(self):
880
885
response_data = mock .create_autospec (Response )
881
886
response_data .status_code = 200
882
887
response_data .headers = {'client-request-id' : 'a' , 'etag' : 'b' }
883
- response_data .content = json .dumps (message )
888
+ response_data .text = json .dumps (message )
889
+ response_data .encoding = 'utf-8'
884
890
885
891
response = self .d (self .TestObj , response_data )
886
892
self .assertTrue (hasattr (response , 'attr_a' ))
887
893
self .assertEqual (response .attr_a , message ['id' ])
888
894
889
895
message = {'id' :1234 }
890
- response_data .content = json .dumps (message )
896
+ response_data .text = json .dumps (message )
891
897
response = self .d (self .TestObj , response_data )
892
898
self .assertEqual (response .attr_a , str (message ['id' ]))
893
899
894
900
message = {'id' :list ()}
895
- response_data .content = json .dumps (message )
901
+ response_data .text = json .dumps (message )
896
902
response = self .d (self .TestObj , response_data )
897
903
self .assertEqual (response .attr_a , str (message ['id' ]))
898
904
899
- response_data .content = json .dumps ({'id' :None })
905
+ response_data .text = json .dumps ({'id' :None })
900
906
response = self .d (self .TestObj , response_data )
901
907
self .assertEqual (response .attr_a , None )
902
908
@@ -907,22 +913,23 @@ def test_attr_bool(self):
907
913
response_data = mock .create_autospec (Response )
908
914
response_data .status_code = 200
909
915
response_data .headers = {'client-request-id' : 'a' , 'etag' : 'b' }
910
- response_data .content = json .dumps ({'Key_C' :True })
916
+ response_data .text = json .dumps ({'Key_C' :True })
917
+ response_data .encoding = 'utf-8'
911
918
912
919
response = self .d (self .TestObj , response_data )
913
920
914
921
self .assertTrue (hasattr (response , 'attr_c' ))
915
922
self .assertEqual (response .attr_c , True )
916
923
917
- response_data .content = json .dumps ({'Key_C' :[]})
924
+ response_data .text = json .dumps ({'Key_C' :[]})
918
925
with self .assertRaises (DeserializationError ):
919
926
response = self .d (self .TestObj , response_data )
920
927
921
- response_data .content = json .dumps ({'Key_C' :0 })
928
+ response_data .text = json .dumps ({'Key_C' :0 })
922
929
response = self .d (self .TestObj , response_data )
923
930
self .assertEqual (response .attr_c , False )
924
931
925
- response_data .content = json .dumps ({'Key_C' :"value" })
932
+ response_data .text = json .dumps ({'Key_C' :"value" })
926
933
with self .assertRaises (DeserializationError ):
927
934
response = self .d (self .TestObj , response_data )
928
935
@@ -933,30 +940,31 @@ def test_attr_list_simple(self):
933
940
response_data = mock .create_autospec (Response )
934
941
response_data .status_code = 200
935
942
response_data .headers = {'client-request-id' : 'a' , 'etag' : 'b' }
936
- response_data .content = json .dumps ({'AttrD' : []})
943
+ response_data .text = json .dumps ({'AttrD' : []})
944
+ response_data .encoding = 'utf-8'
937
945
938
946
response = self .d (self .TestObj , response_data )
939
947
deserialized_list = [d for d in response .attr_d ]
940
948
self .assertEqual (deserialized_list , [])
941
949
942
950
message = {'AttrD' : [1 ,2 ,3 ]}
943
- response_data .content = json .dumps (message )
951
+ response_data .text = json .dumps (message )
944
952
response = self .d (self .TestObj , response_data )
945
953
deserialized_list = [d for d in response .attr_d ]
946
954
self .assertEqual (deserialized_list , message ['AttrD' ])
947
955
948
956
message = {'AttrD' : ["1" ,"2" ,"3" ]}
949
- response_data .content = json .dumps (message )
957
+ response_data .text = json .dumps (message )
950
958
response = self .d (self .TestObj , response_data )
951
959
deserialized_list = [d for d in response .attr_d ]
952
960
self .assertEqual (deserialized_list , [int (i ) for i in message ['AttrD' ]])
953
961
954
- response_data .content = json .dumps ({'AttrD' : ["test" ,"test2" ,"test3" ]})
962
+ response_data .text = json .dumps ({'AttrD' : ["test" ,"test2" ,"test3" ]})
955
963
with self .assertRaises (DeserializationError ):
956
964
response = self .d (self .TestObj , response_data )
957
965
deserialized_list = [d for d in response .attr_d ]
958
966
959
- response_data .content = json .dumps ({'AttrD' : "NotAList" })
967
+ response_data .text = json .dumps ({'AttrD' : "NotAList" })
960
968
with self .assertRaises (DeserializationError ):
961
969
response = self .d (self .TestObj , response_data )
962
970
deserialized_list = [d for d in response .attr_d ]
@@ -968,41 +976,42 @@ def test_attr_list_in_list(self):
968
976
response_data = mock .create_autospec (Response )
969
977
response_data .status_code = 200
970
978
response_data .headers = {'client-request-id' : 'a' , 'etag' : 'b' }
971
- response_data .content = json .dumps ({'AttrF' :[]})
979
+ response_data .text = json .dumps ({'AttrF' :[]})
980
+ response_data .encoding = 'utf-8'
972
981
973
982
response = self .d (self .TestObj , response_data )
974
983
self .assertTrue (hasattr (response , 'attr_f' ))
975
984
self .assertEqual (response .attr_f , [])
976
985
977
- response_data .content = json .dumps ({'AttrF' :None })
986
+ response_data .text = json .dumps ({'AttrF' :None })
978
987
979
988
response = self .d (self .TestObj , response_data )
980
989
self .assertTrue (hasattr (response , 'attr_f' ))
981
990
self .assertEqual (response .attr_f , None )
982
991
983
- response_data .content = json .dumps ({})
992
+ response_data .text = json .dumps ({})
984
993
985
994
response = self .d (self .TestObj , response_data )
986
995
987
996
self .assertTrue (hasattr (response , 'attr_f' ))
988
997
self .assertEqual (response .attr_f , None )
989
998
990
999
message = {'AttrF' :[[]]}
991
- response_data .content = json .dumps (message )
1000
+ response_data .text = json .dumps (message )
992
1001
993
1002
response = self .d (self .TestObj , response_data )
994
1003
self .assertTrue (hasattr (response , 'attr_f' ))
995
1004
self .assertEqual (response .attr_f , message ['AttrF' ])
996
1005
997
1006
message = {'AttrF' :[[1 ,2 ,3 ], ['a' ,'b' ,'c' ]]}
998
- response_data .content = json .dumps (message )
1007
+ response_data .text = json .dumps (message )
999
1008
1000
1009
response = self .d (self .TestObj , response_data )
1001
1010
self .assertTrue (hasattr (response , 'attr_f' ))
1002
1011
self .assertEqual (response .attr_f , [[str (i ) for i in k ] for k in message ['AttrF' ]])
1003
1012
1004
1013
with self .assertRaises (DeserializationError ):
1005
- response_data .content = json .dumps ({'AttrF' :[1 ,2 ,3 ]})
1014
+ response_data .text = json .dumps ({'AttrF' :[1 ,2 ,3 ]})
1006
1015
response = self .d (self .TestObj , response_data )
1007
1016
1008
1017
def test_attr_list_complex (self ):
@@ -1020,7 +1029,8 @@ class CmplxTestObj(Model):
1020
1029
response_data = mock .create_autospec (Response )
1021
1030
response_data .status_code = 200
1022
1031
response_data .headers = {'client-request-id' : 'a' , 'etag' : 'b' }
1023
- response_data .content = json .dumps ({"id" :[{"ABC" : "123" }]})
1032
+ response_data .text = json .dumps ({"id" :[{"ABC" : "123" }]})
1033
+ response_data .encoding = 'utf-8'
1024
1034
1025
1035
d = Deserializer ({'ListObj' :ListObj })
1026
1036
response = d (CmplxTestObj , response_data )
0 commit comments