@@ -108,19 +108,23 @@ def test_clear_and_create_index(mocked_es, object_type, skip_mapping, already_ex
108
108
109
109
@pytest .mark .parametrize ("object_type" , [COURSE_TYPE , PROGRAM_TYPE ])
110
110
@pytest .mark .parametrize ("default_exists" , [True , False ])
111
- def test_switch_indices (mocked_es , mocker , default_exists , object_type ):
111
+ @pytest .mark .parametrize ("alias_exists" , [True , False ])
112
+ def test_switch_indices (mocked_es , mocker , default_exists , alias_exists , object_type ):
112
113
"""
113
114
switch_indices should atomically remove the old backing index
114
115
for the default alias and replace it with the new one
115
116
"""
117
+ mock_log = mocker .patch ("learning_resources_search.indexing_api.log.warning" )
116
118
refresh_mock = mocker .patch (
117
119
"learning_resources_search.indexing_api.refresh_index" , autospec = True
118
120
)
119
121
conn_mock = mocked_es .conn
120
122
conn_mock .indices .exists_alias .return_value = default_exists
121
123
old_backing_index = "old_backing"
122
124
conn_mock .indices .get_alias .return_value .keys .return_value = [old_backing_index ]
123
-
125
+ conn_mock .indices .delete_alias .side_effect = (
126
+ None if alias_exists else NotFoundError ()
127
+ )
124
128
backing_index = "backing"
125
129
switch_indices (backing_index , object_type )
126
130
@@ -155,6 +159,10 @@ def test_switch_indices(mocked_es, mocker, default_exists, object_type):
155
159
conn_mock .indices .delete_alias .assert_called_once_with (
156
160
name = get_reindexing_alias_name (object_type ), index = backing_index
157
161
)
162
+ if not alias_exists :
163
+ mock_log .assert_called_once_with ("Reindex alias not found for %s" , object_type )
164
+ else :
165
+ mock_log .assert_not_called ()
158
166
159
167
160
168
@pytest .mark .parametrize ("temp_alias_exists" , [True , False ])
0 commit comments