66
77from msal .throttled_http_client import (
88 ThrottledHttpClientBase , ThrottledHttpClient , NormalizedResponse )
9+ from msal .exceptions import MsalServiceError
910
1011from tests import unittest
1112from tests .http_client import MinimalResponse as _MinimalResponse
@@ -65,6 +66,26 @@ class CloseMethodCalled(Exception):
6566 pass
6667
6768
69+ class NormalizedResponseTestCase (unittest .TestCase ):
70+ def test_pickled_minimal_response_should_contain_signature (self ):
71+ self .assertIn (MinimalResponse .SIGNATURE , pickle .dumps (MinimalResponse (
72+ status_code = 200 , headers = {}, text = "foo" )))
73+
74+ def test_normalized_response_should_not_contain_signature (self ):
75+ response = NormalizedResponse (MinimalResponse (
76+ status_code = 200 , headers = {}, text = "foo" ))
77+ self .assertNotIn (
78+ MinimalResponse .SIGNATURE , pickle .dumps (response ),
79+ "A pickled object should not contain undesirable data" )
80+ self .assertEqual (response .text , "foo" , "Should return the same response text" )
81+
82+ def test_normalized_response_raise_for_status_should_raise (self ):
83+ response = NormalizedResponse (MinimalResponse (
84+ status_code = 400 , headers = {}, text = "foo" ))
85+ with self .assertRaises (MsalServiceError ):
86+ response .raise_for_status ()
87+
88+
6889class ThrottledHttpClientBaseTestCase (unittest .TestCase ):
6990
7091 def assertCleanPickle (self , obj ):
@@ -77,10 +98,6 @@ def assertValidResponse(self, response):
7798 self .assertIsInstance (response , NormalizedResponse )
7899 self .assertCleanPickle (response )
79100
80- def test_pickled_minimal_response_should_contain_signature (self ):
81- self .assertIn (MinimalResponse .SIGNATURE , pickle .dumps (MinimalResponse (
82- status_code = 200 , headers = {}, text = "foo" )))
83-
84101 def test_throttled_http_client_base_response_should_tolerate_headerless_response (self ):
85102 http_client = ThrottledHttpClientBase (DummyHttpClientWithoutResponseHeaders (
86103 status_code = 200 , response_text = "foo" ))
0 commit comments