def test_validate_password(): from metrique.utils import validate_password OK = 'helloworld42' BAD1 = 'short' BAD2 = None assert validate_password(OK) == OK for bad in (BAD1, BAD2): try: validate_password(bad) except ValueError: pass else: assert False, "Validated BAD password"
def user_register(self, username, password): # FIXME: enable setting roles at creation time... is_true(bool(username and password), 'username and password required!') u = validate_username(username, self.RESERVED_USERNAMES) p = validate_password(password) logger.info('Registering new user %s' % u) # FIXME: make a generic method which runs list of sql statements s_u = "CREATE USER %s WITH PASSWORD '%s';" % (u, p) s_db = "CREATE DATABASE %s WITH OWNER %s;" % (u, u) cnx = self.engine.connect() # can't run in a transaction... cnx.connection.set_isolation_level(0) if not self.user_exists(username): cnx.execute(s_u) logger.info('User created: %s' % u) else: logger.info('User exists: %s' % u) if not self.db_exists(u): cnx.execute(s_db) logger.info('DB created: %s' % u) else: logger.info('DB exists: %s' % u)