Skip to content

Commit a1f9ca7

Browse files
committed
Enable ThrottledHttpClient.close()
1 parent b4401a1 commit a1f9ca7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

msal/throttled_http_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,13 @@ def __init__(self, http_client, http_cache):
128128
3600*24 if 200 <= result.status_code < 300 else 0,
129129
)(http_client.get)
130130

131+
self._http_client = http_client
132+
131133
# The following 2 methods have been defined dynamically by __init__()
132134
#def post(self, *args, **kwargs): pass
133135
#def get(self, *args, **kwargs): pass
134136

137+
def close(self):
138+
"""MSAL won't need this. But we allow throttled_http_client.close() anyway"""
139+
return self._http_client.close()
140+

tests/test_throttled_http_client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ def post(self, url, params=None, data=None, headers=None, **kwargs):
3535
def get(self, url, params=None, headers=None, **kwargs):
3636
return self._build_dummy_response()
3737

38+
def close(self):
39+
raise CloseMethodCalled("Not used by MSAL, but our customers may use it")
40+
41+
42+
class CloseMethodCalled(Exception):
43+
pass
44+
3845

3946
class TestHttpDecoration(unittest.TestCase):
4047

@@ -163,3 +170,10 @@ def test_device_flow_retry_should_not_be_cached(self):
163170
logger.debug(http_cache)
164171
self.assertNotEqual(resp1.text, resp2.text, "Should return a new response")
165172

173+
def test_throttled_http_client_should_provide_close(self):
174+
http_cache = {}
175+
http_client = DummyHttpClient(status_code=200)
176+
http_client = ThrottledHttpClient(http_client, http_cache)
177+
with self.assertRaises(CloseMethodCalled):
178+
http_client.close()
179+

0 commit comments

Comments
 (0)