def test_absent(self): """ Test to ensure that the named user is absent. """ name = "frank_exampledb" ret = {"name": name, "result": True, "comment": "", "changes": {}} mock = MagicMock(side_effect=[True, True, True, False, False, False]) mock_t = MagicMock(side_effect=[True, False]) mock_str = MagicMock(return_value="salt") mock_none = MagicMock(return_value=None) with patch.dict( mysql_user.__salt__, { "mysql.user_exists": mock, "mysql.user_remove": mock_t }, ): with patch.dict(mysql_user.__opts__, {"test": True}): comt = "User frank_exampledb@localhost is set to be removed" ret.update({"comment": comt, "result": None}) self.assertDictEqual(mysql_user.absent(name), ret) with patch.dict(mysql_user.__opts__, {"test": False}): comt = "User frank_exampledb@localhost has been removed" ret.update({ "comment": comt, "result": True, "changes": { "frank_exampledb": "Absent" }, }) self.assertDictEqual(mysql_user.absent(name), ret) with patch.object(mysql_user, "_get_mysql_error", mock_str): comt = "User frank_exampledb@localhost has been removed" ret.update({ "comment": "salt", "result": False, "changes": {} }) self.assertDictEqual(mysql_user.absent(name), ret) comt = "User frank_exampledb@localhost has been removed" ret.update({"comment": "salt"}) self.assertDictEqual(mysql_user.absent(name), ret) with patch.object(mysql_user, "_get_mysql_error", mock_none): comt = ("User frank_exampledb@localhost is not present," " so it cannot be removed") ret.update({ "comment": comt, "result": True, "changes": {} }) self.assertDictEqual(mysql_user.absent(name), ret)
def test_absent(self): ''' Test to ensure that the named user is absent. ''' name = 'frank_exampledb' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=[True, True, True, False, False, False]) mock_t = MagicMock(side_effect=[True, False]) mock_str = MagicMock(return_value='salt') mock_none = MagicMock(return_value=None) with patch.dict(mysql_user.__salt__, { 'mysql.user_exists': mock, 'mysql.user_remove': mock_t }): with patch.dict(mysql_user.__opts__, {'test': True}): comt = ('User frank_exampledb@localhost is set to be removed') ret.update({'comment': comt, 'result': None}) self.assertDictEqual(mysql_user.absent(name), ret) with patch.dict(mysql_user.__opts__, {'test': False}): comt = ('User frank_exampledb@localhost has been removed') ret.update({ 'comment': comt, 'result': True, 'changes': { 'frank_exampledb': 'Absent' } }) self.assertDictEqual(mysql_user.absent(name), ret) with patch.object(mysql_user, '_get_mysql_error', mock_str): comt = ('User frank_exampledb@localhost has been removed') ret.update({ 'comment': 'salt', 'result': False, 'changes': {} }) self.assertDictEqual(mysql_user.absent(name), ret) comt = ('User frank_exampledb@localhost has been removed') ret.update({'comment': 'salt'}) self.assertDictEqual(mysql_user.absent(name), ret) with patch.object(mysql_user, '_get_mysql_error', mock_none): comt = ('User frank_exampledb@localhost is not present,' ' so it cannot be removed') ret.update({ 'comment': comt, 'result': True, 'changes': {} }) self.assertDictEqual(mysql_user.absent(name), ret)
def test_absent(self): ''' Test to ensure that the named user is absent. ''' name = 'frank_exampledb' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=[True, True, True, False, False, False]) mock_t = MagicMock(side_effect=[True, False]) mock_str = MagicMock(return_value='salt') mock_none = MagicMock(return_value=None) with patch.dict(mysql_user.__salt__, {'mysql.user_exists': mock, 'mysql.user_remove': mock_t}): with patch.dict(mysql_user.__opts__, {'test': True}): comt = ('User frank_exampledb@localhost is set to be removed') ret.update({'comment': comt, 'result': None}) self.assertDictEqual(mysql_user.absent(name), ret) with patch.dict(mysql_user.__opts__, {'test': False}): comt = ('User frank_exampledb@localhost has been removed') ret.update({'comment': comt, 'result': True, 'changes': {'frank_exampledb': 'Absent'}}) self.assertDictEqual(mysql_user.absent(name), ret) with patch.object(mysql_user, '_get_mysql_error', mock_str): comt = ('User frank_exampledb@localhost has been removed') ret.update({'comment': 'salt', 'result': False, 'changes': {}}) self.assertDictEqual(mysql_user.absent(name), ret) comt = ('User frank_exampledb@localhost has been removed') ret.update({'comment': 'salt'}) self.assertDictEqual(mysql_user.absent(name), ret) with patch.object(mysql_user, '_get_mysql_error', mock_none): comt = ('User frank_exampledb@localhost is not present,' ' so it cannot be removed') ret.update({'comment': comt, 'result': True, 'changes': {}}) self.assertDictEqual(mysql_user.absent(name), ret)