예제 #1
0
def update(doc_id: str) -> None:
    """
    To do unit test passes test as true 
    """
    ModelNotification.objects(id=doc_id).update_one(
        read=True, 
        updated_at=datetime.utcnow()
    )
예제 #2
0
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)
예제 #3
0
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)
예제 #4
0
def get_all_notifications(provider_id: str) -> List[dict]:
    queryset: ModelNotification = ModelNotification.objects(
        recipient_id=provider_id,
        read=False
    ).all()

    notification = []
    for q in queryset:
        value = q.to_mongo().to_dict()
        value['id'] = value['_id']
        notification.append(value)
    return notification
예제 #5
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)
예제 #6
0
파일: utils.py 프로젝트: luccasPh/gobarber
def create_random_notification(provider: User) -> Notification:
    message = random_lower_string()
    document_id = crud_notification.create(str(provider.id), message)
    return Notification.objects(id=document_id).first()