File tree Expand file tree Collapse file tree 3 files changed +48
-2
lines changed
Expand file tree Collapse file tree 3 files changed +48
-2
lines changed Original file line number Diff line number Diff line change 2222import sys
2323
2424from typesense .api_call import ApiCall
25- from typesense .types .document import DirtyValuesParameters , DocumentSchema
25+ from typesense .types .document import (
26+ DeleteSingleDocumentParameters ,
27+ DirtyValuesParameters ,
28+ DocumentSchema ,
29+ )
2630
2731if sys .version_info >= (3 , 11 ):
2832 import typing
@@ -101,7 +105,10 @@ def update(
101105 )
102106 return typing .cast (TDoc , response )
103107
104- def delete (self ) -> TDoc :
108+ def delete (
109+ self ,
110+ delete_parameters : typing .Union [DeleteSingleDocumentParameters , None ] = None ,
111+ ) -> TDoc :
105112 """
106113 Delete this specific document.
107114
@@ -111,6 +118,7 @@ def delete(self) -> TDoc:
111118 response : TDoc = self .api_call .delete (
112119 self ._endpoint_path ,
113120 entity_type = typing .Dict [str , str ],
121+ params = delete_parameters ,
114122 )
115123 return response
116124
Original file line number Diff line number Diff line change @@ -827,6 +827,17 @@ class SearchResponse(typing.Generic[TDoc], typing.TypedDict):
827827 conversation : typing .NotRequired [Conversation ]
828828
829829
830+ class DeleteSingleDocumentParameters (typing .TypedDict ):
831+ """
832+ Parameters for deleting a single document.
833+
834+ Attributes:
835+ ignore_not_found (bool): Ignore not found documents.
836+ """
837+
838+ ignore_not_found : typing .NotRequired [bool ]
839+
840+
830841class DeleteQueryParameters (typing .TypedDict ):
831842 """
832843 Parameters for deleting documents.
Original file line number Diff line number Diff line change 22
33from __future__ import annotations
44
5+ import pytest
56import requests_mock
67
78from tests .fixtures .document_fixtures import Companies
1314from typesense .api_call import ApiCall
1415from typesense .document import Document
1516from typesense .documents import Documents
17+ from typesense .exceptions import ObjectNotFound
1618
1719
1820def test_init (fake_api_call : ApiCall ) -> None :
@@ -133,3 +135,28 @@ def test_actual_delete(
133135 "company_name" : "Company" ,
134136 "num_employees" : 10 ,
135137 }
138+
139+
140+ def test_actual_delete_non_existent (
141+ actual_documents : Documents ,
142+ delete_all : None ,
143+ create_collection : None ,
144+ create_document : None ,
145+ ) -> None :
146+ """Test that the Document object can delete an document from Typesense Server."""
147+ with pytest .raises (ObjectNotFound ):
148+ actual_documents ["1" ].delete ()
149+
150+
151+ def test_actual_delete_non_existent_ignore_not_found (
152+ actual_documents : Documents ,
153+ delete_all : None ,
154+ create_collection : None ,
155+ create_document : None ,
156+ ) -> None :
157+ """Test that the Document object can delete an document from Typesense Server."""
158+ response = actual_documents ["1" ].delete (
159+ delete_parameters = {"ignore_not_found" : True },
160+ )
161+
162+ assert response == {"id" : "1" }
You can’t perform that action at this time.
0 commit comments