async def test_accepting_one_offer_rejects_all_other_offers( self, app: FastAPI, create_authorized_client: Callable, test_user2: UserInDB, test_user_list: List[UserInDB], test_cleaning_with_offers: CleaningInDB, ) -> None: selected_user = random.choice(test_user_list) authorized_client = create_authorized_client(user=test_user2) res = await authorized_client.put( app.url_path_for( 'offers:accept-offer-from-user', cleaning_id=test_cleaning_with_offers.id, username=selected_user.username, )) assert res.status_code == status.HTTP_200_OK res = await authorized_client.get( app.url_path_for( 'offers:list-offers-for-cleaning', cleaning_id=test_cleaning_with_offers.id, )) assert res.status_code == status.HTTP_200_OK offers = [OfferPublic(**offer) for offer in res.json()] for offer in offers: if offer.user == selected_user.id: assert offer.status == 'accepted' else: assert offer.status == 'rejected'
async def populate_offer(self, *, offer: OfferInDB) -> OfferPublic: """ Queries the user linked to the offer and populates the offer with it. """ return OfferPublic( **offer.dict(), user=await self.users_repo.get_user_by_id(user_id=offer.user_id), # could populate cleaning here as well if needed )
async def test_user_can_successfully_create_offer_for_other_users_cleaning_job( self, app: FastAPI, create_authorized_client: Callable, test_cleaning: CleaningInDB, test_user3: UserInDB, ) -> None: authorized_client = create_authorized_client(user=test_user3) res = await authorized_client.post( app.url_path_for('offers:create-offer', cleaning_id=test_cleaning.id)) assert res.status_code == status.HTTP_201_CREATED offer = OfferPublic(**res.json()) assert offer.user_id == test_user3.id assert offer.cleaning_id == test_cleaning.id assert offer.status == 'pending'
async def test_user_can_cancel_offer_after_it_has_been_accepted( self, app: FastAPI, create_authorized_client: Callable, test_user3: UserInDB, test_cleaning_with_accepted_offer: CleaningInDB, ) -> None: accepted_user_client = create_authorized_client(user=test_user3) res = await accepted_user_client.put( app.url_path_for("offers:cancel-offer-from-user", cleaning_id=test_cleaning_with_accepted_offer.id)) assert res.status_code == status.HTTP_200_OK cancelled_offer = OfferPublic(**res.json()) assert cancelled_offer.status == "cancelled" assert cancelled_offer.user_id == test_user3.id assert cancelled_offer.cleaning_id == test_cleaning_with_accepted_offer.id
async def test_offer_owner_can_get_own_offer( self, app: FastAPI, create_authorized_client: Callable, test_user_list: List[UserInDB], test_cleaning_with_offers: CleaningInDB, ) -> None: first_test_user = test_user_list[0] authorized_client = create_authorized_client(user=first_test_user) res = await authorized_client.get( app.url_path_for( 'offers:get-offer-from-user', cleaning_id=test_cleaning_with_offers.id, username=first_test_user.username, )) assert res.status_code == status.HTTP_200_OK offer = OfferPublic(**res.json()) assert offer.user_id == first_test_user.id
async def test_cleaning_owner_can_get_offer_from_user( self, app: FastAPI, create_authorized_client: Callable, test_user2: UserInDB, test_user_list: List[UserInDB], test_cleaning_with_offers: CleaningInDB, ) -> None: authorized_client = create_authorized_client(user=test_user2) selected_user = random.choice(test_user_list) res = await authorized_client.get( app.url_path_for( "offers:get-offer-from-user", cleaning_id=test_cleaning_with_offers.id, username=selected_user.username, )) assert res.status_code == status.HTTP_200_OK offer = OfferPublic(**res.json()) assert offer.user_id == selected_user.id
async def test_cleaning_owner_can_accept_offer_successfully( self, app: FastAPI, create_authorized_client: Callable, test_user2: UserInDB, test_user_list: List[UserInDB], test_cleaning_with_offers: CleaningInDB, ) -> None: selected_user = random.choice(test_user_list) authorized_client = create_authorized_client(user=test_user2) res = await authorized_client.put( app.url_path_for( "offers:accept-offer-from-user", cleaning_id=test_cleaning_with_offers.id, username=selected_user.username, )) assert res.status_code == status.HTTP_200_OK accepted_offer = OfferPublic(**res.json()) assert accepted_offer.status == "accepted" assert accepted_offer.user_id == selected_user.id assert accepted_offer.cleaning_id == test_cleaning_with_offers.id
async def populate_offer(self, *, offer: OfferInDB) -> OfferPublic: return OfferPublic( **offer.dict(), user=await self.users_repo.get_user_by_id(user_id=offer.user_id), # could populate cleaning here as well if needed )