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