Skip to content

Commit ac8274c

Browse files
author
Rémy HUBSCHER
committed
@leplatrem review.
1 parent 4ca2c44 commit ac8274c

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

kinto_client/__init__.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ def create_collection(self, collection=None, bucket=None,
225225
headers=headers)
226226
except KintoException as e:
227227
if e.response.status_code == 403:
228-
msg = "Unauthorized. Please check that the bucket exists."
228+
msg = ("Unauthorized. Please check that the bucket exists and "
229+
"that you have the permission to create or write this "
230+
"collection.")
229231
e = KintoException(msg, e)
230232
raise e
231233
return resp
@@ -290,9 +292,18 @@ def create_record(self, data, id=None, collection=None, permissions=None,
290292
headers = DO_NOT_OVERWRITE if safe else None
291293

292294
endpoint = self._get_endpoint('record', bucket, collection, id)
293-
resp, _ = self.session.request('put', endpoint, data=data,
294-
permissions=permissions,
295-
headers=headers)
295+
try:
296+
resp, _ = self.session.request('put', endpoint, data=data,
297+
permissions=permissions,
298+
headers=headers)
299+
except KintoException as e:
300+
if e.response.status_code == 403:
301+
msg = ("Unauthorized. Please check that the collection exists "
302+
"and that you have the permission to create or write "
303+
"this record.")
304+
e = KintoException(msg, e)
305+
raise e
306+
296307
return resp
297308

298309
def update_record(self, data, id=None, collection=None, permissions=None,

kinto_client/tests/test_client.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,10 @@ def test_create_collection_raises_a_special_error_on_403(self):
412412
self.client.create_collection(
413413
bucket="buck",
414414
collection="coll")
415-
expected_msg = "Unauthorized. Please check that the bucket exists."
416-
e.exception.message = expected_msg
415+
expected_msg = ("Unauthorized. Please check that the bucket exists "
416+
"and that you have the permission to create or write "
417+
"this collection.")
418+
assert e.exception.message == expected_msg
417419

418420

419421
class RecordTest(unittest.TestCase):
@@ -683,3 +685,15 @@ def test_get_or_create_raise_in_other_cases(self):
683685
collection="coll",
684686
data={'foo': 'bar'},
685687
if_not_exists=True)
688+
689+
def test_create_record_raises_a_special_error_on_403(self):
690+
self.session.request.side_effect = get_http_error(status=403)
691+
with self.assertRaises(KintoException) as e:
692+
self.client.create_record(
693+
bucket="buck",
694+
collection="coll",
695+
data={'foo': 'bar'})
696+
expected_msg = ("Unauthorized. Please check that the collection exists"
697+
" and that you have the permission to create or write "
698+
"this record.")
699+
assert e.exception.message == expected_msg

0 commit comments

Comments
 (0)