Skip to content

Commit

Permalink
Merge pull request #476 from ergo/master
Browse files Browse the repository at this point in the history
configurator: cornice should not commit configuration ever (fixes #440)
  • Loading branch information
leplatrem committed Mar 26, 2018
2 parents fcda515 + c849a85 commit bd1c9d0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
3 changes: 0 additions & 3 deletions cornice/pyramidhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,12 @@ def register_service_views(config, service):
config.add_view(view=decorated_view, route_name=route_name,
**args)

config.commit()

if service.definitions:
# Add the fallback view last
config.add_view(view=get_fallback_view(service),
route_name=route_name,
permission=NO_PERMISSION_REQUIRED,
require_csrf=False)
config.commit()


def _pop_complex_predicates(args):
Expand Down
2 changes: 1 addition & 1 deletion cornice/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def add_resource(klass, depth=1, **kw):
(collection_path), if any.
:param klass:
The class (resource) on witch to register the service.
The class (resource) on which to register the service.
:param depth:
Witch frame should be looked in default 2.
Expand Down
5 changes: 3 additions & 2 deletions tests/test_imperative_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def setUp(self):
name='thing_service')

add_view(UserImp.get, renderer='json')
add_view(UserImp.get, renderer='jsonp')
add_view(UserImp.get, renderer='jsonp', accept='application/javascript')
add_view(UserImp.collection_post, renderer='json', accept='text/json')
user_resource = add_resource(
UserImp, collection_path='/users', path='/users/{id}',
Expand Down Expand Up @@ -182,7 +182,8 @@ def setUp(self):
self.config.include("cornice")

add_view(UserImp.get, renderer='json')
add_view(UserImp.get, renderer='jsonp')
# pyramid does not allow having 2 views with same request conditions
add_view(UserImp.get, renderer='jsonp', accept='application/javascript')
add_view(UserImp.collection_post, renderer='json', accept='text/json')
user_resource = add_resource(
UserImp, collection_path='/users', path='/users/{id}',
Expand Down
5 changes: 3 additions & 2 deletions tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, request, context=None):
def collection_get(self):
return {'users': list(USERS.keys())}

@view(renderer='jsonp')
@view(renderer='jsonp', accept='application/javascript')
@view(renderer='json')
def get(self):
return USERS.get(int(self.request.matchdict['id']))
Expand Down Expand Up @@ -109,7 +109,8 @@ def test_basic_resource(self):

self.assertEqual(self.app.get("/users/1").json, {'name': 'gawel'})

resp = self.app.get("/users/1?callback=test")
resp = self.app.get("/users/1?callback=test",
headers={'Accept': 'application/javascript'})

self.assertIn(b'test({"name": "gawel"})', resp.body, msg=resp.body)

Expand Down

0 comments on commit bd1c9d0

Please sign in to comment.