-
Notifications
You must be signed in to change notification settings - Fork 250
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
Fix #260 Enable to use respond utility in app.view listeners (only when response_urls exists) #288
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 |
---|---|---|
|
@@ -15,6 +15,133 @@ | |
from tests.utils import remove_os_env_temporarily, restore_os_env | ||
|
||
|
||
body = { | ||
"type": "view_submission", | ||
"team": { | ||
"id": "T111", | ||
"domain": "workspace-domain", | ||
"enterprise_id": "E111", | ||
"enterprise_name": "Sandbox Org", | ||
}, | ||
"user": { | ||
"id": "W111", | ||
"username": "primary-owner", | ||
"name": "primary-owner", | ||
"team_id": "T111", | ||
}, | ||
"api_app_id": "A111", | ||
"token": "verification_token", | ||
"trigger_id": "111.222.valid", | ||
"view": { | ||
"id": "V111", | ||
"team_id": "T111", | ||
"type": "modal", | ||
"blocks": [ | ||
{ | ||
"type": "input", | ||
"block_id": "hspI", | ||
"label": { | ||
"type": "plain_text", | ||
"text": "Label", | ||
}, | ||
"optional": False, | ||
"element": {"type": "plain_text_input", "action_id": "maBWU"}, | ||
} | ||
], | ||
"private_metadata": "This is for you!", | ||
"callback_id": "view-id", | ||
"state": { | ||
"values": {"hspI": {"maBWU": {"type": "plain_text_input", "value": "test"}}} | ||
}, | ||
"hash": "1596530361.3wRYuk3R", | ||
"title": { | ||
"type": "plain_text", | ||
"text": "My App", | ||
}, | ||
"clear_on_close": False, | ||
"notify_on_close": False, | ||
"close": { | ||
"type": "plain_text", | ||
"text": "Cancel", | ||
}, | ||
"submit": { | ||
"type": "plain_text", | ||
"text": "Submit", | ||
}, | ||
"previous_view_id": None, | ||
"root_view_id": "V111", | ||
"app_id": "A111", | ||
"external_id": "", | ||
"app_installed_team_id": "T111", | ||
"bot_id": "B111", | ||
}, | ||
"response_urls": [], | ||
} | ||
|
||
raw_body = f"payload={quote(json.dumps(body))}" | ||
|
||
|
||
def simple_listener(ack, body, payload, view): | ||
assert body["trigger_id"] == "111.222.valid" | ||
assert body["view"] == payload | ||
assert payload == view | ||
assert view["private_metadata"] == "This is for you!" | ||
ack() | ||
|
||
|
||
response_url_payload_body = { | ||
"type": "view_submission", | ||
"team": {"id": "T111", "domain": "test-test-test"}, | ||
"user": { | ||
"id": "U111", | ||
"username": "test-test-test", | ||
"name": "test-test-test", | ||
"team_id": "T111", | ||
}, | ||
"api_app_id": "A111", | ||
"token": "verification-token", | ||
"trigger_id": "111.222.xxx", | ||
"view": { | ||
"id": "V111", | ||
"team_id": "T111", | ||
"type": "modal", | ||
"blocks": [], | ||
"callback_id": "view-id", | ||
"state": {}, | ||
"title": { | ||
"type": "plain_text", | ||
"text": "My App", | ||
}, | ||
"close": { | ||
"type": "plain_text", | ||
"text": "Cancel", | ||
}, | ||
"submit": { | ||
"type": "plain_text", | ||
"text": "Submit", | ||
}, | ||
"previous_view_id": None, | ||
"root_view_id": "V111", | ||
"app_id": "A111", | ||
"external_id": "", | ||
"app_installed_team_id": "T111", | ||
"bot_id": "B111", | ||
}, | ||
"response_urls": [ | ||
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 the field this pull request takes care of. This array can have an element only when a modal has a conversations_select block element with response_url_enabled: true option. |
||
{ | ||
"block_id": "b", | ||
"action_id": "a", | ||
"channel_id": "C111", | ||
"response_url": "http://localhost:8888/webhook", | ||
} | ||
], | ||
"is_enterprise_install": False, | ||
} | ||
|
||
|
||
raw_response_url_body = f"payload={quote(json.dumps(response_url_payload_body))}" | ||
|
||
|
||
class TestViewSubmission: | ||
signing_secret = "secret" | ||
valid_token = "xoxb-valid" | ||
|
@@ -46,11 +173,9 @@ def build_headers(self, timestamp: str, body: str): | |
"x-slack-request-timestamp": [timestamp], | ||
} | ||
|
||
def build_valid_request(self) -> BoltRequest: | ||
def build_valid_request(self, body: str = raw_body) -> BoltRequest: | ||
timestamp = str(int(time())) | ||
return BoltRequest( | ||
body=raw_body, headers=self.build_headers(timestamp, raw_body) | ||
) | ||
return BoltRequest(body=body, headers=self.build_headers(timestamp, body)) | ||
|
||
def test_mock_server_is_running(self): | ||
resp = self.web_client.api_test() | ||
|
@@ -123,76 +248,18 @@ def test_failure_2(self): | |
assert response.status == 404 | ||
assert_auth_test_count(self, 1) | ||
|
||
def test_response_urls(self): | ||
app = App( | ||
client=self.web_client, | ||
signing_secret=self.signing_secret, | ||
) | ||
|
||
body = { | ||
"type": "view_submission", | ||
"team": { | ||
"id": "T111", | ||
"domain": "workspace-domain", | ||
"enterprise_id": "E111", | ||
"enterprise_name": "Sandbox Org", | ||
}, | ||
"user": { | ||
"id": "W111", | ||
"username": "primary-owner", | ||
"name": "primary-owner", | ||
"team_id": "T111", | ||
}, | ||
"api_app_id": "A111", | ||
"token": "verification_token", | ||
"trigger_id": "111.222.valid", | ||
"view": { | ||
"id": "V111", | ||
"team_id": "T111", | ||
"type": "modal", | ||
"blocks": [ | ||
{ | ||
"type": "input", | ||
"block_id": "hspI", | ||
"label": { | ||
"type": "plain_text", | ||
"text": "Label", | ||
}, | ||
"optional": False, | ||
"element": {"type": "plain_text_input", "action_id": "maBWU"}, | ||
} | ||
], | ||
"private_metadata": "This is for you!", | ||
"callback_id": "view-id", | ||
"state": { | ||
"values": {"hspI": {"maBWU": {"type": "plain_text_input", "value": "test"}}} | ||
}, | ||
"hash": "1596530361.3wRYuk3R", | ||
"title": { | ||
"type": "plain_text", | ||
"text": "My App", | ||
}, | ||
"clear_on_close": False, | ||
"notify_on_close": False, | ||
"close": { | ||
"type": "plain_text", | ||
"text": "Cancel", | ||
}, | ||
"submit": { | ||
"type": "plain_text", | ||
"text": "Submit", | ||
}, | ||
"previous_view_id": None, | ||
"root_view_id": "V111", | ||
"app_id": "A111", | ||
"external_id": "", | ||
"app_installed_team_id": "T111", | ||
"bot_id": "B111", | ||
}, | ||
"response_urls": [], | ||
} | ||
|
||
raw_body = f"payload={quote(json.dumps(body))}" | ||
|
||
@app.view("view-id") | ||
def check(ack, respond): | ||
respond("Hi") | ||
ack() | ||
|
||
def simple_listener(ack, body, payload, view): | ||
assert body["trigger_id"] == "111.222.valid" | ||
assert body["view"] == payload | ||
assert payload == view | ||
assert view["private_metadata"] == "This is for you!" | ||
ack() | ||
request = self.build_valid_request(raw_response_url_body) | ||
response = app.dispatch(request) | ||
assert response.status == 200 | ||
assert_auth_test_count(self, 1) |
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.
Just for consistency with
internals.py
. This method name does not start with_
but this is part ofinternals
source file. I think it's safe to change the name in the next minor release as no one relies on the argument name.