Repository navigation
Fix #307 Add options to disable the built-in middleware #310
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
Merged
seratch
merged 4 commits into
slackapi:main
from
seratch:issue-307-disabling-builtin-middleware
Apr 29, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5c07faf
Fix #307 Add options to disable the built-in middleware
seratch 3a3bf01
Merge branch 'main' into issue-307-disabling-builtin-middleware
seratch ced62a5
Merge branch 'main' into issue-307-disabling-builtin-middleware
seratch 3d67252
Merge branch 'main' into issue-307-disabling-builtin-middleware
seratch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| from time import sleep | ||
|
|
||
| from slack_sdk.web import WebClient | ||
|
|
||
| from slack_bolt import App, BoltRequest | ||
| from tests.mock_web_api_server import ( | ||
| setup_mock_web_api_server, | ||
| cleanup_mock_web_api_server, | ||
| assert_auth_test_count, | ||
| ) | ||
| from tests.utils import remove_os_env_temporarily, restore_os_env | ||
|
|
||
|
|
||
| class TestEventsIgnoreSelf: | ||
| valid_token = "xoxb-valid" | ||
| mock_api_server_base_url = "http://localhost:8888" | ||
| web_client = WebClient( | ||
| token=valid_token, | ||
| base_url=mock_api_server_base_url, | ||
| ) | ||
|
|
||
| def setup_method(self): | ||
| self.old_os_env = remove_os_env_temporarily() | ||
| setup_mock_web_api_server(self) | ||
|
|
||
| def teardown_method(self): | ||
| cleanup_mock_web_api_server(self) | ||
| restore_os_env(self.old_os_env) | ||
|
|
||
| def test_self_events(self): | ||
| app = App(client=self.web_client) | ||
|
|
||
| @app.event("reaction_added") | ||
| def handle_app_mention(say): | ||
| say("What's up?") | ||
|
|
||
| request: BoltRequest = BoltRequest(body=event_body, mode="socket_mode") | ||
| response = app.dispatch(request) | ||
| assert response.status == 200 | ||
| assert_auth_test_count(self, 1) | ||
| sleep(1) # wait a bit after auto ack() | ||
| # The listener should not be executed | ||
| assert self.mock_received_requests.get("/chat.postMessage") is None | ||
|
|
||
| def test_self_events_disabled(self): | ||
| app = App( | ||
| client=self.web_client, | ||
| ignoring_self_events_enabled=False, | ||
| ) | ||
|
|
||
| @app.event("reaction_added") | ||
| def handle_app_mention(say): | ||
| say("What's up?") | ||
|
|
||
| request: BoltRequest = BoltRequest(body=event_body, mode="socket_mode") | ||
| response = app.dispatch(request) | ||
| assert response.status == 200 | ||
| assert_auth_test_count(self, 1) | ||
| sleep(1) # wait a bit after auto ack() | ||
| # The listener should be executed as the ignoring logic is disabled | ||
| assert self.mock_received_requests.get("/chat.postMessage") == 1 | ||
|
|
||
|
|
||
| event_body = { | ||
| "token": "verification_token", | ||
| "team_id": "T111", | ||
| "enterprise_id": "E111", | ||
| "api_app_id": "A111", | ||
| "event": { | ||
| "type": "reaction_added", | ||
| "user": "W23456789", # bot_user_id | ||
| "item": { | ||
| "type": "message", | ||
| "channel": "C111", | ||
| "ts": "1599529504.000400", | ||
| }, | ||
| "reaction": "heart_eyes", | ||
| "item_user": "W111", | ||
| "event_ts": "1599616881.000800", | ||
| }, | ||
| "type": "event_callback", | ||
| "event_id": "Ev111", | ||
| "event_time": 1599616881, | ||
| "authed_users": ["W111"], | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I moved this to
test_events_ignore_self.py