Exemplo n.º 1
0
 def test_valid_token(self, user_authentication: UserAuthentication,
                      user_entry_squirtle: UserEntry):
     user_token = user_authentication.sign_token(
         user_authentication.login(user_entry_squirtle.email,
                                   "password").dict())
     authorized_user_entry = user_authentication.get_authorized_user(
         user_token)
     assert isinstance(authorized_user_entry, UserEntry)
     assert authorized_user_entry.id == user_entry_squirtle.id
Exemplo n.º 2
0
def login_user(
    form_data: OAuth2PasswordRequestForm = Depends(),
    user_authentication: UserAuthentication = Depends(),
) -> dict:
    try:
        user_token = user_authentication.login(
            email=form_data.username, password=form_data.password
        )
    except InvalidCredentialsException as e:
        raise HTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail="Invalid login credentials.",
        ) from e
    return {
        "access_token": user_authentication.sign_token(user_token.dict()),
        "token_type": "bearer",
    }
Exemplo n.º 3
0
 def test_unknown_user(self, user_authentication: UserAuthentication):
     with pytest.raises(InvalidCredentialsException):
         user_authentication.login("*****@*****.**", "password")
Exemplo n.º 4
0
 def test_wrong_password(self, user_authentication: UserAuthentication,
                         user_entry_squirtle: UserEntry):
     with pytest.raises(InvalidCredentialsException):
         user_authentication.login(user_entry_squirtle.email,
                                   "wrongpassword")
Exemplo n.º 5
0
 def test_valid_login(self, user_authentication: UserAuthentication,
                      user_entry_squirtle: UserEntry):
     user_token = user_authentication.login(user_entry_squirtle.email,
                                            "password")
     assert isinstance(user_token, UserToken)
     assert user_token.user_id == user_entry_squirtle.id