11import unittest
22from unittest .mock import patch , Mock
33import json
4- from tests .utils .api_encryption_test_utils import MockApiClient , MockService
4+ from tests .utils .api_encryption_test_utils import MockApiClient , MockService , MockRestApiClient
55from tests import get_config_for_test , TEST_CONFIG
66import client_encryption .api_encryption as to_test
77
@@ -170,9 +170,9 @@ def test_add_encryption_layer_post(self):
170170 }
171171 }, headers = {"Content-Type" : "application/json" })
172172
173- self .assertIn ("data" , response .data )
174- self .assertIn ("secret" , response .data ["data" ])
175- self .assertEqual (secret2 - secret1 , response .data ["data" ]["secret" ])
173+ self .assertIn ("data" , json . loads ( response .data ) )
174+ self .assertIn ("secret" , json . loads ( response .data ) ["data" ])
175+ self .assertEqual (secret2 - secret1 , json . loads ( response .data ) ["data" ]["secret" ])
176176 self .assertDictEqual ({"Content-Type" : "application/json" }, response .getheaders ())
177177
178178 def test_add_encryption_layer_delete (self ):
@@ -187,17 +187,18 @@ def test_add_encryption_layer_delete(self):
187187 }
188188 }, headers = {"Content-Type" : "application/json" })
189189
190- self .assertEqual ("OK" , response .data )
190+ self .assertEqual ("OK" , json . loads ( response .data ) )
191191 self .assertDictEqual ({"Content-Type" : "application/json" }, response .getheaders ())
192192
193193 def test_add_encryption_layer_get (self ):
194194 test_client = MockApiClient ()
195195 to_test .add_encryption_layer (test_client , self ._json_config )
196196 response = MockService (test_client ).do_something_get (headers = {"Content-Type" : "application/json" })
197+ json_res = json .loads (response .data )
197198
198- self .assertIn ("data" , response . data )
199- self .assertIn ("secret" , response . data [ " data" ])
200- self .assertEqual ([53 , 84 , 75 ], response . data ["data" ]["secret" ])
199+ self .assertIn ("data" , json_res )
200+ self .assertIn ("secret" , json_res [ ' data' ])
201+ self .assertEqual ([53 , 84 , 75 ], json_res ["data" ]["secret" ])
201202 self .assertDictEqual ({"Content-Type" : "application/json" }, response .getheaders ())
202203
203204 def test_add_header_encryption_layer_post_no_oaep_algo (self ):
@@ -216,9 +217,9 @@ def test_add_header_encryption_layer_post_no_oaep_algo(self):
216217 "encryptedData" : {}
217218 }, headers = {"Content-Type" : "application/json" })
218219
219- self .assertIn ("data" , response .data )
220- self .assertIn ("secret" , response .data ["data" ])
221- self .assertEqual (secret2 - secret1 , response .data ["data" ]["secret" ])
220+ self .assertIn ("data" , json . loads ( response .data ) )
221+ self .assertIn ("secret" , json . loads ( response .data ) ["data" ])
222+ self .assertEqual (secret2 - secret1 , json . loads ( response .data ) ["data" ]["secret" ])
222223 self .assertDictEqual ({"Content-Type" : "application/json" , "x-oaep-digest" : "SHA256" }, response .getheaders ())
223224
224225 def test_add_header_encryption_layer_post_no_cert_fingerprint (self ):
@@ -237,9 +238,9 @@ def test_add_header_encryption_layer_post_no_cert_fingerprint(self):
237238 "encryptedData" : {}
238239 }, headers = {"Content-Type" : "application/json" })
239240
240- self .assertIn ("data" , response .data )
241- self .assertIn ("secret" , response .data ["data" ])
242- self .assertEqual (secret2 - secret1 , response .data ["data" ]["secret" ])
241+ self .assertIn ("data" , json . loads ( response .data ) )
242+ self .assertIn ("secret" , json . loads ( response .data ) ["data" ])
243+ self .assertEqual (secret2 - secret1 , json . loads ( response .data ) ["data" ]["secret" ])
243244 self .assertDictEqual ({"Content-Type" : "application/json" }, response .getheaders ())
244245
245246 def test_add_header_encryption_layer_post_no_pubkey_fingerprint (self ):
@@ -258,9 +259,9 @@ def test_add_header_encryption_layer_post_no_pubkey_fingerprint(self):
258259 "encryptedData" : {}
259260 }, headers = {"Content-Type" : "application/json" })
260261
261- self .assertIn ("data" , response .data )
262- self .assertIn ("secret" , response .data ["data" ])
263- self .assertEqual (secret2 - secret1 , response .data ["data" ]["secret" ])
262+ self .assertIn ("data" , json . loads ( response .data ) )
263+ self .assertIn ("secret" , json . loads ( response .data ) ["data" ])
264+ self .assertEqual (secret2 - secret1 , json . loads ( response .data ) ["data" ]["secret" ])
264265 self .assertDictEqual ({"Content-Type" : "application/json" }, response .getheaders ())
265266
266267 def test_add_header_encryption_layer_no_iv (self ):
@@ -294,9 +295,9 @@ def test_add_header_encryption_layer_post(self):
294295 "encryptedData" : {}
295296 }, headers = {"Content-Type" : "application/json" })
296297
297- self .assertIn ("data" , response .data )
298- self .assertIn ("secret" , response .data ["data" ])
299- self .assertEqual (secret2 - secret1 , response .data ["data" ]["secret" ])
298+ self .assertIn ("data" , json . loads ( response .data ) )
299+ self .assertIn ("secret" , json . loads ( response .data ) ["data" ])
300+ self .assertEqual (secret2 - secret1 , json . loads ( response .data ) ["data" ]["secret" ])
300301 self .assertDictEqual ({"Content-Type" : "application/json" }, response .getheaders ())
301302
302303 def test_add_header_encryption_layer_delete (self ):
@@ -324,15 +325,16 @@ def test_add_header_encryption_layer_get(self):
324325 to_test .add_encryption_layer (test_client , self ._json_config )
325326 response = MockService (test_client ).do_something_get_use_headers (headers = {"Content-Type" : "application/json" })
326327
327- self .assertIn ("data" , response .data )
328- self .assertIn ("secret" , response .data ["data" ])
329- self .assertEqual ([53 , 84 , 75 ], response .data ["data" ]["secret" ])
328+ self .assertIn ("data" , json . loads ( response .data ) )
329+ self .assertIn ("secret" , json . loads ( response .data ) ["data" ])
330+ self .assertEqual ([53 , 84 , 75 ], json . loads ( response .data ) ["data" ]["secret" ])
330331 self .assertDictEqual ({"Content-Type" : "application/json" }, response .getheaders ())
331332
332333 @patch ('client_encryption.api_encryption.__oauth_warn' )
333334 def test_add_encryption_layer_oauth_set (self , __oauth_warn ):
334335 test_client = MockApiClient ()
335- to_test .add_encryption_layer (test_client , self ._json_config )
336+ test_rest_client = MockRestApiClient (test_client )
337+ to_test .add_encryption_layer (test_rest_client , self ._json_config )
336338
337339 assert not __oauth_warn .called
338340
0 commit comments