示例#1
0
def test_get_appointments_by_DMY(db: Session) -> None:
    user = utils.create_random_user(db)
    provider = utils.create_random_provider(db)
    appointment = utils.create_random_appointment(db, provider, user)
    date = appointment.date
    query = ProviderDayAvailabilityQuery(
        provider_id=str(provider.id),
        day=date.day, 
        month=date.month, 
        year=date.year)
    my_appointment_1 = crud_appointment.get_appointments_by_DMY(db, query)
    my_appointment_2 = crud_appointment.get_appointments_by_DMY(db, query, provider)
    assert str(my_appointment_1[0].provider_id) == query.provider_id
    assert my_appointment_1[0].date.day == query.day
    assert my_appointment_1[0].date.month == query.month
    assert my_appointment_1[0].date.year == query.year
    assert my_appointment_2[0].provider_id == provider.id
    assert my_appointment_2[0].date.day == query.day
    assert my_appointment_2[0].date.month == query.month
    assert my_appointment_2[0].date.year == query.year

    db.delete(appointment)
    db.delete(user)
    db.delete(provider)
    db.commit()
示例#2
0
def test_list_provider_hours_availability(client: TestClient,
                                          db: Session) -> None:
    user = utils.create_random_user(db)
    user = utils.activate_random_user(db, user)
    provider = utils.create_random_provider(db)
    provider = utils.activate_random_user(db, provider)
    appointment = utils.create_random_appointment(db, provider, user)
    token = security.generate_token(str(provider.id), "access",
                                    datetime.utcnow() + timedelta(hours=2))
    header = {'Authorization': f'Bearer {token}'}
    day = appointment.date.day
    month = appointment.date.month
    year = appointment.date.year
    response = client.get(
        f"/providers/day-availability?provider_id=2deee015-b1dd-4d08-8ce6-99b17a7477a8&day={day}&month={month}&year={year}",
        headers=header)
    data = response.json()
    assert response.status_code == 200
    assert data
    assert "hour" in data[0]
    assert "available" in data[0]

    db.delete(user)
    db.delete(provider)
    db.delete(appointment)
    db.commit()
示例#3
0
def test_get_appointments_by_user(db: Session) -> None:
    user = utils.create_random_user(db)
    provider = utils.create_random_provider(db)
    appointment = utils.create_random_appointment(db, provider, user)
    user_appointments = crud_appointment.get_appointments_by_user(db, user)
    assert user_appointments[0].user_id == user.id

    db.delete(appointment)
    db.delete(user)
    db.delete(provider)
    db.commit()
示例#4
0
def test_get_appointment_by_date(db: Session) -> None:
    user = utils.create_random_user(db)
    provider = utils.create_random_provider(db)
    appointment = utils.create_random_appointment(db, provider, user)
    date = appointment.date
    date_appointment = crud_appointment.get_appointment_by_date(db, str(provider.id), date)
    assert date_appointment.provider_id == provider.id
    assert date_appointment.date == date

    db.delete(appointment)
    db.delete(user)
    db.delete(provider)
    db.commit()
示例#5
0
def test_invalidate_cache_user(db: Session, rdc: RedisCache) -> None:
    user = utils.create_random_user(db)
    provider = utils.create_random_provider(db)
    appointment = utils.create_random_appointment(db, provider, user)
    provider.provider_appointments.append(appointment)
    key = f"user-appointments:{str(user.id)}"
    value = 40
    rdc.setex(key, timedelta(seconds=3600), value=pickle.dumps(value))
    cache = rdc.get(key)
    assert cache
    rdc.invalidate_cache_user(provider)
    cache = rdc.get(key)
    assert cache is None
示例#6
0
def test_get_user_me(client: TestClient, db: Session) -> None:
    user = utils.create_random_user(db)
    provider = utils.create_random_provider(db)
    user = utils.activate_random_user(db, user)
    provider = utils.activate_random_user(db, provider)
    appointment = utils.create_random_appointment(db, provider, user)
    user = utils.activate_random_user(db, user)
    token = security.generate_token(str(user.id), "access", datetime.utcnow() + timedelta(hours=2))
    header = {'Authorization': f'Bearer {token}'}
    response = client.get("/users/me", headers=header)
    data = response.json()
    assert response.status_code == 200
    assert data
    assert data[0]['user_id'] == str(user.id)
    assert "provider" in data[0]

    db.delete(user)
    db.delete(provider)
    db.delete(appointment)
    db.commit()
示例#7
0
def test_update_notification(client: TestClient, db: Session) -> None:
    user = utils.create_random_user(db)
    user = utils.activate_random_user(db, user)
    provider = utils.create_random_provider(db)
    provider = utils.activate_random_user(db, provider)
    notification = utils.create_random_notification(provider)
    appointment = utils.create_random_appointment(db, provider, user)
    token = security.generate_token(str(provider.id), "access",
                                    datetime.utcnow() + timedelta(hours=2))
    header = {'Authorization': f'Bearer {token}'}
    response = client.put("/providers/notifications",
                          headers=header,
                          json={"doc_id": str(notification.id)})
    document = Notification.objects(id=notification.id).first()
    assert response.status_code == 204
    assert document.read == True

    db.delete(user)
    db.delete(provider)
    db.delete(appointment)
    db.commit()
    Notification.delete(notification)
示例#8
0
def test_get_provider_me(client: TestClient, db: Session) -> None:
    user = utils.create_random_user(db)
    user = utils.activate_random_user(db, user)
    provider = utils.create_random_provider(db)
    provider = utils.activate_random_user(db, provider)
    appointment = utils.create_random_appointment(db, provider, user)
    token = security.generate_token(str(provider.id), 'access',
                                    datetime.utcnow() + timedelta(days=1))
    header = {'Authorization': f'Bearer {token}'}
    day = appointment.date.day
    month = appointment.date.month
    year = appointment.date.year
    response = client.get(f'/providers/me?day={day}&month={month}&year={year}',
                          headers=header)
    data = response.json()
    assert response.status_code == 200
    assert data
    assert data[0]['provider_id'] == str(provider.id)
    assert "user" in data[0]

    db.delete(user)
    db.delete(provider)
    db.delete(appointment)
    db.commit()