def test_get_notes(db: Session) -> None: db.query(Note).delete() stored_notes = crud_note.get_multi(db=db) assert len(stored_notes) == 0 for _ in range(10): title = random_string(100) description = random_string(255) tags = random_string(100) note_in = NoteCreate(title=title, description=description, tags=tags) crud_note.create(db=db, obj_in=note_in) stored_notes = crud_note.get_multi(db=db) assert len(stored_notes) == 10 for _ in range(10): title = random_string(100) description = random_string(255) tags = random_string(100) note_in = NoteCreate(title=title, description=description, tags=tags) crud_note.create(db=db, obj_in=note_in) stored_notes = crud_note.get_multi(db=db) assert len(stored_notes) == 20
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
def test_update_note(client: TestClient, db: Session) -> None: 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) data = { "title": random_string(100), "description": random_string(255), "tags": random_string(100) } response = client.put( f"{get_settings().API_HOST}/notes/{note.id}", json=data, ) content = response.json() assert response.status_code == 200 assert content["id"] == note.id assert content["title"] == data["title"] assert content["description"] == data["description"] assert content["tags"] == data["tags"]
def test_update_note(db: Session) -> None: db.query(Note).delete() title = random_string(100) description = random_string(255) tags = random_string(100) note_obj = NoteCreate(title=title, description=description, tags=tags) note = crud_note.create(db=db, obj_in=note_obj) assert note.title == title assert note.description == description assert note.tags == tags new_title = random_string(100) new_description = random_string(255) new_tags = random_string(100) note_in = NoteUpdate(title=new_title, description=new_description, tags=new_tags) note = crud_note.update(db=db, db_obj=note, obj_in=note_in) assert note.title == new_title assert note.description == new_description assert note.tags == new_tags
def test_read_notes(client: TestClient, db: Session) -> None: db.query(Note).delete() for _ in range(10): title = random_string(100) description = random_string(255) tags = random_string(100) note_in = NoteCreate(title=title, description=description, tags=tags) crud_note.create(db=db, obj_in=note_in) response = client.get(f"{get_settings().API_HOST}/notes/", ) content = response.json() assert response.status_code == 200 assert len(content) == 10
def create_note( *, db: Session = Depends(deps.get_db_local), note_in: schemas.NoteCreate, ) -> Any: """ Create new item. """ note = crud_note.create(db=db, 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
def test_delete_note(client: TestClient, db: Session) -> None: 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) print("note id: ", note.id) response = client.delete(f"{get_settings().API_HOST}/notes/{note.id}", ) content = response.json() assert response.status_code == 200 assert content["id"] == note.id assert content["title"] == note.title assert content["description"] == note.description assert content["tags"] == note.tags
def mutate(self, info, **kwargs): data = crud_note.create(db=SessionScoped, obj_in=kwargs) return NoteCreate(status=True, data=data)