@@ -110,21 +110,50 @@ def put(self, entry):
110110 print (f"Failed to update (PUT): Error { resp .http_status } " )
111111 return False
112112
113- def patch (self , entry ):
114- collection = entry .get ("collection" )
115- item_id = entry .get ("id" )
113+ def json_patch (self , collection , item_id , entry ):
114+ """
115+ RFC 6902 https://tools.ietf.org/html/rfc6902
116+ JSON Patch is a format for describing changes to a JSON document
117+ in a way that is similar to a diff
118+ It consists of a sequence of operations to be applied to the target JSON document
119+ """
120+ headers = {
121+ "Content-Type" : "application/json-patch+json" ,
122+ "User-Agent" : f"test_client/{ __version__ } " ,
123+ }
124+ resp = self .transaction_client .patch (f"/collections/{ collection } /items/{ item_id } " , headers = headers , data = entry )
125+ if resp .http_status == 201 :
126+ print (resp .http_status )
127+ print ("Updated (JSON PATCH)" )
128+ return True
129+ elif resp .http_status == 202 :
130+ print (resp .http_status )
131+ print ("Queued for update (JSON PATCH)" )
132+ return True
133+ else :
134+ print (f"Failed to update (JSON PATCH): Error { resp .http_status } " )
135+ return False
136+
137+ def merge_patch (self , collection , item_id , entry ):
138+ """
139+ RFC 7396 https://tools.ietf.org/html/rfc7396
140+ Merge Patch is a format for describing changes to a JSON document
141+ that is intended to be applied in a way that is similar to a merge
142+ """
116143 headers = {
144+ "Content-Type" : "application/merge-patch+json" ,
117145 "User-Agent" : f"test_client/{ __version__ } " ,
118146 }
119147 resp = self .transaction_client .patch (f"/collections/{ collection } /items/{ item_id } " , headers = headers , data = entry )
120148 if resp .http_status == 201 :
121149 print (resp .http_status )
122- print ("Updated (PATCH)" )
150+ print ("Updated (MERGE PATCH)" )
123151 return True
124152 elif resp .http_status == 202 :
125153 print (resp .http_status )
126- print ("Queued for update (PATCH)" )
154+ print ("Queued for update (MERGE PATCH)" )
127155 return True
128156 else :
129- print (f"Failed to update (PATCH): Error { resp .http_status } " )
157+ print (f"Failed to update (MERGE PATCH): Error { resp .http_status } " )
130158 return False
159+
0 commit comments