def test_delete_item(db: Session) -> None:
    db.query(Note).delete()

    stored_notes = crud_note.get_multi(db=db)
    assert len(stored_notes) == 0

    title = random_string(100)
    description = random_string(255)
    tags = random_string(100)

    note_obj = NoteCreate(title=title, description=description, tags=tags)
    note_1 = crud_note.create(db=db, obj_in=note_obj)

    title = random_string(100)
    description = random_string(255)
    tags = random_string(100)

    note_obj = NoteCreate(title=title, description=description, tags=tags)
    note_2 = crud_note.create(db=db, obj_in=note_obj)

    stored_notes = crud_note.get_multi(db=db)
    assert len(stored_notes) == 2

    id_delete = note_1.id
    crud_note.remove(db=db, id=id_delete)
    note_1 = crud_note.get(db=db, id=id_delete)
    assert note_1 is None

    stored_notes = crud_note.get_multi(db=db)
    assert len(stored_notes) == 1
Ejemplo n.º 2
0
def read_note(
        *,
        db: Session = Depends(deps.get_db_local),
        id: int,
) -> Any:
    """
    Get item by ID.
    """
    note = crud_note.get(db=db, id=id)
    if not note:
        raise HTTPException(status_code=404, detail="Item not found")
    return note
Ejemplo n.º 3
0
def delete_note(
        *,
        db: Session = Depends(deps.get_db_local),
        id: int,
) -> Any:
    """
    Delete an item.
    """
    note = crud_note.get(db=db, id=id)
    if not note:
        raise HTTPException(status_code=404, detail="Item not found")
    note = crud_note.remove(db=db, id=id)
    return note
Ejemplo n.º 4
0
def update_item(
    *,
    db: Session = Depends(deps.get_db_local),
    id: int,
    note_in: schemas.NoteUpdate,
) -> Any:
    """
    Update an item.
    """
    note = crud_note.get(db=db, id=id)
    if not note:
        raise HTTPException(status_code=404, detail="Item not found")
    note = crud_note.update(db=db, db_obj=note, obj_in=note_in)
    return note
def test_get_note(db: Session) -> None:

    db.query(Note).delete()

    title = random_string(100)
    description = random_string(255)
    tags = random_string(100)

    note_in = NoteCreate(title=title, description=description, tags=tags)
    note = crud_note.create(db=db, obj_in=note_in)

    stored_note = crud_note.get(db=db, id=note.id)
    assert stored_note
    assert note.id == stored_note.id
    assert note.title == stored_note.title
    assert note.description == stored_note.description
    assert note.tags == stored_note.tags
Ejemplo n.º 6
0
async def websocket_endpoint(websocket: WebSocket,
                             db: Session = Depends(deps.get_db_global)):
    await manager.connect(websocket)
    try:
        while True:
            data = await websocket.receive_text()

            if not data.isnumeric():
                result = "Not a number"
            else:
                result = f"Note ID: {data} | "

                note = crud_note.get(db=db, id=int(data))
                if note:
                    note_dict = note.__dict__
                    note_dict.pop("_sa_instance_state")
                    result += str(note_dict)
                else:
                    result += "Not found"

            await manager.send_message(result, websocket)
    except WebSocketDisconnect:
        await manager.broadcast(f"Some Client Disconnected")
Ejemplo n.º 7
0
 def mutate(self, info, **kwargs):
     note = crud_note.get(db=SessionScoped, id=kwargs["id"])
     if note is None:
         return NoteDelete(status=False)
     data = crud_note.remove(db=SessionScoped, id=note.id)
     return NoteDelete(status=True)
Ejemplo n.º 8
0
 def mutate(self, info, **kwargs):
     note = crud_note.get(db=SessionScoped, id=kwargs["id"])
     if note is None:
         return NoteUpdate(status=False, data=None)
     data = crud_note.update(db=SessionScoped, db_obj=note, obj_in=kwargs)
     return NoteUpdate(status=True, data=data)
Ejemplo n.º 9
0
 def resolve_note(self, info, id):
     return crud_note.get(db=SessionScoped, id=id)