def test_index_template_absent(self): ''' Test to manage a elasticsearch index template. ''' name = 'foo' index_template = {name: {"test": "key"}} ret = {'name': name, 'result': True, 'comment': 'Index template foo is already absent', 'changes': {}} mock_get = MagicMock(side_effect=[None, {"bar": {}}, index_template, index_template, index_template, CommandExecutionError, index_template]) mock_delete = MagicMock(side_effect=[True, False, CommandExecutionError]) with patch.dict(elasticsearch.__salt__, {'elasticsearch.index_template_get': mock_get, 'elasticsearch.index_template_delete': mock_delete}): self.assertDictEqual(elasticsearch.index_template_absent(name), ret) self.assertDictEqual(elasticsearch.index_template_absent(name), ret) ret.update({'comment': 'Successfully removed index template foo', 'changes': {"old": {"test": "key"}}}) self.assertDictEqual(elasticsearch.index_template_absent(name), ret) ret.update({'comment': 'Failed to remove index template foo for unknown reasons', 'result': False, 'changes': {}}) self.assertDictEqual(elasticsearch.index_template_absent(name), ret) with patch.dict(elasticsearch.__opts__, {'test': True}): ret.update({'comment': "Index template foo will be removed", 'result': None, 'changes': {"old": {"test": "key"}}}) self.assertDictEqual(elasticsearch.index_template_absent(name), ret) ret.update({'comment': '', 'result': False, 'changes': {}}) self.assertDictEqual(elasticsearch.index_template_absent(name), ret) ret.update({'comment': '', 'result': False, 'changes': {}}) self.assertDictEqual(elasticsearch.index_template_absent(name), ret)
def test_index_template_absent(): """ Test to manage a elasticsearch index template. """ name = "foo" index_template = {name: {"test": "key"}} ret = { "name": name, "result": True, "comment": "Index template foo is already absent", "changes": {}, } mock_get = MagicMock(side_effect=[ None, { "bar": {} }, index_template, index_template, index_template, CommandExecutionError, index_template, ]) mock_delete = MagicMock(side_effect=[True, False, CommandExecutionError]) with patch.dict( elasticsearch.__salt__, { "elasticsearch.index_template_get": mock_get, "elasticsearch.index_template_delete": mock_delete, }, ): assert elasticsearch.index_template_absent(name) == ret assert elasticsearch.index_template_absent(name) == ret ret.update({ "comment": "Successfully removed index template foo", "changes": { "old": { "test": "key" } }, }) assert elasticsearch.index_template_absent(name) == ret ret.update({ "comment": "Failed to remove index template foo for unknown reasons", "result": False, "changes": {}, }) assert elasticsearch.index_template_absent(name) == ret with patch.dict(elasticsearch.__opts__, {"test": True}): ret.update({ "comment": "Index template foo will be removed", "result": None, "changes": { "old": { "test": "key" } }, }) assert elasticsearch.index_template_absent(name) == ret ret.update({"comment": "", "result": False, "changes": {}}) assert elasticsearch.index_template_absent(name) == ret ret.update({"comment": "", "result": False, "changes": {}}) assert elasticsearch.index_template_absent(name) == ret