async def list_evaluations_for_cleaner( self, *, cleaner: UserInDB) -> List[EvaluationInDB]: evaluations = await self.db.fetch_all( query=LIST_EVALUATIONS_FOR_CLEANER_QUERY, values={"cleaner_id": cleaner.id}) return [EvaluationInDB(**e) for e in evaluations]
async def get_cleaner_evaluation_for_cleaning(self, *, cleaning: CleaningInDB, cleaner: UserInDB) -> EvaluationInDB: evaluation = await self.db.fetch_one(query=GET_CLEANER_EVALUATION_FOR_CLEANING_QUERY, values={"cleaning_id": cleaning.id, "cleaner_id": cleaner.id},) if not evaluation: return None return EvaluationInDB(**evaluation)
async def create_evaluation_for_cleaner(self, *, evaluation_create: EvaluationCreate, cleaning: CleaningInDB, cleaner: UserInDB) -> EvaluationInDB: async with self.db.transaction(): created_evaluation = await self.db.fetch_one(query=CREATE_OWNER_EVALUATION_FOR_CLEANER_QUERY, values={**evaluation_create.dict(), "cleaning_id": cleaning.id, "cleaner_id": cleaner.id},) await self.offers_repo.mark_offer_completed(cleaning=cleaning, cleaner=cleaner) return EvaluationInDB(**created_evaluation)
async def test_owner_can_leave_evaluation_for_cleaner_and_mark_offer_completed( self, app: FastAPI, create_authorized_client: Callable, test_user2: UserInDB, test_user3: UserInDB, test_cleaning_with_accepted_offer: CleaningInDB, ) -> None: evaluation_create = EvaluationCreate( no_show=False, headline='Excellent job', comment=f''' Really appreciated the hard work and effort they put into this job! Though the cleaner took their time, I would definitely hire them again for the quality of their work. ''', professionalism=5, completeness=5, efficiency=4, overall_rating=5, ) authorized_client = create_authorized_client(user=test_user2) res = await authorized_client.post( app.url_path_for( 'evaluations:create-evaluation-for-cleaner', cleaning_id=test_cleaning_with_accepted_offer.id, username=test_user3.username, ), json={'evaluation_create': evaluation_create.dict()}, ) assert res.status_code == status.HTTP_201_CREATED evaluation = EvaluationInDB(**res.json()) assert evaluation.no_show == evaluation_create.no_show assert evaluation.headline == evaluation_create.headline assert evaluation.overall_rating == evaluation_create.overall_rating # check that the offer has now been marked as 'completed' res = await authorized_client.get( app.url_path_for( 'offers:get-offer-from-user', cleaning_id=test_cleaning_with_accepted_offer.id, username=test_user3.username, )) assert res.status_code == status.HTTP_200_OK assert res.json()['status'] == 'completed'
async def test_owner_can_leave_evaluation_for_cleaner_and_mark_offer_completed( self, app: FastAPI, create_authorized_client: Callable, test_user2: UserInDB, test_user3: UserInDB, test_cleaning_with_accepted_offer: CleaningInDB, ) -> None: evaluation_create = EvaluationCreate( no_show=False, headline="Great Job", comment= """ Really love the nice work and effort you put in this job!. Nice Cleaning and I love it.""", professionalism=5, completeness=5, efficiency=4, overall_rating=5, ) authorized_client = create_authorized_client(user=test_user2) res = await authorized_client.post( app.url_path_for("evaluations:create-evaluation-for-cleaner", cleaning_id=test_cleaning_with_accepted_offer.id, username=test_user3.username), json={"evaluation_create": evaluation_create.dict()}, ) assert res.status_code == status.HTTP_201_CREATED evaluation = EvaluationInDB(**res.json()) assert evaluation.no_show == evaluation_create.no_show assert evaluation.headline == evaluation_create.headline assert evaluation.overall_rating == evaluation_create.overall_rating # check if offer has now been marked as "completed" res = await authorized_client.get( app.url_path_for("offers:get-offer-from-user", cleaning_id=test_cleaning_with_accepted_offer.id, username=test_user3.username)) assert res.status_code == status.HTTP_200_OK assert res.json()["status"] == "completed"