def test_grplist_add_no_admin(self):
     self.context.session.assertPerm.side_effect = koji.GenericError
     with self.assertRaises(koji.GenericError):
         kojihub.grplist_add('tag', 'group')
     self.context.session.assertPerm.assert_called_once_with('tag')
     self.assertEqual(len(self.inserts), 0)
     self.assertEqual(len(self.updates), 0)
 def test_grplist_add_no_admin(self):
     self.context.session.assertPerm.side_effect = koji.GenericError
     with self.assertRaises(koji.GenericError):
         kojihub.grplist_add('tag', 'group')
     self.context.session.assertPerm.assert_called_once_with('admin')
     self.assertEqual(len(self.inserts), 0)
     self.assertEqual(len(self.updates), 0)
Ejemplo n.º 3
0
    def test_grplist_add(self):
        tag = 'tag'
        group = 'group'
        self.get_tag.return_value = {'name': 'tag', 'id': 'tag_id'}
        self.lookup_group.return_value = {'name': 'group', 'id': 'group_id'}
        self.get_tag_groups.return_value = {}
        self.context.event_id = 42
        self.context.session.user_id = 24

        kojihub.grplist_add(tag, group)

        # what was called
        self.context.session.assertPerm.assert_called_once_with('tag')
        self.get_tag.assert_called_once_with(tag, strict=True)
        self.lookup_group.assert_called_once_with(group, create=True)
        self.get_tag_groups.assert_called_with('tag_id',
                                               inherit=True,
                                               incl_pkgs=False,
                                               incl_reqs=False)
        # db
        # revoke
        self.assertEqual(len(self.updates), 1)
        update = self.updates[0]
        self.assertEqual(update.table, 'group_config')
        self.assertEqual(update.data, {'revoke_event': 42, 'revoker_id': 24})
        self.assertEqual(update.rawdata, {'active': 'NULL'})
        # insert new group
        self.assertEqual(len(self.inserts), 1)
        insert = self.inserts[0]
        values = {
            'display_name': 'group',
            'biarchonly': False,
            'exported': True,
            'uservisible': True,
            'create_event': 42,
            'creator_id': 24,
            'tag_id': 'tag_id',
            'group_id': 'group_id',
            'blocked': False,
        }
        self.assertEqual(insert.table, 'group_config')
        self.assertEqual(insert.data, values)
        self.assertEqual(insert.rawdata, {})
    def test_grplist_add(self):
        tag = 'tag'
        group = 'group'
        self.get_tag.return_value = {'name': 'tag', 'id': 'tag_id'}
        self.lookup_group.return_value = {'name': 'group', 'id': 'group_id'}
        self.get_tag_groups.return_value = {}
        self.context.event_id = 42
        self.context.session.user_id = 24

        kojihub.grplist_add(tag, group)

        # what was called
        self.context.session.assertPerm.assert_called_once_with('admin')
        self.get_tag.assert_called_once_with(tag, strict=True)
        self.lookup_group.assert_called_once_with(group, create=True)
        self.get_tag_groups.assert_called_with('tag_id', inherit=True,
                incl_pkgs=False, incl_reqs=False)
        # db
        # revoke
        self.assertEqual(len(self.updates), 1)
        update = self.updates[0]
        self.assertEqual(update.table, 'group_config')
        self.assertEqual(update.data, {'revoke_event': 42, 'revoker_id': 24})
        self.assertEqual(update.rawdata, {'active': 'NULL'})
        # insert new group
        self.assertEqual(len(self.inserts), 1)
        insert = self.inserts[0]
        values = {
            'display_name': 'group',
            'biarchonly': False,
            'exported': True,
            'uservisible': True,
            'create_event': 42,
            'creator_id': 24,
            'tag_id': 'tag_id',
            'group_id': 'group_id',
            'blocked': False,
        }
        self.assertEqual(insert.table, 'group_config')
        self.assertEqual(insert.data, values)
        self.assertEqual(insert.rawdata, {})