Skip to content

Commit

Permalink
Merge pull request #44 from Kinto/43-create-bucket
Browse files Browse the repository at this point in the history
Fix crash when creating bucket with POST /buckets (fixes #43)
  • Loading branch information
Natim authored Jun 28, 2017
2 parents 849fc6d + 53e844c commit 6713b63
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ This document describes changes between each past release.
0.5.0 (unreleased)
------------------

- Nothing changed yet.
**Bug fixes**

- Fix crash when creating bucket with ``POST /buckets`` (fixes #43)


0.4.0 (2017-04-14)
Expand Down
6 changes: 5 additions & 1 deletion kinto_emailer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,13 @@ def get_messages(storage, context):

def _validate_emailer_settings(event):
request = event.request
bucket_uri = '/buckets/{bucket_id}'.format(**event.payload)
resource_name = event.payload['resource_name']

for impacted in event.impacted_records:
# See Kinto/kinto#945
bid = impacted['new']['id'] if resource_name == "bucket" else event.payload['bucket_id']
bucket_uri = '/buckets/{}'.format(bid)

metadata = impacted['new']
if 'kinto-emailer' not in metadata:
continue
Expand Down
13 changes: 12 additions & 1 deletion kinto_emailer/tests/test_includeme.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,18 @@ def test_fails_with_missing_hooks(self):
status=400)
assert 'Missing "hooks"' in r.json['message']

def test_validation_errors_are_well_formatted(self):
def test_bucket_validation_errors_are_well_formatted(self):
self.valid_collection['kinto-emailer'].pop('hooks')
r = self.app.post_json('/buckets',
{'data': self.valid_collection},
headers=self.headers,
status=400)
self.assertFormattedError(r, 400,
errno=errors.ERRORS.INVALID_PARAMETERS,
error='Invalid parameters',
message='Missing "hooks"', info=None)

def test_collection_validation_errors_are_well_formatted(self):
self.valid_collection['kinto-emailer'].pop('hooks')
r = self.app.put_json('/buckets/b/collections/c',
{'data': self.valid_collection},
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def read_file(filename):


REQUIREMENTS = [
'pyramid < 1.9',
'kinto > 5',
'pyramid_mailer',
]
Expand Down
2 changes: 2 additions & 0 deletions validate_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def main(args=None):

args = parser.parse_args(args)

cli_utils.setup_logger(logger, args)

client = cli_utils.create_client_from_args(args)

# 1. Check capabilities
Expand Down

0 comments on commit 6713b63

Please sign in to comment.