Example #1
0
    def test_get_by_id(self):
        """Get user by ID."""
        user = User('foo', '*****@*****.**')
        user.save()

        retrieved = User.get_by_id(user.id)
        assert retrieved == user
Example #2
0
File: views.py Project: Yehnn/mall
def autoregister():

    choice_str = 'ABCDEFGHJKLNMPQRSTUVWSXYZ'
    username_str = ''
    password_str = ''
    str_time = time.time()
    username_str = 'AU'
    username_str += str(int(int(str_time) * 1.301))
    for i in range(2):
        username_str += random.choice(choice_str)

    for i in range(6):
        password_str += random.choice(choice_str)

    username = username_str
    password = password_str

    user = User.query.filter_by(username=username).first()
    if user is None:
        user = User.create(
            username=username,
            password=password,
            wechat_id=session.get('wechat_user_id', ''),
        )
        login_user(user, True)
    else:
        autoregister()
Example #3
0
 def test_check_password(self):
     """Check password."""
     user = User.create(username='******', email='*****@*****.**',
                        password='******')
     assert user.check_password('foobarbaz123') is True
     assert user.check_password('barfoobaz') is False
Example #4
0
 def test_password_is_nullable(self):
     """Test null password."""
     user = User(username='******', email='*****@*****.**')
     user.save()
     assert user.password is None
Example #5
0
 def test_created_at_defaults_to_datetime(self):
     """Test creation date."""
     user = User(username='******', email='*****@*****.**')
     user.save()
     assert bool(user.created_at)
     assert isinstance(user.created_at, dt.datetime)
Example #6
0
def load_user(user_id):
    """Load user by ID."""
    return User.get_by_id(int(user_id))