async def test_cleaning_with_accepted_offer( db: Database, test_user2: UserInDB, test_user3: UserInDB, test_user_list: List[UserInDB]) -> CleaningInDB: ''' We're creating a cleaning with offers from everyone in the test_user_list and having test_user2 accept the offer from test_user3. ''' cleaning_repo = CleaningsRepository(db) offers_repo = OffersRepository(db) new_cleaning = CleaningCreate( name='cleaning with offers', description='desc for cleaning', price=9.99, cleaning_type='full_clean', ) created_cleaning = await cleaning_repo.create_cleaning( new_cleaning=new_cleaning, requesting_user=test_user2) offers = [] for user in test_user_list: offers.append( await offers_repo.create_offer_for_cleaning(new_offer=OfferCreate( cleaning_id=created_cleaning.id, user_id=user.id))) await offers_repo.accept_offer( offer=[offer for offer in offers if offer.user_id == test_user3.id][0], offer_update=OfferUpdate(status='accepted')) return created_cleaning
async def test_cleaning_with_accepted_offer( db: Database, test_user2: UserInDB, test_user3: UserInDB, test_user_list: List[UserInDB]) -> CleaningInDB: cleaning_repo = CleaningsRepository(db) offers_repo = OffersRepository(db) new_cleaning = CleaningCreate( name="cleaning with offers", description="desc for cleaning", price=9.99, cleaning_type="full_clean", ) created_cleaning = await cleaning_repo.create_cleaning( new_cleaning=new_cleaning, requesting_user=test_user2) offers = [] for user in test_user_list: offers.append( await offers_repo.create_offer_for_cleaning(new_offer=OfferCreate( cleaning_id=created_cleaning.id, user_id=user.id))) await offers_repo.accept_offer( offer=[o for o in offers if o.user_id == test_user3.id][0], offer_update=OfferUpdate(status="accepted")) return created_cleaning
async def test_cleaning_with_offers( db: Database, test_user2: UserInDB, test_user_list: List[UserInDB]) -> CleaningInDB: cleaning_repo = CleaningsRepository(db) offers_repo = OffersRepository(db) new_cleaning = CleaningCreate( name="cleaning with offers", description="desc for cleaning", price=9.99, cleaning_type="full_clean", ) created_cleaning = await cleaning_repo.create_cleaning( new_cleaning=new_cleaning, requesting_user=test_user2) for user in test_user_list: await offers_repo.create_offer_for_cleaning(new_offer=OfferCreate( cleaning_id=created_cleaning.id, user_id=user.id)) return created_cleaning
async def test_user_can_successfully_rescind_pending_offer( self, app: FastAPI, create_authorized_client: Callable, test_user4: UserInDB, test_user_list: List[UserInDB], test_cleaning_with_offers: CleaningInDB, ) -> None: authorized_client = create_authorized_client(user=test_user4) res = await authorized_client.delete( app.url_path_for("offers:rescind-offer-from-user", cleaning_id=test_cleaning_with_offers.id)) assert res.status_code == status.HTTP_200_OK offers_repo = OffersRepository(app.state._db) offers = await offers_repo.list_offers_for_cleaning( cleaning=test_cleaning_with_offers) user_ids = [user.id for user in test_user_list] for offer in offers: assert offer.user_id in user_ids assert offer.user_id != test_user4.id
async def test_cancelling_offer_sets_all_others_to_pending( 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 offers_repo = OffersRepository(app.state._db) offers = await offers_repo.list_offers_for_cleaning( cleaning=test_cleaning_with_accepted_offer) for offer in offers: if offer.user_id == test_user3.id: assert offer.status == "cancelled" else: assert offer.status == "pending"
async def create_cleaning_with_evaluation_offer_helper( db: Database, owner: UserInDB, cleaner: UserInDB, cleaning_create: CleaningCreate, evaluation_create: EvaluationCreate) -> CleaningInDB: cleaning_repo = CleaningsRepository(db) offers_repo = OffersRepository(db) evals_repo = EvaluationsRepository(db) created_cleaning = await cleaning_repo.create_cleaning( new_cleaning=cleaning_create, requesting_user=owner) offer = await offers_repo.create_offer_for_cleaning(new_offer=OfferCreate( cleaning_id=created_cleaning.id, user_id=cleaner.id)) await offers_repo.accept_offer(offer=offer, offer_update=OfferUpdate(status="accepted")) await evals_repo.create_evaluation_for_cleaner( evaluation_create=evaluation_create, cleaning=created_cleaning, cleaner=cleaner, ) return created_cleaning
def __init__(self, db: Database) -> None: super().__init__(db) self.offers_repo = OffersRepository(db)