async def test_get_cleaning_by_id(self, app: FastAPI,
                                   authorized_client: AsyncClient,
                                   test_cleaning: CleaningInDB) -> None:
     res = await authorized_client.get(
         app.url_path_for("cleanings:get-cleaning-by-id",
                          cleaning_id=test_cleaning.id))
     assert res.status_code == status.HTTP_200_OK
     cleaning = CleaningPublic(**res.json()).dict(exclude={"owner"})
     assert cleaning == test_cleaning.dict(exclude={"owner"})
Beispiel #2
0
 async def populate_cleaning(
         self,
         *,
         cleaning: CleaningInDB,
         requesting_user: UserInDB = None) -> CleaningPublic:
     return CleaningPublic(
         **cleaning.dict(exclude={"owner"}),
         owner=await self.users_repo.get_user_by_id(user_id=cleaning.owner),
         # any other populated fields for cleaning public would be tacked on here
     )
 async def test_valid_input_creates_cleaning_belonging_to_user(
     self, app: FastAPI, authorized_client: AsyncClient, test_user: UserInDB, new_cleaning: CleaningCreate
 ) -> None:
     res = await authorized_client.post(
         app.url_path_for("cleanings:create-cleaning"), json=new_cleaning.dict()
     )
     assert res.status_code == status.HTTP_201_CREATED
     created_cleaning = CleaningPublic(**res.json())
     assert created_cleaning.name == new_cleaning.name
     assert created_cleaning.price == new_cleaning.price
     assert created_cleaning.cleaning_type == new_cleaning.cleaning_type
     assert created_cleaning.owner == test_user.id
Beispiel #4
0
 async def populate_cleaning(
         self,
         *,
         cleaning: CleaningInDB,
         requesting_user: UserInDB = None) -> CleaningPublic:
     """
     creates a model with all the attributes of the cleaning record retrieved by 
     the GET_CLEANING_BY_ID_QUERY, but the owner field is replaced.
     """
     return CleaningPublic(
         **cleaning.dict(exclude={"owner"}),
         owner=await self.users_repo.get_user_by_id(user_id=cleaning.owner),
         # any other populated fields for cleaning public would be tacked on here
     )
 async def test_user_cant_change_ownership_of_cleaning(
     self,
     app: FastAPI,
     authorized_client: AsyncClient,
     test_cleaning: CleaningInDB,
     test_user: UserInDB,
     test_user2: UserInDB,
 ) -> None:
     res = await authorized_client.put(
         app.url_path_for("cleanings:update-cleaning-by-id",
                          cleaning_id=test_cleaning.id),
         json={"cleaning_update": {"owner": str(test_user2.id)}},
     )
     assert res.status_code == status.HTTP_200_OK
     cleaning = CleaningPublic(**res.json())
     assert cleaning.owner == test_user.id