Skip to content

Commit 4fafad4

Browse files
authored
Merge pull request #150 from Kinto/147-more-context-on-KintoException
Add more context on KintoExceptions
2 parents 7989121 + 4727d8e commit 4fafad4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

kinto_http/exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ def __init__(self, message=None, exception=None):
1212
self.request = None
1313
self.response = None
1414

15+
def __str__(self):
16+
if self.request is not None and self.response is not None:
17+
return '{} {} - {} {}'.format(self.request.method, self.request.path_url,
18+
self.response.status_code, self.message)
19+
return self.message
20+
1521

1622
class BucketNotFound(KintoException):
1723
pass

kinto_http/tests/functional.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,18 @@ def test_group_creation_if_not_exists(self):
131131
if_not_exists=True)
132132

133133
def test_group_creation_if_bucket_does_not_exist(self):
134-
with pytest.raises(KintoException):
134+
with pytest.raises(KintoException) as e:
135135
self.client.create_group(
136136
id='payments', bucket='mozilla',
137137
data={'members': ['blah', ]})
138138
self.client.create_group(
139139
id='payments', bucket='mozilla',
140140
data={'members': ['blah', ]},
141141
if_not_exists=True)
142+
assert str(e).endswith('PUT /v1/buckets/mozilla/groups/payments - '
143+
'403 Unauthorized. Please check that the '
144+
'bucket exists and that you have the permission '
145+
'to create or write on this group.')
142146

143147
def test_group_update(self):
144148
self.client.create_bucket(id='mozilla')

0 commit comments

Comments
 (0)