import mock from asf.steve.backends import elastic @mock.patch('elasticsearch.Elasticsearch') def test_init_new(mock_elasticsearch_class): mock_elasticsearch_class.return_value = mock_elasticsearch = mock.MagicMock() mock_elasticsearch.indices = mock_indices= mock.MagicMock() mock_indices.exists.return_value = False elastic.ElasticStorageBackend('pookie.com', 1234, 'http://foo.com', 'true') calls = [mock.call([{'url_prefix': 'http://foo.com', 'use_ssl': True, 'host': 'pookie.com', 'port': 1234}])] mock_elasticsearch_class.assert_has_calls(calls) calls = [mock.call.exists('steve'), mock.call.create(body={'settings': {'number_of_replicas': 1, 'number_of_shards': 3}}, index='steve')] mock_indices.assert_has_calls(calls) @mock.patch('elasticsearch.Elasticsearch') def test_init_exists(mock_elasticsearch_class): mock_elasticsearch_class.return_value = mock_elasticsearch = mock.MagicMock() mock_elasticsearch.indices = mock_indices= mock.MagicMock() mock_indices.exists.return_value = True elastic.ElasticStorageBackend('pookie.com', 1234, 'http://foo.com', 'true') calls = [mock.call([{'url_prefix': 'http://foo.com', 'use_ssl': True, 'host': 'pookie.com', 'port': 1234}])] mock_elasticsearch_class.assert_has_calls(calls) mock_indices.assert_has_calls([])