Skip to content

Commit ced7e01

Browse files
committed
testing _get_url
1 parent 42681fa commit ced7e01

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

slack_sdk/web/internal_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _get_url(base_url: str, api_method: str) -> str:
6868
e.g. 'https://slack.com/api/chat.postMessage'
6969
"""
7070
if base_url.endswith("/") and api_method.startswith("/"):
71-
base_url.rstrip("/")
71+
api_method = api_method.lstrip("/")
7272
return urljoin(base_url, api_method)
7373

7474

tests/slack_sdk/web/test_internal_utils.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
_parse_web_class_objects,
1313
_to_v2_file_upload_item,
1414
_next_cursor_is_present,
15+
_get_url,
1516
)
1617

1718

@@ -108,3 +109,36 @@ def test_next_cursor_is_present(self):
108109
assert _next_cursor_is_present({"response_metadata": {"next_cursor": ""}}) is False
109110
assert _next_cursor_is_present({"response_metadata": {"next_cursor": None}}) is False
110111
assert _next_cursor_is_present({"something_else": {"next_cursor": "next-page"}}) is False
112+
113+
def test_get_url_prevent_double_slash(self):
114+
# Test case: Prevent double slash when both base_url and api_method include slashes
115+
api_url = _get_url("https://slack.com/api/", "/chat.postMessage")
116+
self.assertEqual(
117+
api_url,
118+
"https://slack.com/api/chat.postMessage",
119+
"Should correctly handle and remove double slashes between base_url and api_method",
120+
)
121+
122+
# Test case: Handle base_url without trailing slash
123+
api_url = _get_url("https://slack.com/api", "chat.postMessage")
124+
self.assertEqual(
125+
api_url,
126+
"https://slack.com/chat.postMessage",
127+
"Should correctly handle base_url without a trailing slash",
128+
)
129+
130+
# Test case: Handle api_method without leading slash
131+
api_url = _get_url("https://slack.com/api/", "chat.postMessage")
132+
self.assertEqual(
133+
api_url,
134+
"https://slack.com/api/chat.postMessage",
135+
"Should correctly handle api_method without a leading slash",
136+
)
137+
138+
# Test case: Both inputs are clean
139+
api_url = _get_url("https://slack.com/api", "/chat.postMessage")
140+
self.assertEqual(
141+
api_url,
142+
"https://slack.com/chat.postMessage",
143+
"Should correctly combine base_url and api_method with clean inputs",
144+
)

0 commit comments

Comments
 (0)