diff --git a/tests/slack_sdk/web/test_legacy_web_client_url_format.py b/tests/slack_sdk/web/test_legacy_web_client_url_format.py new file mode 100644 index 00000000..0ba2f5ae --- /dev/null +++ b/tests/slack_sdk/web/test_legacy_web_client_url_format.py @@ -0,0 +1,35 @@ +from unittest import TestCase + +from slack_sdk.web.legacy_client import LegacyWebClient +from tests.slack_sdk.web.mock_web_api_handler import MockHandler +from tests.mock_web_api_server import setup_mock_web_api_server, cleanup_mock_web_api_server, assert_received_request_count + + +class TestLegacyWebClientUrlFormat(TestCase): + def setUp(self): + setup_mock_web_api_server(self, MockHandler) + self.client = LegacyWebClient(token="xoxb-api_test", base_url="http://localhost:8888") + self.client_base_url_slash = LegacyWebClient(token="xoxb-api_test", base_url="http://localhost:8888/") + + def tearDown(self): + cleanup_mock_web_api_server(self) + + def test_base_url_without_slash_api_method_without_slash(self): + self.client.api_call("chat.postMessage") + assert_received_request_count(self, "/chat.postMessage", 1) + + def test_base_url_without_slash_api_method_with_slash(self): + self.client.api_call("/chat.postMessage") + assert_received_request_count(self, "/chat.postMessage", 1) + + def test_base_url_with_slash_api_method_without_slash(self): + self.client_base_url_slash.api_call("chat.postMessage") + assert_received_request_count(self, "/chat.postMessage", 1) + + def test_base_url_with_slash_api_method_with_slash(self): + self.client_base_url_slash.api_call("/chat.postMessage") + assert_received_request_count(self, "/chat.postMessage", 1) + + def test_base_url_without_slash_api_method_with_slash_and_trailing_slash(self): + self.client.api_call("/chat.postMessage/") + assert_received_request_count(self, "/chat.postMessage/", 1) diff --git a/tests/slack_sdk/web/test_web_client_url_format.py b/tests/slack_sdk/web/test_web_client_url_format.py new file mode 100644 index 00000000..9ef4f932 --- /dev/null +++ b/tests/slack_sdk/web/test_web_client_url_format.py @@ -0,0 +1,35 @@ +from unittest import TestCase + +from slack_sdk.web import WebClient +from tests.slack_sdk.web.mock_web_api_handler import MockHandler +from tests.mock_web_api_server import setup_mock_web_api_server, cleanup_mock_web_api_server, assert_received_request_count + + +class TestWebClientUrlFormat(TestCase): + def setUp(self): + setup_mock_web_api_server(self, MockHandler) + self.client = WebClient(token="xoxb-api_test", base_url="http://localhost:8888") + self.client_base_url_slash = WebClient(token="xoxb-api_test", base_url="http://localhost:8888/") + + def tearDown(self): + cleanup_mock_web_api_server(self) + + def test_base_url_without_slash_api_method_without_slash(self): + self.client.api_call("chat.postMessage") + assert_received_request_count(self, "/chat.postMessage", 1) + + def test_base_url_without_slash_api_method_with_slash(self): + self.client.api_call("/chat.postMessage") + assert_received_request_count(self, "/chat.postMessage", 1) + + def test_base_url_with_slash_api_method_without_slash(self): + self.client_base_url_slash.api_call("chat.postMessage") + assert_received_request_count(self, "/chat.postMessage", 1) + + def test_base_url_with_slash_api_method_with_slash(self): + self.client_base_url_slash.api_call("/chat.postMessage") + assert_received_request_count(self, "/chat.postMessage", 1) + + def test_base_url_without_slash_api_method_with_slash_and_trailing_slash(self): + self.client.api_call("/chat.postMessage/") + assert_received_request_count(self, "/chat.postMessage/", 1) diff --git a/tests/slack_sdk_async/web/test_web_client_url_format.py b/tests/slack_sdk_async/web/test_web_client_url_format.py new file mode 100644 index 00000000..3f25dac0 --- /dev/null +++ b/tests/slack_sdk_async/web/test_web_client_url_format.py @@ -0,0 +1,45 @@ +import unittest + +from slack_sdk.web.async_client import AsyncWebClient +from tests.slack_sdk_async.helpers import async_test +from tests.slack_sdk.web.mock_web_api_handler import MockHandler +from tests.mock_web_api_server import ( + setup_mock_web_api_server_async, + cleanup_mock_web_api_server_async, + assert_received_request_count_async, +) + + +class TestAsyncWebClientUrlFormat(unittest.TestCase): + def setUp(self): + setup_mock_web_api_server_async(self, MockHandler) + self.client = AsyncWebClient(token="xoxb-api_test", base_url="http://localhost:8888") + self.client_base_url_slash = AsyncWebClient(token="xoxb-api_test", base_url="http://localhost:8888/") + + def tearDown(self): + cleanup_mock_web_api_server_async(self) + + @async_test + async def test_base_url_without_slash_api_method_without_slash(self): + await self.client.api_call("chat.postMessage") + await assert_received_request_count_async(self, "/chat.postMessage", 1) + + @async_test + async def test_base_url_without_slash_api_method_with_slash(self): + await self.client.api_call("/chat.postMessage") + await assert_received_request_count_async(self, "/chat.postMessage", 1) + + @async_test + async def test_base_url_with_slash_api_method_without_slash(self): + await self.client_base_url_slash.api_call("chat.postMessage") + await assert_received_request_count_async(self, "/chat.postMessage", 1) + + @async_test + async def test_base_url_with_slash_api_method_with_slash(self): + await self.client_base_url_slash.api_call("/chat.postMessage") + await assert_received_request_count_async(self, "/chat.postMessage", 1) + + @async_test + async def test_base_url_without_slash_api_method_with_slash_and_trailing_slash(self): + await self.client.api_call("/chat.postMessage/") + await assert_received_request_count_async(self, "/chat.postMessage/", 1)