|
4 | 4 | import time |
5 | 5 | import unittest |
6 | 6 | import sys |
| 7 | +try: |
| 8 | + from unittest.mock import patch, ANY |
| 9 | +except: |
| 10 | + from mock import patch, ANY |
7 | 11 |
|
8 | 12 | import requests |
9 | 13 |
|
10 | 14 | import msal |
11 | | -from tests.http_client import MinimalHttpClient |
| 15 | +from tests.http_client import MinimalHttpClient, MinimalResponse |
12 | 16 | from msal.oauth2cli import AuthCodeReceiver |
13 | 17 |
|
14 | 18 | logger = logging.getLogger(__name__) |
@@ -758,13 +762,21 @@ def test_acquire_token_for_client_should_hit_regional_endpoint(self): |
758 | 762 | timeout=2, # Short timeout makes this test case responsive on non-VM |
759 | 763 | ) |
760 | 764 | scopes = ["https://graph.microsoft.com/.default"] |
| 765 | + |
| 766 | + with patch.object( # Test the request hit the regional endpoint |
| 767 | + self.app.http_client, "post", return_value=MinimalResponse( |
| 768 | + status_code=400, text='{"error": "mock"}')) as mocked_method: |
| 769 | + self.app.acquire_token_for_client(scopes) |
| 770 | + mocked_method.assert_called_with( |
| 771 | + 'https://westus.login.microsoft.com/{}/oauth2/v2.0/token'.format( |
| 772 | + self.app.authority.tenant), |
| 773 | + params=ANY, data=ANY, headers=ANY) |
761 | 774 | result = self.app.acquire_token_for_client( |
762 | 775 | scopes, |
763 | 776 | params={"AllowEstsRNonMsi": "true"}, # For testing regional endpoint. It will be removed once MSAL Python 1.12+ has been onboard to ESTS-R |
764 | 777 | ) |
765 | 778 | self.assertIn('access_token', result) |
766 | 779 | self.assertCacheWorksForApp(result, scopes) |
767 | | - # TODO: Test the request hit the regional endpoint self.region? |
768 | 780 |
|
769 | 781 |
|
770 | 782 | class RegionalEndpointViaEnvVarTestCase(WorldWideRegionalEndpointTestCase): |
|
0 commit comments