async def test_list_of_cleanings_with_evaluated_offer( db: Database, test_user2: UserInDB, test_user3: UserInDB, ) -> List[CleaningInDB]: return [ await create_cleaning_with_evaluated_offer_helper( db=db, owner=test_user2, cleaner=test_user3, cleaning_create=CleaningCreate( name=f"test cleaning - {i}", description=f"test description - {i}", price=float(f"{i}9.99"), cleaning_type="full_clean", ), evaluation_create=EvaluationCreate( professionalism=random.randint(0, 5), completeness=random.randint(0, 5), efficiency=random.randint(0, 5), overall_rating=random.randint(0, 5), headline=f"test headline - {i}", comment=f"test comment - {i}", ), ) for i in range(5) ]
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"