def test_present_table(self): ''' Test present ''' with patch.dict(postgres_privileges.__salt__, {'postgres.has_privileges': self.mock_true}): comt = 'The requested privilege(s) are already set' self.ret.update({'comment': comt, 'result': True}) self.assertDictEqual( postgres_privileges.present( self.name, self.table_name, 'table'), self.ret) with patch.dict(postgres_privileges.__salt__, {'postgres.has_privileges': self.mock_false, 'postgres.privileges_grant': self.mock_true}): with patch.dict(postgres_privileges.__opts__, {'test': True}): comt = ('The privilege(s): {0} are' ' set to be granted to {1}').format('ALL', self.name) self.ret.update({'comment': comt, 'result': None}) self.assertDictEqual( postgres_privileges.present(self.name, self.table_name, 'table', privileges=['ALL']), self.ret) with patch.dict(postgres_privileges.__opts__, {'test': False}): comt = ('The privilege(s): {0} have ' 'been granted to {1}').format('ALL', self.name) self.ret.update({'comment': comt, 'result': True, 'changes': {'baruwa': 'Present'}}) self.assertDictEqual( postgres_privileges.present(self.name, self.table_name, 'table', privileges=['ALL']), self.ret)
def test_present_group(self): ''' Test present group ''' with patch.dict( postgres_privileges.__salt__, { 'postgres.has_privileges': self.mock_false, 'postgres.privileges_grant': self.mock_true }): with patch.dict(postgres_privileges.__opts__, {'test': True}): comt = ('The privilege(s): {0} are' ' set to be granted to {1}').format( self.group_name, self.name) self.ret.update({'comment': comt, 'result': None}) self.assertDictEqual( postgres_privileges.present(self.name, self.group_name, 'group'), self.ret) with patch.dict(postgres_privileges.__opts__, {'test': False}): comt = ('The privilege(s): {0} have ' 'been granted to {1}').format(self.group_name, self.name) self.ret.update({ 'comment': comt, 'result': True, 'changes': { 'baruwa': 'Present' } }) self.assertDictEqual( postgres_privileges.present(self.name, self.group_name, 'group'), self.ret)
def test_present_group(): """ Test present group """ group_name = "admins" name = "baruwa" ret = {"name": name, "changes": {}, "result": False, "comment": ""} mock_true = MagicMock(return_value=True) mock_false = MagicMock(return_value=False) with patch.dict( postgres_privileges.__salt__, { "postgres.has_privileges": mock_false, "postgres.privileges_grant": mock_true, }, ): with patch.dict(postgres_privileges.__opts__, {"test": True}): comt = "The privilege(s): {} are set to be granted to {}".format( group_name, name) ret.update({"comment": comt, "result": None}) assert postgres_privileges.present(name, group_name, "group") == ret with patch.dict(postgres_privileges.__opts__, {"test": False}): comt = "The privilege(s): {} have been granted to {}".format( group_name, name) ret.update({ "comment": comt, "result": True, "changes": { "baruwa": "Present" } }) assert postgres_privileges.present(name, group_name, "group") == ret
def test_present_group(self): ''' Test present group ''' with patch.dict(postgres_privileges.__salt__, {'postgres.has_privileges': self.mock_false, 'postgres.privileges_grant': self.mock_true}): with patch.dict(postgres_privileges.__opts__, {'test': True}): comt = ('The privilege(s): {0} are' ' set to be granted to {1}').format(self.group_name, self.name) self.ret.update({'comment': comt, 'result': None}) self.assertDictEqual( postgres_privileges.present(self.name, self.group_name, 'group'), self.ret) with patch.dict(postgres_privileges.__opts__, {'test': False}): comt = ('The privilege(s): {0} have ' 'been granted to {1}').format(self.group_name, self.name) self.ret.update({'comment': comt, 'result': True, 'changes': {'baruwa': 'Present'}}) self.assertDictEqual( postgres_privileges.present(self.name, self.group_name, 'group'), self.ret)
def test_present_table(self): ''' Test present ''' with patch.dict(postgres_privileges.__salt__, {'postgres.has_privileges': self.mock_true}): comt = 'The requested privilege(s) are already set' self.ret.update({'comment': comt, 'result': True}) self.assertDictEqual( postgres_privileges.present( self.name, self.table_name, 'table'), self.ret) with patch.dict(postgres_privileges.__salt__, {'postgres.has_privileges': self.mock_false, 'postgres.privileges_grant': self.mock_true}): with patch.dict(postgres_privileges.__opts__, {'test': True}): comt = ('The privilege(s): {0} are' ' set to be granted to {1}').format('ALL', self.name) self.ret.update({'comment': comt, 'result': None}) self.assertDictEqual( postgres_privileges.present(self.name, self.table_name, 'table', privileges=['ALL']), self.ret) with patch.dict(postgres_privileges.__opts__, {'test': False}): comt = ('The privilege(s): {0} have ' 'been granted to {1}').format('ALL', self.name) self.ret.update({'comment': comt, 'result': True, 'changes': {'baruwa': 'Present'}}) self.assertDictEqual( postgres_privileges.present(self.name, self.table_name, 'table', privileges=['ALL']), self.ret)
def test_present_table(self): """ Test present """ with patch.dict(postgres_privileges.__salt__, {"postgres.has_privileges": self.mock_true}): comt = "The requested privilege(s) are already set" self.ret.update({"comment": comt, "result": True}) self.assertDictEqual( postgres_privileges.present(self.name, self.table_name, "table"), self.ret, ) with patch.dict( postgres_privileges.__salt__, { "postgres.has_privileges": self.mock_false, "postgres.privileges_grant": self.mock_true, }, ): with patch.dict(postgres_privileges.__opts__, {"test": True}): comt = ("The privilege(s): {0} are" " set to be granted to {1}").format("ALL", self.name) self.ret.update({"comment": comt, "result": None}) self.assertDictEqual( postgres_privileges.present(self.name, self.table_name, "table", privileges=["ALL"]), self.ret, ) with patch.dict(postgres_privileges.__opts__, {"test": False}): comt = ("The privilege(s): {0} have " "been granted to {1}").format("ALL", self.name) self.ret.update({ "comment": comt, "result": True, "changes": { "baruwa": "Present" } }) self.assertDictEqual( postgres_privileges.present(self.name, self.table_name, "table", privileges=["ALL"]), self.ret, )
def test_present_table(): """ Test present """ table_name = "awl" name = "baruwa" ret = {"name": name, "changes": {}, "result": False, "comment": ""} mock_true = MagicMock(return_value=True) mock_false = MagicMock(return_value=False) with patch.dict(postgres_privileges.__salt__, {"postgres.has_privileges": mock_true}): comt = "The requested privilege(s) are already set" ret.update({"comment": comt, "result": True}) assert postgres_privileges.present(name, table_name, "table") == ret with patch.dict( postgres_privileges.__salt__, { "postgres.has_privileges": mock_false, "postgres.privileges_grant": mock_true, }, ): with patch.dict(postgres_privileges.__opts__, {"test": True}): comt = "The privilege(s): {} are set to be granted to {}".format( "ALL", name) ret.update({"comment": comt, "result": None}) assert (postgres_privileges.present(name, table_name, "table", privileges=["ALL"]) == ret) with patch.dict(postgres_privileges.__opts__, {"test": False}): comt = "The privilege(s): {} have been granted to {}".format( "ALL", name) ret.update({ "comment": comt, "result": True, "changes": { "baruwa": "Present" } }) assert (postgres_privileges.present(name, table_name, "table", privileges=["ALL"]) == ret)