Skip to content

Commit 08efbe2

Browse files
authored
[Cosmos] fix endpoint_discovery logic to be user-configurable (Azure#21778)
* fix endpoint_discovery logic to be user-configurable * Create test_user_configs.py * Update test_user_configs.py
1 parent 4721339 commit 08efbe2

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def _build_connection_policy(kwargs):
7979
policy.RequestTimeout
8080
policy.ConnectionMode = kwargs.pop('connection_mode', None) or policy.ConnectionMode
8181
policy.ProxyConfiguration = kwargs.pop('proxy_config', None) or policy.ProxyConfiguration
82-
policy.EnableEndpointDiscovery = kwargs.pop('enable_endpoint_discovery', None) or policy.EnableEndpointDiscovery
82+
policy.EnableEndpointDiscovery = kwargs.pop('enable_endpoint_discovery') \
83+
if 'enable_endpoint_discovery' in kwargs.keys() else policy.EnableEndpointDiscovery
8384
policy.PreferredLocations = kwargs.pop('preferred_locations', None) or policy.PreferredLocations
8485
policy.UseMultipleWriteLocations = kwargs.pop('multiple_write_locations', None) or \
8586
policy.UseMultipleWriteLocations
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# The MIT License (MIT)
2+
# Copyright (c) 2021 Microsoft Corporation
3+
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy
5+
# of this software and associated documentation files (the "Software"), to deal
6+
# in the Software without restriction, including without limitation the rights
7+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
# copies of the Software, and to permit persons to whom the Software is
9+
# furnished to do so, subject to the following conditions:
10+
11+
# The above copyright notice and this permission notice shall be included in all
12+
# copies or substantial portions of the Software.
13+
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
# SOFTWARE.
21+
22+
import unittest
23+
24+
import azure.cosmos.cosmos_client as cosmos_client
25+
import pytest
26+
from test_config import _test_config
27+
28+
29+
# This test class serves to test user-configurable options and verify they are
30+
# properly set and saved into the different object instances that use these
31+
# user-configurable settings.
32+
33+
pytestmark = pytest.mark.cosmosEmulator
34+
35+
@pytest.mark.usefixtures("teardown")
36+
class TestUserConfigs(unittest.TestCase):
37+
38+
def test_enable_endpoint_discovery(self):
39+
client_false = cosmos_client.CosmosClient(url=_test_config.host, credential=_test_config.masterKey,
40+
enable_endpoint_discovery=False)
41+
client_default = cosmos_client.CosmosClient(url=_test_config.host, credential=_test_config.masterKey)
42+
client_true = cosmos_client.CosmosClient(url=_test_config.host, credential=_test_config.masterKey,
43+
enable_endpoint_discovery=True)
44+
45+
self.assertFalse(client_false.client_connection.connection_policy.EnableEndpointDiscovery)
46+
self.assertTrue(client_default.client_connection.connection_policy.EnableEndpointDiscovery)
47+
self.assertTrue(client_true.client_connection.connection_policy.EnableEndpointDiscovery)
48+
49+
if __name__ == "__main__":
50+
unittest.main()

0 commit comments

Comments
 (0)