def test_pipeline_present(self): ''' Test to manage a elasticsearch pipeline. ''' name = 'foo' pipeline = {name: {"test": "key"}} ret = {'name': name, 'result': True, 'comment': 'Pipeline foo is already present', 'changes': {}} mock_get = MagicMock(side_effect=[pipeline, pipeline, None, None, None, pipeline, CommandExecutionError, None]) mock_create = MagicMock(side_effect=[True, True, False, CommandExecutionError]) with patch.dict(elasticsearch.__salt__, {'elasticsearch.pipeline_get': mock_get, 'elasticsearch.pipeline_create': mock_create}): self.assertDictEqual(elasticsearch.pipeline_present(name, {"test": "key"}), ret) ret.update({'comment': "Successfully replaced pipeline foo", 'changes': {'old': {"test": "key"}, 'new': {"test2": "key"}}}) self.assertDictEqual(elasticsearch.pipeline_present(name, {"test2": "key"}), ret) ret.update({'comment': "Successfully created pipeline foo", 'changes': {'new': {"test2": "key"}}}) self.assertDictEqual(elasticsearch.pipeline_present(name, {"test2": "key"}), ret) ret.update({'comment': 'Cannot create pipeline foo, False', 'result': False}) self.assertDictEqual(elasticsearch.pipeline_present(name, {"test2": "key"}), ret) with patch.dict(elasticsearch.__opts__, {'test': True}): ret.update({'comment': "Pipeline foo does not exist and will be created", 'result': None, 'changes': {'new': {"test2": "key"}}}) self.assertDictEqual(elasticsearch.pipeline_present(name, {"test2": "key"}), ret) ret.update({'comment': "Pipeline foo exists with wrong configuration and will be overriden", 'result': None, 'changes': {'old': {"test": "key"}, 'new': {"test2": "key"}}}) self.assertDictEqual(elasticsearch.pipeline_present(name, {"test2": "key"}), ret) ret.update({'comment': '', 'result': False, 'changes': {}}) self.assertDictEqual(elasticsearch.pipeline_present(name, {}), ret) ret.update({'comment': '', 'result': False, 'changes': {}}) self.assertDictEqual(elasticsearch.pipeline_present(name, {}), ret)
def test_pipeline_present(): """ Test to manage a elasticsearch pipeline. """ name = "foo" pipeline = {name: {"test": "key"}} ret = { "name": name, "result": True, "comment": "Pipeline foo is already present", "changes": {}, } mock_get = MagicMock(side_effect=[ pipeline, pipeline, None, None, None, pipeline, CommandExecutionError, None, ]) mock_create = MagicMock( side_effect=[True, True, False, CommandExecutionError]) with patch.dict( elasticsearch.__salt__, { "elasticsearch.pipeline_get": mock_get, "elasticsearch.pipeline_create": mock_create, }, ): assert elasticsearch.pipeline_present(name, {"test": "key"}) == ret ret.update({ "comment": "Successfully replaced pipeline foo", "changes": { "old": { "test": "key" }, "new": { "test2": "key" } }, }) assert elasticsearch.pipeline_present(name, {"test2": "key"}) == ret ret.update({ "comment": "Successfully created pipeline foo", "changes": { "new": { "test2": "key" } }, }) assert elasticsearch.pipeline_present(name, {"test2": "key"}) == ret ret.update({ "comment": "Cannot create pipeline foo, False", "result": False }) assert elasticsearch.pipeline_present(name, {"test2": "key"}) == ret with patch.dict(elasticsearch.__opts__, {"test": True}): ret.update({ "comment": "Pipeline foo does not exist and will be created", "result": None, "changes": { "new": { "test2": "key" } }, }) assert elasticsearch.pipeline_present(name, {"test2": "key"}) == ret ret.update({ "comment": ("Pipeline foo exists with wrong configuration and will be" " overridden"), "result": None, "changes": { "old": { "test": "key" }, "new": { "test2": "key" } }, }) assert elasticsearch.pipeline_present(name, {"test2": "key"}) == ret ret.update({"comment": "", "result": False, "changes": {}}) assert elasticsearch.pipeline_present(name, {}) == ret ret.update({"comment": "", "result": False, "changes": {}}) assert elasticsearch.pipeline_present(name, {}) == ret