コード例 #1
0
 def setUp(self):
     # Initialize functional test framework
     self.app = webtest.TestApp(self.router)
     self.logout()
     if not os.path.exists(temporaryFolder):
         os.mkdir(temporaryFolder)
     # Reset users
     word = "Спасибо1".decode("utf-8")
     self.userS = {"username": word, "password": word, "nickname": word, "email": word + "@example.com"}
     self.userN = dict((key, value.replace("1", "2")) for key, value in self.userS.iteritems())
     for userIndex, valueByKey in enumerate([self.userS, self.userN], 1):
         username, password, nickname, email = [
             valueByKey.get(x) for x in "username", "password", "nickname", "email"
         ]
         db.merge(
             User(
                 id=userIndex,
                 username=username,
                 password_=hash(password),
                 nickname=nickname,
                 email=email,
                 is_super=userIndex % 2,
             )
         )
     transaction.commit()
コード例 #2
0
def apply_user_(ticket):
    'Finalize a change to a user account'
    # Load
    user_ = db.query(User_).filter(
        (User_.ticket == ticket) & 
        (User_.when_expired >= datetime.datetime.utcnow())).first()
    # If the ticket is valid,
    if user_:
        # Apply the change and reset rejection_count
        db.merge(User(
            id=user_.user_id,
            username=user_.username,
            password_=user_.password_,
            nickname=user_.nickname,
            email=user_.email,
            rejection_count=0))
    # Return
    return user_