async def test_authenticated_user_can_view_other_users_profile(
     self, app: FastAPI, authorized_client: AsyncClient, test_user: UserInDB, test_user2: UserInDB
 ) -> None:
     res = await authorized_client.get(
         app.url_path_for("profiles:get-profile-by-username", username=test_user2.username)
     )
     assert res.status_code == status.HTTP_200_OK
     profile = ProfilePublic(**res.json())
     assert profile.username == test_user2.username
 async def test_user_can_update_own_profile(
     self, app: FastAPI, authorized_client: AsyncClient, test_user: UserInDB, attr: str, value: str,
 ) -> None:
     assert getattr(test_user.profile, attr) != value
     res = await authorized_client.put(
         app.url_path_for("profiles:update-own-profile"), json={"profile_update": {attr: value}},
     )
     assert res.status_code == status.HTTP_200_OK
     profile = ProfilePublic(**res.json())
     assert getattr(profile, attr) == value
Exemple #3
0
 async def populate_user(self, *, user: UserInDB) -> UserInDB:
     user_profile = await self.profile_repo.get_profile_by_user_id(user_id=user.id)
     user.profile = ProfilePublic(**user_profile.dict())
     return user