def test_elasticsearch_index_creation_should_failed_when_no_index_is_provided(
     self, elasticsearch_mock
 ):
     interface = ElasticSearchInterface(["127.0.0.1"])
     interface._es.indices = MagicMock()
     interface._es.indices.exists = MagicMock()
     with self.assertRaisesRegex(Exception, "Index name not defined"):
         interface.create_index()
 def test_elasticsearch_index_creation_should_check_if_index_exists(
     self, elasticsearch_mock
 ):
     interface = ElasticSearchInterface(["127.0.0.1"])
     interface._es.indices = MagicMock()
     interface._es.indices.exists = MagicMock()
     interface.create_index("querido-diario")
     interface._es.indices.exists.assert_called_once_with(index="querido-diario")
 def test_elasticsearch_index_creation_should_not_recreate_index_if_it_exists(
     self, elasticsearch_mock
 ):
     interface = ElasticSearchInterface(["127.0.0.1"])
     interface._es.indices = MagicMock()
     interface._es.indices.exists = MagicMock(return_value=True)
     interface._es.indices.create = MagicMock()
     interface.create_index("querido-diario")
     interface._es.indices.exists.assert_called_once_with(index="querido-diario")
     interface._es.indices.create.assert_not_called()
 def test_elasticsearch_index_creation_with_default_index_value(
     self, elasticsearch_mock
 ):
     interface = ElasticSearchInterface(
         ["127.0.0.1"], default_index="querido-diario2"
     )
     interface._es.indices = MagicMock()
     interface._es.indices.exists = MagicMock()
     interface.create_index()
     interface._es.indices.exists.assert_called_once_with(index="querido-diario2")
 def test_elasticsearch_index_should_allow_change_default_timeout(
     self, elasticsearch_mock
 ):
     interface = ElasticSearchInterface(["127.0.0.1"], timeout="2m")
     interface._es.indices = MagicMock()
     interface._es.indices.exists = MagicMock(return_value=False)
     interface._es.indices.create = MagicMock()
     interface.create_index("querido-diario")
     interface._es.indices.create.assert_called_once_with(
         index="querido-diario",
         body={"mappings": {"properties": {"date": {"type": "date"}}}},
         timeout="2m",
     )
 def test_elasticsearch_should_create_index_if_it_does_not_exists(
     self, elasticsearch_mock
 ):
     interface = ElasticSearchInterface(["127.0.0.1"])
     interface._es.indices = MagicMock()
     interface._es.indices.exists = MagicMock(return_value=False)
     interface._es.indices.create = MagicMock()
     interface.create_index("querido-diario")
     interface._es.indices.exists.assert_called_once_with(index="querido-diario")
     interface._es.indices.create.assert_called_once_with(
         index="querido-diario",
         body={"mappings": {"properties": {"date": {"type": "date"}}}},
         timeout="30s",
     )
 def test_elasticsearch_should_create_index_with_default_value_with_function_has_no_arguments(
     self, elasticsearch_mock
 ):
     interface = ElasticSearchInterface(
         ["127.0.0.1"], default_index="querido-diario2"
     )
     interface._es.indices = MagicMock()
     interface._es.indices.exists = MagicMock(return_value=False)
     interface._es.indices.create = MagicMock()
     interface.create_index()
     interface._es.indices.exists.assert_called_once_with(index="querido-diario2")
     interface._es.indices.create.assert_called_once_with(
         index="querido-diario2",
         body={"mappings": {"properties": {"date": {"type": "date"}}}},
         timeout="30s",
     )
    def test_index_creation(self):
        self.delete_index("querido-diario")

        interface = ElasticSearchInterface(["127.0.0.1"], timeout="5m")
        interface.create_index("querido-diario")
        self.assertTrue(self._es.indices.exists("querido-diario"))