Skip to content

Commit

Permalink
Merge pull request #292 from circlingthesun/path-check
Browse files Browse the repository at this point in the history
Add resource path warning
  • Loading branch information
almet committed Apr 30, 2015
2 parents a082a1b + ef4fd62 commit ca8d00c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cornice/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
import warnings
from cornice import Service
try:
import venusian
Expand All @@ -26,6 +27,10 @@ def wrapper(klass):
services = {}

if 'collection_path' in kw:
if kw['collection_path'] == kw['path']:
msg = "Warning: collection_path and path are not distinct."
warnings.warn(msg)

prefixes = ('', 'collection_')
else:
prefixes = ('',)
Expand Down
14 changes: 14 additions & 0 deletions cornice/tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,24 @@ def put(self):
return dict(type=repr(self.context))


class TestResourceWarning(TestCase):
@mock.patch('warnings.warn')
def test_path_clash(self, mocked_warn):
@resource(collection_path='/badthing/{id}', path='/badthing/{id}',
name='bad_thing_service')
class BadThing(object):
def __init__(self, request, context=None):
pass

msg = "Warning: collection_path and path are not distinct."
mocked_warn.assert_called_with(msg)


class TestResource(TestCase):

def setUp(self):
from pyramid.renderers import JSONP

self.config = testing.setUp()
self.config.add_renderer('jsonp', JSONP(param_name='callback'))
self.config.include("cornice")
Expand Down

0 comments on commit ca8d00c

Please sign in to comment.