Exemplo n.º 1
0
def test_create_contract_without_nanny_by_admin(client: TestClient,
                                                superuser_token_headers: dict,
                                                db: Session) -> None:
    user = create_random_user(db)
    date_today = date.today()
    data = {
        "weekdays": random_weekdays(),
        "weeks": 44,
        "hours": 40.0,
        "price_hour_standard": 3.5,
        "price_hour_extra": 3.8,
        "price_fees": 3.08,
        "price_meals": 4.0,
        "start": str(date_today),
        "end": str(date_today + relativedelta(months=+12, days=-1))
    }
    response = client.post(
        f"{settings.API_V1_STR}/contracts/" + f"?user_id={user.id}",
        headers=superuser_token_headers,
        json=data,
    )
    assert response.status_code == 200
    content = response.json()
    assert "id" in content
    assert content["user_id"] == user.id
    assert content["weekdays"] == data["weekdays"]
    assert content["weeks"] == data["weeks"]
    assert content["hours"] == data["hours"]
    assert content["price_hour_standard"] == data["price_hour_standard"]
    assert content["price_hour_extra"] == data["price_hour_extra"]
    assert content["price_fees"] == data["price_fees"]
    assert content["price_meals"] == data["price_meals"]
    assert content["start"] == data["start"]
    assert content["end"] == data["end"]
Exemplo n.º 2
0
def test_update_contract_by_user(client: TestClient,
                                 normal_user_token_headers: dict,
                                 db: Session) -> None:
    r = client.get(f"{settings.API_V1_STR}/users/me",
                   headers=normal_user_token_headers)
    user_id = r.json()["id"]
    contract = create_random_contract(db, user_id=user_id)
    date_today = date.today()
    data = {
        "weekdays": random_weekdays(),
        "weeks": 44,
        "hours": 40.0,
        "price_hour_standard": 3.5,
        "price_hour_extra": 3.8,
        "price_fees": 3.08,
        "price_meals": 4.0,
        "start": str(date_today),
        "end": str(date_today + relativedelta(months=+12, days=-1))
    }
    response = client.put(f"{settings.API_V1_STR}/contracts/{contract.id}",
                          headers=normal_user_token_headers,
                          json=data)
    assert response.status_code == 200
    content = response.json()
    assert content["weekdays"] == data["weekdays"]
    assert content["weeks"] == data["weeks"]
    assert content["hours"] == data["hours"]
    assert content["price_hour_standard"] == data["price_hour_standard"]
    assert content["price_hour_extra"] == data["price_hour_extra"]
    assert content["price_fees"] == data["price_fees"]
    assert content["price_meals"] == data["price_meals"]
    assert content["start"] == data["start"]
    assert content["end"] == data["end"]
Exemplo n.º 3
0
def test_update_contract(db: Session) -> None:
    user = create_random_user(db)
    nanny = create_random_user(db)

    date_today = date.today()
    weekdays = random_weekdays()
    weeks = random_int_range(20, 47)
    hours = random_int_range(10, 50)
    price_hour_standard = random_float_range(2.5, 4, 1)
    price_hour_extra = random_float_range(2.5, 4, 1)
    price_fees = random_float_range(3.08, 5, 2)
    price_meals = random_float_range(2, 6, 1)
    start = str(date_today)
    end = str(date_today + relativedelta(months=+12, days=-1))
    created_on = datetime.now()
    updated_on = datetime.now()

    contract_in = ContractCreate(user_id=user.id,
                                 nanny_id=nanny.id,
                                 weekdays=weekdays,
                                 weeks=weeks,
                                 hours=hours,
                                 price_hour_standard=price_hour_standard,
                                 price_hour_extra=price_hour_extra,
                                 price_fees=price_fees,
                                 price_meals=price_meals,
                                 start=start,
                                 end=end)
    contract = crud.contract.create_with_owner(db=db,
                                               obj_in=contract_in,
                                               user_id=user.id,
                                               nanny_id=nanny.id)
    contract_update = ContractUpdate(weekdays=weekdays,
                                     weeks=weeks,
                                     hours=hours,
                                     price_hour_standard=price_hour_standard,
                                     price_hour_extra=price_hour_extra,
                                     price_fees=price_fees,
                                     price_meals=price_meals,
                                     start=start,
                                     end=end)
    contract2 = crud.contract.update(db=db,
                                     db_obj=contract,
                                     obj_in=contract_update)
    assert contract.id == contract2.id
    assert contract.user_id == contract2.user_id
    assert contract.nanny_id == contract2.nanny_id
    assert contract.weekdays == contract2.weekdays
    assert contract.weeks == contract2.weeks
    assert contract.hours == contract2.hours
    assert contract.price_hour_standard == contract2.price_hour_standard
    assert contract.price_hour_extra == contract2.price_hour_extra
    assert contract.price_fees == contract2.price_fees
    assert contract.price_meals == contract2.price_meals
    assert contract.start == contract2.start
    assert contract.end == contract2.end
    assert isinstance(contract2.created_on, datetime)
    assert isinstance(contract2.updated_on, datetime)
