Пример #1
0
def user(app, session, request):
    """Add a test user in the test database."""
    user = User(username='******', email='*****@*****.**',
                password='******', active=True)
    session.add(user)
    session.commit()
    with app.app_context():
        user.auth_token = user.generate_auth_token()
    session.add(user)
    session.commit()

    @request.addfinalizer
    def fin():
        """Delete user from database after test finishes."""
        session.delete(user)
        session.commit()

    return user
def test_plaintext_password_is_the_hashed_one():
    """Testing the class method."""
    user = User(username='******', password='******')
    assert user.is_password_correct('123')
Пример #3
0
def test_user_get_absolute_url(user: User):
    assert user.get_absolute_url() == f"/users/{user.username}/"
Пример #4
0
def verify_token(token):
    """Verify user by token."""
    g.user = User.verify_auth_token(token)
    return g.user is not None