Skip to content

Commit 85ddfb3

Browse files
committed
Merge pull request #68 from vsham20/Issue_29
Rename the last_modified field to if_match (fixes #29)
2 parents 2c11ce2 + 0c95d5e commit 85ddfb3

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Overwriting existing objects
204204
----------------------------
205205

206206
Most of the methods take a ``safe`` argument, which defaults to ``True``. If set
207-
to ``True`` and a ``last_modified`` field is present in the passed ``data``, then a
207+
to ``True`` and a ``if_match`` field is present in the passed ``data``, then a
208208
check will be added to the requests to ensure the record wasn't modified on
209209
the server side in the meantime.
210210

kinto_client/__init__.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ def _paginated(self, endpoint, records=None, if_none_match=None, **kwargs):
118118
if_none_match=if_none_match)
119119
return records.values()
120120

121-
def _get_cache_headers(self, safe, data=None, last_modified=None):
121+
def _get_cache_headers(self, safe, data=None, if_match=None):
122122
has_data = data is not None and data.get('last_modified')
123-
if (last_modified is None and has_data):
124-
last_modified = data['last_modified']
125-
if safe and last_modified is not None:
126-
return {'If-Match': utils.quote(last_modified)}
123+
if (if_match is None and has_data):
124+
if_match = data['last_modified']
125+
if safe and if_match is not None:
126+
return {'If-Match': utils.quote(if_match)}
127127
# else return None
128128

129129
def _create_if_not_exists(self, resource, **kwargs):
@@ -165,9 +165,9 @@ def create_bucket(self, bucket=None, data=None, permissions=None,
165165
return resp
166166

167167
def update_bucket(self, bucket=None, data=None, permissions=None,
168-
safe=True, last_modified=None, method='put'):
168+
safe=True, if_match=None, method='put'):
169169
endpoint = self._get_endpoint('bucket', bucket)
170-
headers = self._get_cache_headers(safe, data, last_modified)
170+
headers = self._get_cache_headers(safe, data, if_match)
171171
resp, _ = self.session.request(method, endpoint, data=data,
172172
permissions=permissions,
173173
headers=headers)
@@ -189,15 +189,15 @@ def get_bucket(self, bucket=None):
189189
raise BucketNotFound(bucket or self._bucket_name, e)
190190
return resp
191191

192-
def delete_bucket(self, bucket=None, safe=True, last_modified=None):
192+
def delete_bucket(self, bucket=None, safe=True, if_match=None):
193193
endpoint = self._get_endpoint('bucket', bucket)
194-
headers = self._get_cache_headers(safe, last_modified=last_modified)
194+
headers = self._get_cache_headers(safe, if_match=if_match)
195195
resp, _ = self.session.request('delete', endpoint, headers=headers)
196196
return resp['data']
197197

198-
def delete_buckets(self, safe=True, last_modified=None):
198+
def delete_buckets(self, safe=True, if_match=None):
199199
endpoint = self._get_endpoint('buckets')
200-
headers = self._get_cache_headers(safe, last_modified=last_modified)
200+
headers = self._get_cache_headers(safe, if_match=if_match)
201201
resp, _ = self.session.request('delete', endpoint, headers=headers)
202202
return resp['data']
203203

@@ -226,9 +226,9 @@ def create_collection(self, collection=None, bucket=None,
226226

227227
def update_collection(self, data=None, collection=None, bucket=None,
228228
permissions=None, method='put',
229-
safe=True, last_modified=None):
229+
safe=True, if_match=None):
230230
endpoint = self._get_endpoint('collection', bucket, collection)
231-
headers = self._get_cache_headers(safe, data, last_modified)
231+
headers = self._get_cache_headers(safe, data, if_match)
232232
resp, _ = self.session.request(method, endpoint, data=data,
233233
permissions=permissions,
234234
headers=headers)
@@ -244,15 +244,15 @@ def get_collection(self, collection=None, bucket=None):
244244
return resp
245245

246246
def delete_collection(self, collection=None, bucket=None,
247-
safe=True, last_modified=None):
247+
safe=True, if_match=None):
248248
endpoint = self._get_endpoint('collection', bucket, collection)
249-
headers = self._get_cache_headers(safe, last_modified=last_modified)
249+
headers = self._get_cache_headers(safe, if_match=if_match)
250250
resp, _ = self.session.request('delete', endpoint, headers=headers)
251251
return resp['data']
252252

253-
def delete_collections(self, bucket=None, safe=True, last_modified=None):
253+
def delete_collections(self, bucket=None, safe=True, if_match=None):
254254
endpoint = self._get_endpoint('collections', bucket)
255-
headers = self._get_cache_headers(safe, last_modified=last_modified)
255+
headers = self._get_cache_headers(safe, if_match=if_match)
256256
resp, _ = self.session.request('delete', endpoint, headers=headers)
257257
return resp['data']
258258

@@ -291,12 +291,12 @@ def create_record(self, data, id=None, collection=None, permissions=None,
291291

292292
def update_record(self, data, id=None, collection=None, permissions=None,
293293
bucket=None, safe=True, method='put',
294-
last_modified=None):
294+
if_match=None):
295295
id = id or data.get('id')
296296
if id is None:
297297
raise KeyError('Unable to update a record, need an id.')
298298
endpoint = self._get_endpoint('record', bucket, collection, id)
299-
headers = self._get_cache_headers(safe, data, last_modified)
299+
headers = self._get_cache_headers(safe, data, if_match)
300300
resp, _ = self.session.request(method, endpoint, data=data,
301301
headers=headers,
302302
permissions=permissions)
@@ -307,16 +307,16 @@ def patch_record(self, *args, **kwargs):
307307
return self.update_record(*args, **kwargs)
308308

