Changeset 820 for trunk


Ignore:
Timestamp:
Feb 5, 2016, 9:04:31 AM (4 years ago)
Author:
cito
Message:

Skip test for privileges when running as superuser

It's not possible to test for missing privileges as a superuser
because superusers always have all privileges.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/pg.py

    r818 r820  
    17901790            return regtypes
    17911791
    1792     def has_table_privilege(self, table, privilege='select'):
    1793         """Check whether current user has specified table privilege."""
     1792    def has_table_privilege(self, table, privilege='select', flush=False):
     1793        """Check whether current user has specified table privilege.
     1794
     1795        If flush is set, then the internal cache for table privileges will
     1796        be flushed. This may be necessary after privileges have been changed.
     1797        """
     1798        privileges = self._privileges
     1799        if flush:
     1800            privileges.clear()
     1801            self._do_debug('The privileges cache has been flushed')
    17941802        privilege = privilege.lower()
    17951803        try:  # ask cache
    1796             return self._privileges[(table, privilege)]
     1804            ret = privileges[table, privilege]
    17971805        except KeyError:  # cache miss, ask the database
    17981806            q = "SELECT has_table_privilege(%s, $2)" % (
     
    18001808            q = self.db.query(q, (table, privilege))
    18011809            ret = q.getresult()[0][0] == self._make_bool(True)
    1802             self._privileges[(table, privilege)] = ret  # cache it
    1803             return ret
     1810            privileges[table, privilege] = ret  # cache it
     1811        return ret
    18041812
    18051813    def get(self, table, row, keyname=None):
  • trunk/tests/test_classic_dbwrapper.py

    r817 r820  
    10721072    def testGetAttnamesWithRegtypes(self):
    10731073        get_attnames = self.db.get_attnames
    1074         self.createTable('test_table',
    1075                          ' n int, alpha smallint, beta bool,'
    1076                          ' gamma char(5), tau text, v varchar(3)')
     1074        self.createTable('test_table', 'n int, alpha smallint, beta bool,'
     1075            ' gamma char(5), tau text, v varchar(3)')
    10771076        use_regtypes = self.db.use_regtypes
    10781077        regtypes = use_regtypes()
     
    10901089    def testGetAttnamesWithoutRegtypes(self):
    10911090        get_attnames = self.db.get_attnames
    1092         self.createTable('test_table',
    1093                          ' n int, alpha smallint, beta bool,'
    1094                          ' gamma char(5), tau text, v varchar(3)')
     1091        self.createTable('test_table', 'n int, alpha smallint, beta bool,'
     1092            ' gamma char(5), tau text, v varchar(3)')
    10951093        use_regtypes = self.db.use_regtypes
    10961094        regtypes = use_regtypes()
     
    11511149            self.assertEqual(r, 'i2 i4 i8 d f4 f8 m v4 c4 t')
    11521150        table = 'test table for get_attnames'
    1153         self.createTable(table,
    1154                          ' n int, alpha smallint, v varchar(3),'
    1155                          ' gamma char(5), tau text, beta bool')
     1151        self.createTable(table, 'n int, alpha smallint, v varchar(3),'
     1152                ' gamma char(5), tau text, beta bool')
    11561153        r = get_attnames(table)
    11571154        self.assertIsInstance(r, OrderedDict)
     
    11901187        self.assertEqual(r, 'i2 i4 i8 d f4 f8 m v4 c4 t')
    11911188        table = 'test table for get_attnames'
    1192         self.createTable(table,
    1193                          ' n int, alpha smallint, v varchar(3),'
    1194                          ' gamma char(5), tau text, beta bool')
     1189        self.createTable(table, 'n int, alpha smallint, v varchar(3),'
     1190                ' gamma char(5), tau text, beta bool')
    11951191        r = get_attnames(table)
    11961192        self.assertIsInstance(r, AttrDict)
     
    12161212        self.assertEqual(can('test', 'update'), True)
    12171213        self.assertEqual(can('test', 'delete'), True)
     1214        self.assertRaises(pg.ProgrammingError, can, 'test', 'foobar')
     1215        self.assertRaises(pg.ProgrammingError, can, 'table_does_not_exist')
     1216        r = self.db.query('select rolsuper FROM pg_roles'
     1217            ' where rolname=current_user').getresult()[0][0]
     1218        if not pg.get_bool():
     1219            r = r == 't'
     1220        if r:
     1221            self.skipTest('must not be superuser')
    12181222        self.assertEqual(can('pg_views', 'select'), True)
    12191223        self.assertEqual(can('pg_views', 'delete'), False)
    1220         self.assertRaises(pg.ProgrammingError, can, 'test', 'foobar')
    1221         self.assertRaises(pg.ProgrammingError, can, 'table_does_not_exist')
    12221224
    12231225    def testGet(self):
Note: See TracChangeset for help on using the changeset viewer.