def test_calls_get_alias(self, mock_get_alias, mock_es_alias): with self.assertRaises(RequestError): create_or_update_index(self.configuration, {}) mock_es_alias.from_configuration.assert_called_once_with( configuration=self.configuration) mock_get_alias.assert_called_once_with( mock_es_alias.from_configuration.return_value)
def test_calls_get_current_index_if_alias_exists( self, mock_es, mock_get_current_and_next_index): mock_es.indices.exists_alias.return_value = True mock_get_current_and_next_index.return_value = 'a', 'b' create_or_update_index(self.configuration, {}) mock_get_current_and_next_index.assert_called_once_with( f'{settings.ES_INDEX_PREFIX}{self.keyword}_{self.edition}')
def test_calls_create_index_if_alias_exists( self, mock_es, mock_get_current_and_next_index): mock_es.indices.exists_alias.return_value = True mock_get_current_and_next_index.return_value = 'a', 'b' create_or_update_index(self.configuration, {}) mock_es.indices.create.assert_called_once_with( index='b', body=self.default_body)
def test_calls_create_index_if_alias_exists( self, mock_es, mock_get_current_and_next_index): mock_es.indices.exists_alias.return_value = True mock_get_current_and_next_index.return_value = 'a', 'b' create_or_update_index(self.configuration, {}) mock_es.indices.create.assert_called_once_with(index='b', body=self.default_body)
def test_calls_indices_put_alias_if_no_alias(self, mock_es): mock_es.indices.exists_alias.return_value = False mock_es.indices.create.return_value = {'acknowledged': True} create_or_update_index(self.configuration, {}) mock_es.indices.put_alias.assert_called_once_with( index=f'{settings.ES_INDEX_PREFIX}{self.keyword}_{self.edition}_1', name=f'{settings.ES_INDEX_PREFIX}{self.keyword}_{self.edition}')
def test_calls_refresh_indices_if_alias_exists( self, mock_es, mock_get_current_and_next_index, mock_reindex): mock_es.indices.exists_alias.return_value = True mock_es.indices.create.return_value = {'acknowledged': True} mock_get_current_and_next_index.return_value = 'a', 'b' mock_reindex.return_value = 0, [] create_or_update_index(self.configuration, {}) mock_es.indices.refresh.assert_called_once_with(index='b')
def test_calls_put_alias_if_alias_exists( self, mock_es, mock_get_current_and_next_index, mock_reindex): mock_es.indices.exists_alias.return_value = True mock_es.indices.create.return_value = {'acknowledged': True} mock_get_current_and_next_index.return_value = 'a', 'b' mock_reindex.return_value = 0, [] create_or_update_index(self.configuration, {}) mock_es.indices.put_alias.assert_called_once_with( index='b', name=f'{settings.ES_INDEX_PREFIX}{self.keyword}_{self.edition}')
def test_creates_new_index(self, mock_get_alias): alias = uuid.uuid4() alias_prefixed = '{}{}'.format(settings.ES_INDEX_PREFIX, alias) mock_get_alias.return_value = alias_prefixed index = '{}{}_1'.format(settings.ES_INDEX_PREFIX, alias) self.assertFalse(es.indices.exists_alias(name=alias_prefixed)) self.assertFalse(es.indices.exists(index=index)) create_or_update_index(self.configuration, {}) self.assertTrue(es.indices.exists_alias(name=alias_prefixed)) self.assertTrue(es.indices.exists(index=index)) es.indices.delete(index=index)
def test_calls_delete_alias_if_alias_exists( self, mock_es, mock_get_current_and_next_index, mock_reindex): mock_es.indices.exists_alias.return_value = True mock_es.indices.create.return_value = {'acknowledged': True} mock_get_current_and_next_index.return_value = 'a', 'b' mock_reindex.return_value = 0, [] mock_es.indices.put_alias.return_value = {'acknowledged': True} create_or_update_index(self.configuration, {}) mock_es.indices.delete_alias.assert_called_once_with( index='a', name=f'{settings.ES_INDEX_PREFIX}{self.keyword}_{self.edition}')
def test_returns_correct_values(self): success, logs, error_msg = create_or_update_index(self.configuration, {}) self.assertIsInstance(success, bool) self.assertTrue(success) self.assertIsInstance(logs, list) self.assertEqual(len(logs), 3) self.assertEqual(error_msg, '')
def test_returns_correct_values(self): success, logs, error_msg = create_or_update_index( self.configuration, {}) self.assertIsInstance(success, bool) self.assertTrue(success) self.assertIsInstance(logs, list) self.assertEqual(len(logs), 3) self.assertEqual(error_msg, '')
def create_temp_indices(configuration_list: list): """ For each index, create the index and update it with the questionnaires of the corresponding configuration as found in the database. Make sure to override the settings and use a custom prefix for the indices. Args: ``configuration_list`` (list): A list of tuples containing the configurations for which a ES index shall be created and consisting of - [0]: code of the configuration - [1]: edition of the configuration """ for code, edition in configuration_list: mappings = get_mappings() create_or_update_index(get_configuration(code=code, edition=edition), mappings) put_questionnaire_data(Questionnaire.with_status.public().filter( configuration__code=code))
def create_temp_indices(configuration_list: list): """ For each index, create the index and update it with the questionnaires of the corresponding configuration as found in the database. Make sure to override the settings and use a custom prefix for the indices. Args: ``configuration_list`` (list): A list of tuples containing the configurations for which a ES index shall be created and consisting of - [0]: code of the configuration - [1]: edition of the configuration """ for code, edition in configuration_list: mappings = get_mappings() create_or_update_index( get_configuration(code=code, edition=edition), mappings) put_questionnaire_data( Questionnaire.with_status.public().filter(configuration__code=code) )
def test_calls_indices_exists_alias(self, mock_es): create_or_update_index(self.configuration, {}) mock_es.indices.exists_alias.assert_called_once_with( name=f'{settings.ES_INDEX_PREFIX}{self.keyword}_{self.edition}')
def test_calls_indices_create_if_no_alias(self, mock_es): mock_es.indices.exists_alias.return_value = False create_or_update_index(self.configuration, {}) mock_es.indices.create.assert_called_once_with( index=f'{settings.ES_INDEX_PREFIX}{self.keyword}_{self.edition}_1', body=self.default_body)