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