Skip to content

Commit 8c7b9d2

Browse files
Filip Majfilmaj
authored andcommitted
Add comment for when link parameter for bookmarks.add API is required vs. optional. Add integration tests for bookmarks API.
1 parent b07e49f commit 8c7b9d2

3 files changed

Lines changed: 75 additions & 2 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import logging
2+
import os
3+
import unittest
4+
5+
from integration_tests.env_variable_names import (
6+
SLACK_SDK_TEST_BOT_TOKEN,
7+
SLACK_SDK_TEST_WEB_TEST_CHANNEL_ID,
8+
)
9+
from slack_sdk.web import WebClient
10+
from slack_sdk.web.async_client import AsyncWebClient
11+
12+
13+
class TestBookmarks(unittest.TestCase):
14+
"""Runs integration tests with real Slack API testing the bookmarks.* APIs"""
15+
16+
def setUp(self):
17+
if not hasattr(self, "logger"):
18+
self.logger = logging.getLogger(__name__)
19+
self.bot_token = os.environ[SLACK_SDK_TEST_BOT_TOKEN]
20+
self.async_client: AsyncWebClient = AsyncWebClient(token=self.bot_token)
21+
self.sync_client: WebClient = WebClient(token=self.bot_token)
22+
self.channel_id = os.environ[SLACK_SDK_TEST_WEB_TEST_CHANNEL_ID]
23+
24+
def tearDown(self):
25+
pass
26+
27+
def test_adding_listing_editing_removing_bookmark(self):
28+
client = self.sync_client
29+
# create a new bookmark
30+
bookmark = client.bookmarks_add(
31+
channel_id=self.channel_id,
32+
title="slack!",
33+
type="link",
34+
link="https://slack.com",
35+
)
36+
self.assertIsNotNone(bookmark)
37+
bookmark_id = bookmark["bookmark"]["id"]
38+
# make sure we find the bookmark we just added
39+
all_bookmarks = client.bookmarks_list(channel_id=self.channel_id)
40+
self.assertIsNotNone(all_bookmarks)
41+
self.assertIsNotNone(
42+
next(
43+
(b for b in all_bookmarks["bookmarks"] if b["id"] == bookmark_id), None
44+
)
45+
)
46+
# edit the bookmark
47+
bookmark = client.bookmarks_edit(
48+
bookmark_id=bookmark_id,
49+
channel_id=self.channel_id,
50+
title="slack api!",
51+
type="link",
52+
link="https://api.slack.com",
53+
)
54+
self.assertIsNotNone(bookmark)
55+
# make sure we find the edited bookmark we just added
56+
all_bookmarks = client.bookmarks_list(channel_id=self.channel_id)
57+
self.assertIsNotNone(all_bookmarks)
58+
edited_bookmark = next(
59+
(b for b in all_bookmarks["bookmarks"] if b["id"] == bookmark_id), None
60+
)
61+
self.assertIsNotNone(edited_bookmark)
62+
self.assertEqual(edited_bookmark["title"], "slack api!")
63+
# remove the bookmark
64+
removed_bookmark = client.bookmarks_remove(
65+
bookmark_id=bookmark_id, channel_id=self.channel_id
66+
)
67+
self.assertIsNotNone(removed_bookmark)
68+
# make sure we cannot find the bookmark we just removed
69+
all_bookmarks = client.bookmarks_list(channel_id=self.channel_id)
70+
self.assertIsNotNone(all_bookmarks)
71+
self.assertIsNone(
72+
next((b for b in all_bookmarks if b["id"] == bookmark_id), None)
73+
)

slack_sdk/web/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,7 @@ def bookmarks_add(
15601560
type: str,
15611561
emoji: Optional[str] = None,
15621562
entity_id: Optional[str] = None,
1563-
link: Optional[str] = None,
1563+
link: Optional[str] = None, # include when type is 'link'
15641564
parent_id: Optional[str] = None,
15651565
**kwargs,
15661566
) -> SlackResponse:

slack_sdk/web/legacy_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ def bookmarks_add(
15711571
type: str,
15721572
emoji: Optional[str] = None,
15731573
entity_id: Optional[str] = None,
1574-
link: Optional[str] = None,
1574+
link: Optional[str] = None, # include when type is 'link'
15751575
parent_id: Optional[str] = None,
15761576
**kwargs,
15771577
) -> Union[Future, SlackResponse]:

0 commit comments

Comments
 (0)