def __call__(self, username, is_locked=False, is_admin=False): """ Create a user with the given username. is_locked - if True, create with a locked password is_admin - if True, grant administrative rights to the user """ couchdb = Server(self.config['couchdb.address']) try: udb = couchdb[self.config['couchdb.users_database']] except: print "Failed to connect to couchdb at %s/%s" % (self.config['couchdb.address'], self.config['couchdb.users_database']) return 1 new_user = User(username=username) if new_user.id in udb: print 'User "%s" already exists' % username return 1 if not is_locked: done = False while(not done): password = getpass(prompt="Password for %s: " % username) password2 = getpass(prompt="Repeat password: "******"Passwords did not match, try again.\n" new_user.set_password(password) if is_admin: new_user.roles = [ROLE_ADMIN] new_user.store(udb) print 'Created user "%s"' % username
def setUp(self): # XXX load it! self.config = {'web.apps': ['radarpost.web.api'], 'web.debug': True, 'web.static_files_url': '/static', 'beaker.session.type': 'memory', 'couchdb.users_database': self.TEST_USERS_DB, 'couchdb.address': 'http://localhost:5984', 'couchdb.prefix': 'radar/' } self.url_gen = URLGenerator(build_routes(self.config), {}) # set-up users database couchdb = get_couchdb_server(self.config) dbname = self.config['couchdb.users_database'] if dbname in couchdb: del couchdb[dbname] self._users_db = couchdb.create(dbname) # create an admin admin = User(username=self.TEST_ADMIN_USER, password=self.TEST_ADMIN_PASSWORD) admin.roles = [ROLE_ADMIN] admin.store(self._users_db)
def setUp(self): self.config = load_test_config() self.url_gen = URLGenerator(build_routes(self.config), {}) # set-up users database couchdb = get_couchdb_server(self.config) dbname = self.config['couchdb.users_database'] if dbname in couchdb: del couchdb[dbname] self._users_db = couchdb.create(dbname) # create an admin admin = User(username=self.config['test.admin_user'], password=self.config['test.admin_password']) admin.roles = [ROLE_ADMIN] admin.store(self._users_db)