Add Slack connect API support + tests#1089
Conversation
c253296 to
9eae59a
Compare
Codecov Report
@@ Coverage Diff @@
## main #1089 +/- ##
==========================================
+ Coverage 86.07% 86.19% +0.11%
==========================================
Files 110 110
Lines 9847 9928 +81
==========================================
+ Hits 8476 8557 +81
Misses 1371 1371
Continue to review full report at Codecov.
|
seratch
left a comment
There was a problem hiding this comment.
Left a few (early) comments. I hope these were helpful to you!
slack_sdk/web/client.py
Outdated
| channel_id: str = None, | ||
| invite_id: str = None, |
There was a problem hiding this comment.
I know some existing methods (e.g., views_update) are not yet consistent about this but let's use Optional type hint for the value that can be None.
| channel_id: str = None, | |
| invite_id: str = None, | |
| channel_id: Optional[str] = None, | |
| invite_id: Optional[str] = None, |
For existing others, we are happy to change the type hint this time! We don't call it a breaking change. It's a correction that does not affect runtime behavior.
There was a problem hiding this comment.
Sure thing. I see that the type hint is another way of declaring a union type with None. I've included that for other existing methods that don't currently use the Optional type hint as well (including views_update) in the latest changes.
slack_sdk/web/client.py
Outdated
| kwargs.update({"channel_id": channel_id}) | ||
| else: | ||
| kwargs.update({"invite_id": invite_id}) | ||
| return self.api_call("conversations.acceptSharedInvite", json=kwargs) |
There was a problem hiding this comment.
If there is no strong reason to use json request body here, let's use params for new ones. Although this method does not have any array arguments at this moment, we may encounter #1054 with future updates of the endpoint.
There was a problem hiding this comment.
Thanks for the context with #1054. I've modified acceptSharedInvite and approveSharedInvite to accept params instead.
| @@ -0,0 +1,129 @@ | |||
| import logging | |||
There was a problem hiding this comment.
As this file has only tests for Slack Connect APIs, how about naming it to test_conversations_connect.py? If we will have integration tests for other conversations.* endpoints in the future, we can have them in a different file.
| invite_id=invite["invite_id"], | ||
| ) | ||
|
|
||
| # clean up created channel |
There was a problem hiding this comment.
How about having this part with if channel_id is not None: in finally clause? We can have a new local variable channel_id: Optional[str] outside the try/finally block.
There was a problem hiding this comment.
Yes, that is much nicer - and we will always attempt to cleanup any channels in the course of the test. Thanks for the suggestion - I've included these changes!
srajiang
left a comment
There was a problem hiding this comment.
Thanks always for the prompt feedback! I've included some updates based on that feedback.
slack_sdk/web/client.py
Outdated
| channel_id: str = None, | ||
| invite_id: str = None, |
There was a problem hiding this comment.
Sure thing. I see that the type hint is another way of declaring a union type with None. I've included that for other existing methods that don't currently use the Optional type hint as well (including views_update) in the latest changes.
slack_sdk/web/client.py
Outdated
| kwargs.update({"channel_id": channel_id}) | ||
| else: | ||
| kwargs.update({"invite_id": invite_id}) | ||
| return self.api_call("conversations.acceptSharedInvite", json=kwargs) |
There was a problem hiding this comment.
Thanks for the context with #1054. I've modified acceptSharedInvite and approveSharedInvite to accept params instead.
| invite_id=invite["invite_id"], | ||
| ) | ||
|
|
||
| # clean up created channel |
There was a problem hiding this comment.
Yes, that is much nicer - and we will always attempt to cleanup any channels in the course of the test. Thanks for the suggestion - I've included these changes!
| def test_sync(self): | ||
| sender = self.sender_sync_client | ||
| receiver = self.receiver_sync_client | ||
| channel_id: Optional[str] |
There was a problem hiding this comment.
If there is no assignment and we access the value in finally clause, it should raise an exception.
| channel_id: Optional[str] | |
| channel_id: Optional[str] = None |
| ) | ||
|
|
||
| # For Slack Connect shared tests | ||
| SLACK_SDK_TEST_SENDER_BOT_TOKEN = "SLACK_SDK_TEST_SENDER_BOT_TOKEN" |
There was a problem hiding this comment.
Can we make these names more specific?
| SLACK_SDK_TEST_SENDER_BOT_TOKEN = "SLACK_SDK_TEST_SENDER_BOT_TOKEN" | |
| SLACK_SDK_TEST_CONNECT_INVITE_SENDER_BOT_TOKEN = "SLACK_SDK_TEST_CONNECT_INVITE_SENDER_BOT_TOKEN" |
| date: Optional[str] = None, | ||
| metadata_only: Optional[bool] = None, | ||
| **kwargs | ||
| **kwargs, |
There was a problem hiding this comment.
This is fine to have these changes but, out of curiosity, do you use some code formatter that does this? I don't believe that you manually added these commas.
There was a problem hiding this comment.
Right, these were added by the Python extension I have in my VSCode, it seems. But I kept it in there because it seemed better style to leave the trailing commas in there.
|
Probably, we can merge this PR soon. I've moved this one to v3.9 milestone. |
Thanks @seratch - I think it should be ready now with the last set of tweaks based on your last comments. |
| date: Optional[str] = None, | ||
| metadata_only: Optional[bool] = None, | ||
| **kwargs | ||
| **kwargs, |
Summary
Fixes #1058 by adding support for recently added Slack Connect AP methods.
Category (place an
xin each of the[ ])/docs-src(Documents, have you run./docs.sh?)/docs-src-v2(Documents, have you run./docs-v2.sh?)/tutorial(PythOnBoardingBot tutorial)tests/integration_tests(Automated tests for this library)Requirements (place an
xin each[ ])python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.shafter making the changes.