@@ -108,19 +108,23 @@ def test_clear_and_create_index(mocked_es, object_type, skip_mapping, already_ex
108108
109109@pytest .mark .parametrize ("object_type" , [COURSE_TYPE , PROGRAM_TYPE ])
110110@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 ):
112113 """
113114 switch_indices should atomically remove the old backing index
114115 for the default alias and replace it with the new one
115116 """
117+ mock_log = mocker .patch ("learning_resources_search.indexing_api.log.warning" )
116118 refresh_mock = mocker .patch (
117119 "learning_resources_search.indexing_api.refresh_index" , autospec = True
118120 )
119121 conn_mock = mocked_es .conn
120122 conn_mock .indices .exists_alias .return_value = default_exists
121123 old_backing_index = "old_backing"
122124 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+ )
124128 backing_index = "backing"
125129 switch_indices (backing_index , object_type )
126130
@@ -155,6 +159,10 @@ def test_switch_indices(mocked_es, mocker, default_exists, object_type):
155159 conn_mock .indices .delete_alias .assert_called_once_with (
156160 name = get_reindexing_alias_name (object_type ), index = backing_index
157161 )
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 ()
158166
159167
160168@pytest .mark .parametrize ("temp_alias_exists" , [True , False ])
0 commit comments