async def test_valid_input_creates_cleaning(
            self, app: FastAPI, client: AsyncClient,
            new_cleaning: CleaningCreate) -> None:
        res = await client.post(app.url_path_for('cleanings:create-cleaning'),
                                json={'new_cleaning': new_cleaning.dict()})
        assert res.status_code == HTTP_201_CREATED

        created_cleaning = CleaningCreate(**res.json())
        assert created_cleaning == new_cleaning
Beispiel #2
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
Beispiel #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
Beispiel #4
0
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 test_unauthorized_user_unable_to_create_cleaning(
     self, app: FastAPI, client: AsyncClient, new_cleaning: CleaningCreate
 ) -> None:
     res = await client.post(
         app.url_path_for("cleanings:create-cleaning"), json={"new_cleaning": new_cleaning.dict()}
     )
     assert res.status_code == status.HTTP_401_UNAUTHORIZED
def new_cleaning():
    return CleaningCreate(
        name="test cleaning",
        description="test description",
        price=10.00,
        cleaning_type="spot_clean",
    )
Beispiel #7
0
    async def create_cleaning(self, *,
                              new_cleaning: CleaningCreate) -> CleaningInDB:
        query_values = new_cleaning.dict()
        cleaning = await self.db.fetch_one(query=CREATE_CLEANING_QUERY,
                                           values=query_values)

        return CleaningInDB(**cleaning)
Beispiel #8
0
def new_cleaning():
    return CleaningCreate(
        name='test cleaning',
        description='test description',
        price=10.00,
        cleaning_type='spot_clean',
    )
Beispiel #9
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
Beispiel #10
0
 async def create_cleaning(self, *, new_cleaning: CleaningCreate,
                           requesting_user: UserInDB) -> CleaningInDB:
     cleaning = await self.db.fetch_one(query=CREATE_CLEANING_QUERY,
                                        values={
                                            **new_cleaning.dict(), "owner":
                                            requesting_user.id
                                        })
     return CleaningInDB(**cleaning)
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)
Beispiel #12
0
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)
 async def test_valid_input_creates_cleaning_belonging_to_user(
     self, app: FastAPI, authorized_client: AsyncClient, test_user: UserInDB, new_cleaning: CleaningCreate
 ) -> None:
     res = await authorized_client.post(
         app.url_path_for("cleanings:create-cleaning"), json=new_cleaning.dict()
     )
     assert res.status_code == status.HTTP_201_CREATED
     created_cleaning = CleaningPublic(**res.json())
     assert created_cleaning.name == new_cleaning.name
     assert created_cleaning.price == new_cleaning.price
     assert created_cleaning.cleaning_type == new_cleaning.cleaning_type
     assert created_cleaning.owner == test_user.id
Beispiel #14
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)
    ]
Beispiel #15
0
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 create_cleaning(self, *,
                           new_cleaning: CleaningCreate) -> CleaningInDB:
     cleaning = await self.db.fetch_one(query=CREATE_CLEANING_QUERY,
                                        values=new_cleaning.dict())
     return CleaningInDB.parse_obj(cleaning)