Skip to content

Commit 49d860f

Browse files
committed
Patch Unit tests to use cached path as the default
Need to patch the cache expiry check as pymongo is magicmocked, which results in magicmock being passed to timedelta. We shouldn't really be testing that flow in these unit tests.
1 parent a343757 commit 49d860f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

tests/unit/test_arctic.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
def test_arctic_lazy_init():
2020
with patch('pymongo.MongoClient', return_value=MagicMock(), autospec=True) as mc, \
2121
patch('arctic.arctic.mongo_retry', side_effect=lambda x: x, autospec=True), \
22+
patch('arctic._cache.Cache._is_not_expired', return_value=True), \
2223
patch('arctic.arctic.get_auth', autospec=True) as ga:
2324
store = Arctic('cluster')
2425
assert not mc.called
@@ -30,6 +31,7 @@ def test_arctic_lazy_init():
3031
def test_arctic_lazy_init_ssl_true():
3132
with patch('pymongo.MongoClient', return_value=MagicMock(), autospec=True) as mc, \
3233
patch('arctic.arctic.mongo_retry', side_effect=lambda x: x, autospec=True), \
34+
patch('arctic._cache.Cache._is_not_expired', return_value=True), \
3335
patch('arctic.arctic.get_auth', autospec=True) as ga:
3436
store = Arctic('cluster', ssl=True)
3537
assert not mc.called
@@ -48,6 +50,7 @@ def test_arctic_lazy_init_ssl_true():
4850
def test_connection_passed_warning_raised():
4951
with patch('pymongo.MongoClient', return_value=MagicMock(), autospec=True), \
5052
patch('arctic.arctic.mongo_retry', side_effect=lambda x: x, autospec=True), \
53+
patch('arctic._cache.Cache._is_not_expired', return_value=True), \
5154
patch('arctic.arctic.get_auth', autospec=True), \
5255
patch('arctic.arctic.logger') as lg:
5356
magic_mock = MagicMock(nodes={("host", "port")})
@@ -62,7 +65,8 @@ def test_connection_passed_warning_raised():
6265
def test_arctic_auth():
6366
with patch('pymongo.MongoClient', return_value=MagicMock(), autospec=True), \
6467
patch('arctic.arctic.mongo_retry', autospec=True), \
65-
patch('arctic.arctic.get_auth', autospec=True) as ga:
68+
patch('arctic._cache.Cache._is_not_expired', return_value=True), \
69+
patch('arctic.arctic.get_auth', autospec=True) as ga:
6670
ga.return_value = Credential('db', 'admin_user', 'admin_pass')
6771
store = Arctic('cluster')
6872
# do something to trigger lazy arctic init
@@ -86,7 +90,8 @@ def test_arctic_auth():
8690
def test_arctic_auth_custom_app_name():
8791
with patch('pymongo.MongoClient', return_value=MagicMock(), autospec=True), \
8892
patch('arctic.arctic.mongo_retry', autospec=True), \
89-
patch('arctic.arctic.get_auth', autospec=True) as ga:
93+
patch('arctic._cache.Cache._is_not_expired', return_value=True), \
94+
patch('arctic.arctic.get_auth', autospec=True) as ga:
9095
ga.return_value = Credential('db', 'admin_user', 'admin_pass')
9196
store = Arctic('cluster', app_name=sentinel.app_name)
9297
# do something to trigger lazy arctic init
@@ -108,7 +113,8 @@ def test_arctic_auth_custom_app_name():
108113
def test_arctic_connect_hostname():
109114
with patch('pymongo.MongoClient', return_value=MagicMock(), autospec=True) as mc, \
110115
patch('arctic.arctic.mongo_retry', autospec=True) as ar, \
111-
patch('arctic.arctic.get_mongodb_uri', autospec=True) as gmu:
116+
patch('arctic._cache.Cache._is_not_expired', return_value=True), \
117+
patch('arctic.arctic.get_mongodb_uri', autospec=True) as gmu:
112118
store = Arctic('hostname', socketTimeoutMS=sentinel.socket_timeout,
113119
connectTimeoutMS=sentinel.connect_timeout,
114120
serverSelectionTimeoutMS=sentinel.select_timeout)
@@ -124,6 +130,7 @@ def test_arctic_connect_with_environment_name():
124130
with patch('pymongo.MongoClient', return_value=MagicMock(), autospec=True) as mc, \
125131
patch('arctic.arctic.mongo_retry', autospec=True) as ar, \
126132
patch('arctic.arctic.get_auth', autospec=True), \
133+
patch('arctic._cache.Cache._is_not_expired', return_value=True), \
127134
patch('arctic.arctic.get_mongodb_uri') as gmfe:
128135
store = Arctic('live', socketTimeoutMS=sentinel.socket_timeout,
129136
connectTimeoutMS=sentinel.connect_timeout,
@@ -453,7 +460,8 @@ def flaky_auth(*args, **kwargs):
453460

454461
def test_reset():
455462
c = MagicMock()
456-
with patch('pymongo.MongoClient', return_value=c, autospec=True) as mc:
463+
with patch('pymongo.MongoClient', return_value=c, autospec=True) as mc, \
464+
patch('arctic._cache.Cache._is_not_expired', return_value=True):
457465
store = Arctic('hostname')
458466
# do something to trigger lazy arctic init
459467
store.list_libraries()

0 commit comments

Comments
 (0)