|
| 1 | +import unittest |
| 2 | + |
| 3 | +from slack_sdk.web.async_client import AsyncWebClient |
| 4 | +from tests.slack_sdk_async.helpers import async_test |
| 5 | +from tests.slack_sdk.web.mock_web_api_handler import MockHandler |
| 6 | +from tests.mock_web_api_server import ( |
| 7 | + setup_mock_web_api_server_async, |
| 8 | + cleanup_mock_web_api_server_async, |
| 9 | + assert_received_request_count_async, |
| 10 | +) |
| 11 | + |
| 12 | + |
| 13 | +class TestAsyncWebClientUrlFormat(unittest.TestCase): |
| 14 | + def setUp(self): |
| 15 | + setup_mock_web_api_server_async(self, MockHandler) |
| 16 | + self.client = AsyncWebClient(token="xoxb-api_test", base_url="http://localhost:8888") |
| 17 | + self.client_base_url_slash = AsyncWebClient(token="xoxb-api_test", base_url="http://localhost:8888/") |
| 18 | + |
| 19 | + def tearDown(self): |
| 20 | + cleanup_mock_web_api_server_async(self) |
| 21 | + |
| 22 | + @async_test |
| 23 | + async def test_base_url_without_slash_api_method_without_slash(self): |
| 24 | + await self.client.api_call("chat.postMessage") |
| 25 | + await assert_received_request_count_async(self, "/chat.postMessage", 1) |
| 26 | + |
| 27 | + @async_test |
| 28 | + async def test_base_url_without_slash_api_method_with_slash(self): |
| 29 | + await self.client.api_call("/chat.postMessage") |
| 30 | + await assert_received_request_count_async(self, "/chat.postMessage", 1) |
| 31 | + |
| 32 | + @async_test |
| 33 | + async def test_base_url_with_slash_api_method_without_slash(self): |
| 34 | + await self.client_base_url_slash.api_call("chat.postMessage") |
| 35 | + await assert_received_request_count_async(self, "/chat.postMessage", 1) |
| 36 | + |
| 37 | + @async_test |
| 38 | + async def test_base_url_with_slash_api_method_with_slash(self): |
| 39 | + await self.client_base_url_slash.api_call("/chat.postMessage") |
| 40 | + await assert_received_request_count_async(self, "/chat.postMessage", 1) |
| 41 | + |
| 42 | + @async_test |
| 43 | + async def test_base_url_without_slash_api_method_with_slash_and_trailing_slash(self): |
| 44 | + await self.client.api_call("/chat.postMessage/") |
| 45 | + await assert_received_request_count_async(self, "/chat.postMessage/", 1) |
0 commit comments