def test_update_notification(db: Session) -> None:
    provider = utils.create_random_provider(db)
    notification = utils.create_random_notification(provider)
    crud_notification.update(notification.id)
    update_notification = Notification.objects(id=notification.id).first()
    assert update_notification

    db.delete(provider)
    db.commit()
    Notification.delete(notification)
def test_create_notification(db: Session) -> None:
    provider = utils.create_random_provider(db)
    message = utils.random_lower_string()
    document_id = crud_notification.create(str(provider.id), message)
    notification = Notification.objects(id=document_id).first()
    assert notification
    assert notification.content == message
    assert notification.recipient_id == str(provider.id)

    db.delete(provider)
    db.commit()
    Notification.delete(notification)
Exemple #3
0
def test_list_provider_notifications(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.get("/providers/notifications", headers=header)
    data = response.json()
    assert response.status_code == 200
    assert data
    assert data[0]['recipient_id'] == str(provider.id)

    db.delete(user)
    db.delete(provider)
    db.delete(appointment)
    db.commit()
    Notification.delete(notification)
Exemple #4
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)