@@ -20,7 +20,14 @@ def test_arctic_lazy_init():
20
20
# do something to trigger lazy arctic init
21
21
store .list_libraries ()
22
22
assert mc .called
23
+
24
+ mock_conn_info = {u'authInfo' :
25
+ {u'authenticatedUsers' : [{u'user' : u'research' , u'userSource' : u'admin' }]},
26
+ u'ok' : 1.0 }
23
27
28
+ mock_conn_info_empty = {u'authInfo' :
29
+ {u'authenticatedUsers' : []},
30
+ u'ok' : 1.0 }
24
31
25
32
def test_arctic_auth ():
26
33
with patch ('pymongo.MongoClient' , return_value = MagicMock (), autospec = True ), \
@@ -39,6 +46,7 @@ def test_arctic_auth():
39
46
with patch ('arctic.arctic.ArcticLibraryBinding.get_library_type' , return_value = None , autospec = True ):
40
47
ga .return_value = Credential ('db' , 'user' , 'pass' )
41
48
store ._conn ['arctic_jblackburn' ].name = 'arctic_jblackburn'
49
+ store ._conn ['arctic_jblackburn' ].command .return_value = mock_conn_info
42
50
store ['jblackburn.library' ]
43
51
44
52
# Creating the library will have attempted to auth against it
@@ -62,12 +70,38 @@ def test_arctic_auth_custom_app_name():
62
70
with patch ('arctic.arctic.ArcticLibraryBinding.get_library_type' , return_value = None , autospec = True ):
63
71
ga .return_value = Credential ('db' , 'user' , 'pass' )
64
72
store ._conn ['arctic_jblackburn' ].name = 'arctic_jblackburn'
73
+ store ._conn ['arctic_jblackburn' ].command .return_value = mock_conn_info
65
74
store ['jblackburn.library' ]
66
75
67
76
# Creating the library will have attempted to auth against it
68
77
assert ga .call_args_list == [call ('cluster' , sentinel .app_name , 'arctic_jblackburn' )]
69
78
70
79
80
+ def test_arctic_auth_admin_reauth ():
81
+ with patch ('pymongo.MongoClient' , return_value = MagicMock (), autospec = True ), \
82
+ patch ('arctic.arctic.mongo_retry' , autospec = True ), \
83
+ patch ('arctic.arctic.get_auth' , autospec = True ) as ga :
84
+ ga .return_value = Credential ('db' , 'admin_user' , 'admin_pass' )
85
+ store = Arctic ('cluster' )
86
+ # do something to trigger lazy arctic init
87
+ store .list_libraries ()
88
+ assert ga .call_args_list == [call ('cluster' , 'arctic' , 'admin' )]
89
+ ga .reset_mock ()
90
+
91
+ # Get a 'missing' library
92
+ with pytest .raises (LibraryNotFoundException ):
93
+ with patch ('arctic.arctic.ArcticLibraryBinding.get_library_type' , return_value = None , autospec = True ), \
94
+ patch ('arctic.arctic.logger' ) as logger :
95
+ ga .return_value = Credential ('db' , 'user' , 'pass' )
96
+ store ._conn ['arctic_jblackburn' ].name = 'arctic_jblackburn'
97
+ store ._conn ['arctic_jblackburn' ].command .return_value = mock_conn_info_empty
98
+ store ['jblackburn.library' ]
99
+
100
+ assert store ._conn ['arctic_jblackburn' ].command .call_args_list == [call ({'connectionStatus' : 1 })]
101
+ assert ga .call_args_list == [call ('cluster' , 'arctic' , 'arctic_jblackburn' ),
102
+ call ('cluster' , 'arctic' , store ._adminDB .name )]
103
+
104
+
71
105
def test_arctic_connect_hostname ():
72
106
with patch ('pymongo.MongoClient' , return_value = MagicMock (), autospec = True ) as mc , \
73
107
patch ('arctic.arctic.mongo_retry' , autospec = True ) as ar , \
0 commit comments