コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
async def test_list_of_new_and_updated_cleanings(
        db: Database, test_user_list: List[UserInDB]) -> List[CleaningInDB]:
    cleanings_repo = CleaningsRepository(db)
    new_cleanings = [
        await cleanings_repo.create_cleaning(
            new_cleaning=CleaningCreate(
                name=f"feed item cleaning job - {i}",
                description=f"test description for feed item cleaning: {i}",
                price=float(f"{i}9.99"),
                cleaning_type=["full_clean", "spot_clean", "dust_up"][i % 3],
            ),
            requesting_user=test_user_list[i % len(test_user_list)],
        ) for i in range(50)
    ]

    # update every 4 cleanings
    for i, cleaning in enumerate(new_cleanings):
        if i % 4 == 0:
            updated_cleaning = await cleanings_repo.update_cleaning(
                cleaning=cleaning,
                cleaning_update=CleaningUpdate(
                    description=f"Updated {cleaning.description}",
                    price=cleaning.price + 100.0),
            )
            new_cleanings[i] = updated_cleaning

    return new_cleanings
コード例 #4
0
async def test_cleaning(db: Database, test_user: UserInDB) -> CleaningInDB:
    cleaning_repo = CleaningsRepository(db)
    new_cleaning = CleaningCreate(name="fake cleaning name",
                                  description="fake cleaning description",
                                  price=9.99,
                                  cleaning_type="spot_clean")
    return await cleaning_repo.create_cleaning(new_cleaning=new_cleaning,
                                               requesting_user=test_user)
コード例 #5
0
ファイル: conftest.py プロジェクト: alex-evans/learn-fastapi
async def test_cleaning(db: Database) -> CleaningInDB:
    cleaning_repo = CleaningsRepository(db)
    new_cleaning = CleaningCreate(
        name='fake cleaning name',
        description='fake cleaning description',
        price=9.99,
        cleaning_type='spot_clean',
    )

    return await cleaning_repo.create_cleaning(new_cleaning=new_cleaning)
コード例 #6
0
async def test_cleanings_list(db: Database,
                              test_user2: UserInDB) -> List[CleaningInDB]:
    cleaning_repo = CleaningsRepository(db)
    return [
        await cleaning_repo.create_cleaning(
            new_cleaning=CleaningCreate(name=f"test cleaning {i}",
                                        description="test description",
                                        price=20.00,
                                        cleaning_type="full_clean"),
            requesting_user=test_user2,
        ) for i in range(5)
    ]
コード例 #7
0
ファイル: conftest.py プロジェクト: jeancarlosdanese/phresh
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
コード例 #8
0
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