Skip to content

Commit

Permalink
Merge pull request #500 from jpvanhal/patch/empty-url-prefix
Browse files Browse the repository at this point in the history
Allow empty string as the `url_prefix`
  • Loading branch information
jfinkels committed Mar 14, 2016
2 parents 18ded62 + 70b6549 commit df69be6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion flask_restless/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,12 @@ def create_api_blueprint(self, name, model, methods=READONLY_METHODS,
# instance
# TODO what should the second argument here be?
# TODO should the url_prefix be specified here or in register_blueprint
prefix = url_prefix or self.url_prefix or DEFAULT_URL_PREFIX
if url_prefix is not None:
prefix = url_prefix
elif self.url_prefix is not None:
prefix = self.url_prefix
else:
prefix = DEFAULT_URL_PREFIX
blueprint = Blueprint(name, __name__, url_prefix=prefix)
add_rule = blueprint.add_url_rule

Expand Down
18 changes: 18 additions & 0 deletions tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,19 @@ def test_url_prefix(self):
response = self.app.get('/api/person')
assert response.status_code == 404

def test_empty_url_prefix(self):
"""Tests for specifying an empty string as URL prefix at the manager
level but not when creating an API.
"""
manager = APIManager(self.flaskapp, session=self.session,
url_prefix='')
manager.create_api(self.Person)
response = self.app.get('/person')
assert response.status_code == 200
response = self.app.get('/api/person')
assert response.status_code == 404

def test_override_url_prefix(self):
"""Tests that a call to :meth:`APIManager.create_api` can
override the URL prefix provided in the constructor to the
Expand All @@ -229,10 +242,15 @@ def test_override_url_prefix(self):
manager = APIManager(self.flaskapp, session=self.session,
url_prefix='/foo')
manager.create_api(self.Person, url_prefix='/bar')
manager.create_api(self.Article, url_prefix='')
response = self.app.get('/bar/person')
assert response.status_code == 200
response = self.app.get('/article')
assert response.status_code == 200
response = self.app.get('/foo/person')
assert response.status_code == 404
response = self.app.get('/foo/article')
assert response.status_code == 404

# # This is a possible feature, but we will not support this for now.
# def test_append_url_prefix(self):
Expand Down

0 comments on commit df69be6

Please sign in to comment.