def test_absent(self): ''' Test to ensure that the named database is absent. ''' name = 'main' version = '9.4' ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''} mock_t = MagicMock(return_value=True) mock = MagicMock(side_effect=[True, True, False]) with patch.dict(postgres_cluster.__salt__, {'postgres.cluster_exists': mock, 'postgres.cluster_remove': mock_t}): with patch.dict(postgres_cluster.__opts__, {'test': True}): comt = ('Cluster {0}/{1} is set to be removed'.format(version, name)) ret.update({'comment': comt, 'result': None}) self.assertDictEqual(postgres_cluster.absent(version, name), ret) with patch.dict(postgres_cluster.__opts__, {'test': False}): comt = ('Cluster {0}/{1} has been removed'.format(version, name)) ret.update({'comment': comt, 'result': True, 'changes': {name: 'Absent'}}) self.assertDictEqual(postgres_cluster.absent(version, name), ret) comt = ('Cluster {0}/{1} is not present, so it cannot be removed' .format(version, name)) ret.update({'comment': comt, 'result': True, 'changes': {}}) self.assertDictEqual(postgres_cluster.absent(version, name), ret)
def test_absent(self): """ Test to ensure that the named database is absent. """ name = "main" version = "9.4" ret = {"name": name, "changes": {}, "result": False, "comment": ""} mock_t = MagicMock(return_value=True) mock = MagicMock(side_effect=[True, True, False]) with patch.dict( postgres_cluster.__salt__, { "postgres.cluster_exists": mock, "postgres.cluster_remove": mock_t }, ): with patch.dict(postgres_cluster.__opts__, {"test": True}): comt = "Cluster {0}/{1} is set to be removed".format( version, name) ret.update({"comment": comt, "result": None}) self.assertDictEqual(postgres_cluster.absent(version, name), ret) with patch.dict(postgres_cluster.__opts__, {"test": False}): comt = "Cluster {0}/{1} has been removed".format(version, name) ret.update({ "comment": comt, "result": True, "changes": { name: "Absent" } }) self.assertDictEqual(postgres_cluster.absent(version, name), ret) comt = "Cluster {0}/{1} is not present, so it cannot be removed".format( version, name) ret.update({"comment": comt, "result": True, "changes": {}}) self.assertDictEqual(postgres_cluster.absent(version, name), ret)