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

Decorators that accepts kwargs from URL test #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion test_classy/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ def test_func_decorator_index():

def test_func_decorator_get():
resp = client.get('/decorated/1234')
eq_(b"Get 1234", resp.data)
eq_(b"Get 1234", resp.data)

def test_func_special_decorator():
resp = client.get('/decorated/special/someid')
eq_(b"someid1", resp.data)
14 changes: 13 additions & 1 deletion test_classy/view_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,14 @@ def decorated_view(*args, **kwargs):
def wraps_decorator(f):
@wraps(f)
def decorated_view(*args, **kwargs):
return f(*args, **kwargs)
return f(*args, **kwargs)
return decorated_view

def specialized_decorator(f):
@wraps(f)
def decorated_view(id, *args, **kwargs):
transformed_id = id + "1"
return f(transformed_id, *args, **kwargs)
return decorated_view

class DecoratedView(FlaskView):
Expand All @@ -153,3 +160,8 @@ def index(self):
@func_decorator
def get(self, id):
return "Get " + id

@route("/special/<id>")
@specialized_decorator
def special(self, transformed_id):
return transformed_id