Exemplo n.º 1
0
async def register_user(username: str, password: str):
    if db.query(User).filter(User.username == username).first():
        raise HTTPException(status_code=409, detail='Username already exists')
    user = User(username, pwd_context.hash(password))
    db.add(user)
    db.commit()
    return Response('Created User.', 201)
Exemplo n.º 2
0
def test_authenticate_user_wrong_user(example_user):
    example_user.hashed_password = pwd_context.hash('bababa')

    with patch('app.auth.get_user', return_value=None):
        user = authenticate_user(Mock(),
                                 email=example_user.email,
                                 password='******')

    assert user is False
Exemplo n.º 3
0
def example_user():
    return User(email='*****@*****.**',
                username='******',
                hashed_password=pwd_context.hash('passwd'))