def test_alias_absent(self): ''' Test to manage a elasticsearch alias. ''' name = 'foo' index = 'bar' alias = {index: {"aliases": {name: {"test": "key"}}}} ret = {'name': name, 'result': True, 'comment': 'Alias foo for index bar is already absent', 'changes': {}} mock_get = MagicMock(side_effect=[None, {"foo2": {}}, alias, alias, alias, CommandExecutionError, alias]) mock_delete = MagicMock(side_effect=[True, False, CommandExecutionError]) with patch.dict(elasticsearch.__salt__, {'elasticsearch.alias_get': mock_get, 'elasticsearch.alias_delete': mock_delete}): self.assertDictEqual(elasticsearch.alias_absent(name, index), ret) self.assertDictEqual(elasticsearch.alias_absent(name, index), ret) ret.update({'comment': 'Successfully removed alias foo for index bar', 'changes': {"old": {"test": "key"}}}) self.assertDictEqual(elasticsearch.alias_absent(name, index), ret) ret.update({'comment': 'Failed to remove alias foo for index bar for unknown reasons', 'result': False, 'changes': {}}) self.assertDictEqual(elasticsearch.alias_absent(name, index), ret) with patch.dict(elasticsearch.__opts__, {'test': True}): ret.update({'comment': "Alias foo for index bar will be removed", 'result': None, 'changes': {"old": {"test": "key"}}}) self.assertDictEqual(elasticsearch.alias_absent(name, index), ret) ret.update({'comment': '', 'result': False, 'changes': {}}) self.assertDictEqual(elasticsearch.alias_absent(name, index), ret) ret.update({'comment': '', 'result': False, 'changes': {}}) self.assertDictEqual(elasticsearch.alias_absent(name, index), ret)
def test_alias_absent(): """ Test to manage a elasticsearch alias. """ name = "foo" index = "bar" alias = {index: {"aliases": {name: {"test": "key"}}}} ret = { "name": name, "result": True, "comment": "Alias foo for index bar is already absent", "changes": {}, } mock_get = MagicMock(side_effect=[ None, { "foo2": {} }, alias, alias, alias, CommandExecutionError, alias, ]) mock_delete = MagicMock(side_effect=[True, False, CommandExecutionError]) with patch.dict( elasticsearch.__salt__, { "elasticsearch.alias_get": mock_get, "elasticsearch.alias_delete": mock_delete, }, ): assert elasticsearch.alias_absent(name, index) == ret assert elasticsearch.alias_absent(name, index) == ret ret.update({ "comment": "Successfully removed alias foo for index bar", "changes": { "old": { "test": "key" } }, }) assert elasticsearch.alias_absent(name, index) == ret ret.update({ "comment": ("Failed to remove alias foo for index bar for unknown reasons"), "result": False, "changes": {}, }) assert elasticsearch.alias_absent(name, index) == ret with patch.dict(elasticsearch.__opts__, {"test": True}): ret.update({ "comment": "Alias foo for index bar will be removed", "result": None, "changes": { "old": { "test": "key" } }, }) assert elasticsearch.alias_absent(name, index) == ret ret.update({"comment": "", "result": False, "changes": {}}) assert elasticsearch.alias_absent(name, index) == ret ret.update({"comment": "", "result": False, "changes": {}}) assert elasticsearch.alias_absent(name, index) == ret