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

Add bookmarks.* API support #1176

Merged
merged 2 commits into from Feb 17, 2022
Merged

Add bookmarks.* API support #1176

merged 2 commits into from Feb 17, 2022

Conversation

filmaj
Copy link
Contributor

@filmaj filmaj commented Feb 16, 2022

Summary

This PR adds support for the add/edit/list/remove bookmark APIs.

This is my first PR adding support for new APIs, so reviews are appreciated. Maybe I missed some stuff? I.e. maybe integration tests? Not sure, would very much appreciate your guidance @seratch 🙇

Category (place an x in each of the [ ])

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.signature (Request Signature Verifier)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.models (UI component builders)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.rtm_v2 (RTM client)
  • /docs-src (Documents, have you run ./scripts/docs.sh?)
  • /docs-src-v2 (Documents, have you run ./scripts/docs-v2.sh?)
  • /tutorial (PythOnBoardingBot tutorial)
  • tests/integration_tests (Automated tests for this library)

Requirements (place an x in each [ ])

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh after making the changes.

@filmaj filmaj added enhancement M-T: A feature request for new functionality semver:patch web-client Version: 3x labels Feb 16, 2022
@filmaj filmaj added this to the 3.15.0 milestone Feb 16, 2022
@filmaj filmaj self-assigned this Feb 16, 2022
@codecov
Copy link

codecov bot commented Feb 16, 2022

Codecov Report

Merging #1176 (c572675) into main (4d3f67d) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1176      +/-   ##
==========================================
+ Coverage   86.63%   86.68%   +0.04%     
==========================================
  Files         110      110              
  Lines       10793    10829      +36     
==========================================
+ Hits         9351     9387      +36     
  Misses       1442     1442              
Impacted Files Coverage Δ
slack_sdk/web/async_client.py 85.14% <100.00%> (+0.18%) ⬆️
slack_sdk/web/client.py 86.53% <100.00%> (+0.16%) ⬆️
slack_sdk/web/legacy_client.py 86.24% <100.00%> (+0.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d3f67d...c572675. Read the comment docs.

Copy link
Member

@srajiang srajiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. You generated the changes to legacy_client by running the codegen scripts, yes?

I left one small comment. Ultimately I think it's up to the api docs to specify whether this is a required field when type='link', and the docs can be improved, so I am also fine with leaving as is.

slack_sdk/web/async_client.py Outdated Show resolved Hide resolved
@filmaj
Copy link
Contributor Author

filmaj commented Feb 16, 2022

You generated the changes to legacy_client by running the codegen scripts, yes?

Yes! I was mostly using previous "add some new API" pull requests to this repo as a template, and saw that they included changes to legacy and async clients, but when I went to edit those I saw the big comment at the top of the file telling me to generate the changes off of client.py 😄

type: str,
emoji: Optional[str] = None,
entity_id: Optional[str] = None,
link: Optional[str] = None, # include when type is 'link'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment will be removed when the codegen command is executed next time. Can you add this change to client.py and run either python setup.py codegen or ./scripts/run_validation.sh?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do! I am also working on an integration test (mostly so I can have some more hands-on experience with what this API does), so I will include this suggested change as well as the integration test in a moment, and ask for your review again 🙇

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filmaj Got it. Thanks!

Copy link
Member

@srajiang srajiang Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call out @seratch I had meant to leave this in the the client.py file! 🙇

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI when I moved the comment to client.py and re-ran python3 setup.py codegen, the comment only shows up in legacy_client.py and not async_client.py 🤔

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once integration_tests/web/test_bookmarks.py is improved, we can merge this PR and release a new version tomorrow!

@@ -0,0 +1,71 @@
import asyncio
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test code itself is great! but I have a few suggestions:

  • Let's remove unused imports
  • Let's run black code formatter

The following is an example that fixes all the above:

import logging
import os
import unittest

from integration_tests.env_variable_names import (
    SLACK_SDK_TEST_BOT_TOKEN,
    SLACK_SDK_TEST_WEB_TEST_CHANNEL_ID,
)
from slack_sdk.web import WebClient


class TestBookmarks(unittest.TestCase):
    """Runs integration tests with real Slack API testing the bookmarks.* APIs"""

    def setUp(self):
        if not hasattr(self, "logger"):
            self.logger = logging.getLogger(__name__)
            self.bot_token = os.environ[SLACK_SDK_TEST_BOT_TOKEN]
            self.sync_client: WebClient = WebClient(token=self.bot_token)
            self.channel_id = os.environ[SLACK_SDK_TEST_WEB_TEST_CHANNEL_ID]

    def tearDown(self):
        pass

    def test_adding_listing_editing_removing_bookmark(self):
        client = self.sync_client
        # create a new bookmark
        bookmark = client.bookmarks_add(
            channel_id=self.channel_id,
            title="slack!",
            type="link",
            link="https://slack.com",
        )
        self.assertIsNotNone(bookmark)
        bookmark_id = bookmark["bookmark"]["id"]
        # make sure we find the bookmark we just added
        all_bookmarks = client.bookmarks_list(channel_id=self.channel_id)
        self.assertIsNotNone(all_bookmarks)
        self.assertIsNotNone(
            next(
                (b for b in all_bookmarks["bookmarks"] if b["id"] == bookmark_id), None
            )
        )
        # edit the bookmark
        bookmark = client.bookmarks_edit(
            bookmark_id=bookmark_id,
            channel_id=self.channel_id,
            title="slack api!",
            type="link",
            link="https://api.slack.com",
        )
        self.assertIsNotNone(bookmark)
        # make sure we find the edited bookmark we just added
        all_bookmarks = client.bookmarks_list(channel_id=self.channel_id)
        self.assertIsNotNone(all_bookmarks)
        edited_bookmark = next(
            (b for b in all_bookmarks["bookmarks"] if b["id"] == bookmark_id), None
        )
        self.assertIsNotNone(edited_bookmark)
        self.assertEqual(edited_bookmark["title"], "slack api!")
        # remove the bookmark
        removed_bookmark = client.bookmarks_remove(
            bookmark_id=bookmark_id, channel_id=self.channel_id
        )
        self.assertIsNotNone(removed_bookmark)
        # make sure we cannot find the bookmark we just removed
        all_bookmarks = client.bookmarks_list(channel_id=self.channel_id)
        self.assertIsNotNone(all_bookmarks)
        self.assertIsNone(
            next((b for b in all_bookmarks if b["id"] == bookmark_id), None)
        )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting @seratch - I saw that some code formatters were run as part of the run_validation.sh script, so I assumed that was run against the test code as well. Looks like we run black against the tests/ directory but not against the integration_tests/ directory. Should we?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we run black against the tests/ directory but not against the integration_tests/ directory. Should we?

Good point. I think that enabling black for the directory too would be a nice improvement

@filmaj filmaj merged commit 8c7b9d2 into main Feb 17, 2022
@filmaj filmaj deleted the bookmark-apis branch February 17, 2022 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement M-T: A feature request for new functionality semver:patch Version: 3x web-client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants