Skip to content

Commit

Permalink
Merge pull request #413 from dairiki/issue.411
Browse files Browse the repository at this point in the history
Restore old semantics of location='path' (fixes #411)
  • Loading branch information
leplatrem committed Oct 26, 2016
2 parents fc290ba + 4481c12 commit 94b47ef
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
10 changes: 10 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ CHANGELOG

- Nothing changed yet.

2.0.3 (unreleased)
==================

**Bug fixes**

- To maintain consistency with cornice 1.2 as to the semantics of
``location='path'``, change ``cornice.validators.extract_cstruct``
so that it places ``request.matchdict`` (rather than
``request.path``) into ``cstruct['path']``. (#411)


2.0.2 (2016-10-25)
==================
Expand Down
2 changes: 1 addition & 1 deletion cornice/validators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def extract_cstruct(request):

cstruct = {'method': request.method,
'url': request.url,
'path': request.path,
'path': request.matchdict,
'body': body}

for sub, attr in (('querystring', 'GET'),
Expand Down
6 changes: 6 additions & 0 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ def test_validated_querystring_and_schema_from_same_schema(self):
self.assertEqual(response.json['errors'][0]['description'],
'Invalid email length')

def test_validated_path_content_from_schema(self):
# Test validation request.matchdict. (See #411)
app = TestApp(main({}))
response = app.get('/item/42', status=200)
self.assertEqual(response.json, {'item_id': 42})

def test_content_type_with_no_body_should_pass(self):
app = TestApp(main({}))

Expand Down
13 changes: 13 additions & 0 deletions tests/validationapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,19 @@ def deserialize(self, cstruct=null):
def newsletter(request):
return request.validated

class ItemPathSchema(MappingSchema):
item_id = SchemaNode(Integer())

class ItemSchema(MappingSchema):
path = ItemPathSchema()

item_service = Service(name='item', path='/item/{item_id}')

@item_service.get(schema=ItemSchema,
validators=(colander_validator,))
def item(request):
return request.validated['path']


def includeme(config):
config.include("cornice")
Expand Down

0 comments on commit 94b47ef

Please sign in to comment.