309309
def delete_record(self, id, collection=None, bucket=None,
310-
safe=True, last_modified=None):
310+
safe=True, if_match=None):
311311
endpoint = self._get_endpoint('record', bucket, collection, id)
312-
headers = self._get_cache_headers(safe, last_modified=last_modified)
312+
headers = self._get_cache_headers(safe, if_match=if_match)
313313
resp, _ = self.session.request('delete', endpoint, headers=headers)
314314
return resp['data']
315315

316316
def delete_records(self, collection=None, bucket=None,
317-
safe=True, last_modified=None):
317+
safe=True, if_match=None):
318318
endpoint = self._get_endpoint('records', bucket, collection)
319-
headers = self._get_cache_headers(safe, last_modified=last_modified)
319+
headers = self._get_cache_headers(safe, if_match=if_match)
320320
resp, _ = self.session.request('delete', endpoint, headers=headers)
321321
return resp['data']
322322

kinto_client/tests/test_client.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ def test_patch_is_issued_on_patch(self):
136136
permissions={'read': ['natim']},
137137
headers=None)
138138

139-
def test_update_bucket_handles_last_modified(self):
139+
def test_update_bucket_handles_if_match(self):
140140
self.client.update_bucket(
141141
'testbucket',
142142
data={'foo': 'bar'},
143-
last_modified=1234)
143+
if_match=1234)
144144
self.session.request.assert_called_with(
145145
'put',
146146
'/buckets/testbucket',
@@ -203,8 +203,8 @@ def test_delete_bucket_returns_the_contained_data(self):
203203
mock_response(self.session, data={'deleted': True})
204204
assert self.client.delete_bucket('bucket') == {'deleted': True}
205205

206-
def test_delete_bucket_handles_last_modified(self):
207-
self.client.delete_bucket('mybucket', last_modified=1234)
206+
def test_delete_bucket_handles_if_match(self):
207+
self.client.delete_bucket('mybucket', if_match=1234)
208208
url = '/buckets/mybucket'
209209
headers = {'If-Match': '"1234"'}
210210
self.session.request.assert_called_with('delete', url, headers=headers)
@@ -282,11 +282,11 @@ def test_collection_update_issues_an_http_put(self):
282282
'put', url, data={'foo': 'bar'},
283283
permissions=mock.sentinel.permissions, headers=None)
284284

285-
def test_update_handles_last_modified(self):
285+
def test_update_handles_if_match(self):
286286
self.client.update_collection(
287287
{'foo': 'bar'},
288288
collection='mycollection',
289-
last_modified=1234)
289+
if_match=1234)
290290

291291
url = '/buckets/mybucket/collections/mycollection'
292292
headers = {'If-Match': '"1234"'}
@@ -317,11 +317,11 @@ def test_patch_collection_issues_an_http_patch(self):
317317
'patch', url, data={'key': 'secret'}, headers=None,
318318
permissions=None)
319319

320-
def test_patch_collection_handles_last_modified(self):
320+
def test_patch_collection_handles_if_match(self):
321321
self.client.patch_collection(
322322
collection='mycollection',
323323
data={'key': 'secret'},
324-
last_modified=1234)
324+
if_match=1234)
325325

326326
url = '/buckets/mybucket/collections/mycollection'
327327
headers = {'If-Match': '"1234"'}
@@ -366,7 +366,7 @@ def test_collection_delete_if_match(self):
366366
mock_response(self.session, data=data)
367367
deleted = self.client.delete_collection(
368368
'mycollection',
369-
last_modified=1234)
369+
if_match=1234)
370370
assert deleted == data
371371
url = '/buckets/mybucket/collections/mycollection'
372372
self.session.request.assert_called_with(
@@ -377,7 +377,7 @@ def test_collection_delete_if_match_not_included_if_not_safe(self):
377377
mock_response(self.session, data=data)
378378
deleted = self.client.delete_collection(
379379
'mycollection',
380-
last_modified=1324,
380+
if_match=1324,
381381
safe=False)
382382
assert deleted == data
383383
url = '/buckets/mybucket/collections/mycollection'
@@ -588,7 +588,7 @@ def test_record_delete_if_match(self):
588588
collection='mycollection',
589589
bucket='mybucket',
590590
id='1',
591-
last_modified=1234)
591+
if_match=1234)
592592
assert deleted == data
593593
url = '/buckets/mybucket/collections/mycollection/records/1'
594594
self.session.request.assert_called_with(
@@ -601,7 +601,7 @@ def test_record_delete_if_match_not_included_if_not_safe(self):
601601
collection='mycollection',
602602
bucket='mybucket',
603603
id='1',
604-
last_modified=1234,
604+
if_match=1234,
605605
safe=False)
606606
assert deleted == data
607607
url = '/buckets/mybucket/collections/mycollection/records/1'
@@ -618,11 +618,11 @@ def test_update_record_gets_the_id_from_data_if_exists(self):
618618
'put', '/buckets/mybucket/collections/mycollection/records/1',
619619
data={'id': 1, 'foo': 'bar'}, headers=None, permissions=None)
620620

621-
def test_update_record_handles_last_modified(self):
621+
def test_update_record_handles_if_match(self):
622622
mock_response(self.session)
623623
self.client.update_record(
624624
bucket='mybucket', collection='mycollection',
625-
data={'id': 1, 'foo': 'bar'}, last_modified=1234)
625+
data={'id': 1, 'foo': 'bar'}, if_match=1234)
626626

627627
headers = {'If-Match': '"1234"'}
628628
self.session.request.assert_called_with(

0 commit comments

Comments
 (0)