6
6
7
7
from msal .throttled_http_client import (
8
8
ThrottledHttpClientBase , ThrottledHttpClient , NormalizedResponse )
9
+ from msal .exceptions import MsalServiceError
9
10
10
11
from tests import unittest
11
12
from tests .http_client import MinimalResponse as _MinimalResponse
@@ -65,6 +66,26 @@ class CloseMethodCalled(Exception):
65
66
pass
66
67
67
68
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
+
68
89
class ThrottledHttpClientBaseTestCase (unittest .TestCase ):
69
90
70
91
def assertCleanPickle (self , obj ):
@@ -77,10 +98,6 @@ def assertValidResponse(self, response):
77
98
self .assertIsInstance (response , NormalizedResponse )
78
99
self .assertCleanPickle (response )
79
100
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
-
84
101
def test_throttled_http_client_base_response_should_tolerate_headerless_response (self ):
85
102
http_client = ThrottledHttpClientBase (DummyHttpClientWithoutResponseHeaders (
86
103
status_code = 200 , response_text = "foo" ))
0 commit comments