Repository navigation
Fix #370 by adding an alias of next arg (next_) in middleware arguments
#394
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,10 +45,10 @@ def run_middleware( | |
| for m in self.middleware: | ||
| middleware_state = {"next_called": False} | ||
|
|
||
| def next(): | ||
| def next_(): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not an essential part of this PR. It's just a minor refactoring |
||
| middleware_state["next_called"] = True | ||
|
|
||
| resp = m.process(req=req, resp=resp, next=next) | ||
| resp = m.process(req=req, resp=resp, next=next_) | ||
| if not middleware_state["next_called"]: | ||
| # next() was not called in this middleware | ||
| return (resp, True) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,6 +87,53 @@ def test_next_call(self): | |
| assert response.body == "acknowledged!" | ||
| assert_auth_test_count(self, 1) | ||
|
|
||
| def test_decorator_next_call(self): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checking these test patterns should be helpful for knowing the purpose of the changes. |
||
| app = App( | ||
| client=self.web_client, | ||
| signing_secret=self.signing_secret, | ||
| ) | ||
|
|
||
| @app.middleware | ||
| def just_next(next): | ||
| next() | ||
|
|
||
| app.shortcut("test-shortcut")(just_ack) | ||
|
|
||
| response = app.dispatch(self.build_request()) | ||
| assert response.status == 200 | ||
| assert response.body == "acknowledged!" | ||
| assert_auth_test_count(self, 1) | ||
|
|
||
| def test_next_call_(self): | ||
| app = App( | ||
| client=self.web_client, | ||
| signing_secret=self.signing_secret, | ||
| ) | ||
| app.use(just_next_) | ||
| app.shortcut("test-shortcut")(just_ack) | ||
|
|
||
| response = app.dispatch(self.build_request()) | ||
| assert response.status == 200 | ||
| assert response.body == "acknowledged!" | ||
| assert_auth_test_count(self, 1) | ||
|
|
||
| def test_decorator_next_call_(self): | ||
| app = App( | ||
| client=self.web_client, | ||
| signing_secret=self.signing_secret, | ||
| ) | ||
|
|
||
| @app.middleware | ||
| def just_next_(next_): | ||
| next_() | ||
|
|
||
| app.shortcut("test-shortcut")(just_ack) | ||
|
|
||
| response = app.dispatch(self.build_request()) | ||
| assert response.status == 200 | ||
| assert response.body == "acknowledged!" | ||
| assert_auth_test_count(self, 1) | ||
|
|
||
| def test_class_call(self): | ||
| class NextClass: | ||
| def __call__(self, next): | ||
|
|
@@ -104,6 +151,23 @@ def __call__(self, next): | |
| assert response.body == "acknowledged!" | ||
| assert_auth_test_count(self, 1) | ||
|
|
||
| def test_class_call_(self): | ||
| class NextUnderscoreClass: | ||
| def __call__(self, next_): | ||
| next_() | ||
|
|
||
| app = App( | ||
| client=self.web_client, | ||
| signing_secret=self.signing_secret, | ||
| ) | ||
| app.use(NextUnderscoreClass()) | ||
| app.shortcut("test-shortcut")(just_ack) | ||
|
|
||
| response = app.dispatch(self.build_request()) | ||
| assert response.status == 200 | ||
| assert response.body == "acknowledged!" | ||
| assert_auth_test_count(self, 1) | ||
|
|
||
|
|
||
| def just_ack(ack): | ||
| ack("acknowledged!") | ||
|
|
@@ -115,3 +179,7 @@ def no_next(): | |
|
|
||
| def just_next(next): | ||
| next() | ||
|
|
||
|
|
||
| def just_next_(next_): | ||
| next_() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this enables bolt-python to resolve the alias name as well.