def testIsValid(self): config_names = config.GetAll() for config_name in config_names: self.assertTrue(config.IsValid(config_name)) self.assertTrue(config.IsValid(config_name.lower())) self.assertFalse(config.IsValid(config_name.upper())) self.assertFalse(config.IsValid('invalidconfig'))
def Populate(do_it): old_configs = config.GetAll() for key, value in old_configs.iteritems(): if not key.startswith(ROLE_PREFIX): continue user = key[len(ROLE_PREFIX):] if not re.search(r'^[\[email protected]]+$', user): continue print 'Translating perms for %s (%s)' % (user, value) if '@' in user: user = utils.NormalizeEmail(user) for perm in value: if isinstance(perm, basestring): if perm == perms.Role.ADMIN: print '...Granting %s admin permissions' % user if do_it: perms.Grant(user, perms.Role.ADMIN, perms.GLOBAL_TARGET) else: print '...User %s had global permission %s; ignoring' % ( user, perm) elif isinstance(perm, list) and len(perm) == 2: print '...Granting %s permission %s to %s' % (user, perm[0], perm[1]) if do_it: perms.Grant(user, perm[0], perm[1]) else: print '...User %s has unexpected permission %s; ignoring' % ( user, perm)
def testConfig(self): """Tests storage of simple and structured values in Config entities.""" self.assertEquals(None, config.Get('k')) config.Set('k', 'value') self.assertEquals('value', config.Get('k')) config.Set('j', False) self.assertEquals({'k': 'value', 'j': False}, config.GetAll()) config.Set('k', [3, 4, {'a': 'b'}, None]) self.assertEquals([3, 4, {'a': 'b'}, None], config.Get('k')) config.Delete('k') self.assertEquals(None, config.Get('k'))
def Purge(do_it): old_configs = config.GetAll() for key, _ in old_configs.iteritems(): if not key.startswith(ROLE_PREFIX): if key == 'default_publisher_domain': print 'Deleting legacy entry %s' % key if do_it: config.Delete(key) else: print 'Ignoring config %s; not a permission.' % key continue user = key[len(ROLE_PREFIX):] if not re.search(r'^[\[email protected]]+$', user): print 'Deleting bogus entry %s' % key else: print 'Deleting permissions for user %s' % user if do_it: config.Delete(key)
def testGetAll(self): config_names = config.GetAll() self.assertNotEqual(0, len(config_names))