Exemplo n.º 4
0
def test_get_contract_by_nanny(db: Session) -> None:
    user = create_random_user(db)
    nanny = create_random_user(db)

    date_today = date.today()
    weekdays = random_weekdays()
    weeks = random_int_range(20, 47)
    hours = random_int_range(10, 50)
    price_hour_standard = random_float_range(2.5, 4, 1)
    price_hour_extra = random_float_range(2.5, 4, 1)
    price_fees = random_float_range(3.08, 5, 2)
    price_meals = random_float_range(2, 6, 1)
    start = str(date_today)
    end = str(date_today + relativedelta(months=+12, days=-1))

    contract_in = ContractCreate(user_id=user.id,
                                 nanny_id=nanny.id,
                                 weekdays=weekdays,
                                 weeks=weeks,
                                 hours=hours,
                                 price_hour_standard=price_hour_standard,
                                 price_hour_extra=price_hour_extra,
                                 price_fees=price_fees,
                                 price_meals=price_meals,
                                 start=start,
                                 end=end)
    contract = crud.contract.create_with_owner(db=db,
                                               obj_in=contract_in,
                                               user_id=user.id,
                                               nanny_id=nanny.id)
    stored_contracts = crud.contract.get_multi_by_nanny(
        db=db, nanny_id=contract.nanny_id)
    stored_contract = [x for x in stored_contracts if x.id == contract.id][0]
    assert isinstance(stored_contracts, list)
    assert stored_contract
    assert contract.id == stored_contract.id
    assert contract.user_id == stored_contract.user_id
    assert contract.nanny_id == stored_contract.nanny_id
    assert contract.weekdays == stored_contract.weekdays
    assert contract.weeks == stored_contract.weeks
    assert contract.hours == stored_contract.hours
    assert contract.price_hour_standard == stored_contract.price_hour_standard
    assert contract.price_hour_extra == stored_contract.price_hour_extra
    assert contract.price_fees == stored_contract.price_fees
    assert contract.price_meals == stored_contract.price_meals
    assert contract.start == stored_contract.start
    assert contract.end == stored_contract.end
Exemplo n.º 5
0
def test_update_contract_by_another_user(client: TestClient,
                                         normal_user_token_headers: dict,
                                         db: Session) -> None:
    contract = create_random_contract(db)
    date_today = date.today()
    data = {
        "weekdays": random_weekdays(),
        "weeks": 44,
        "hours": 40.0,
        "price_hour_standard": 3.5,
        "price_hour_extra": 3.8,
        "price_fees": 3.08,
        "price_meals": 4.0,
        "start": str(date_today),
        "end": str(date_today + relativedelta(months=+12, days=-1))
    }
    response = client.put(f"{settings.API_V1_STR}/contracts/{contract.id}",
                          headers=normal_user_token_headers,
                          json=data)
    assert response.status_code == 400