Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow empty string as the url_prefix #500

Merged
merged 1 commit into from
Mar 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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