Skip to content

Commit 5464f89

Browse files
tests: ensure consistent behavior around url format (#1600)
* tests: add tests that aim to ensure consistent behavior around url formats * Fix naming * make the tests work * Clean up imports * Improve based on rebase * Clean up PR * clean up PR
1 parent 860bf9b commit 5464f89

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from unittest import TestCase
2+
3+
from slack_sdk.web.legacy_client import LegacyWebClient
4+
from tests.slack_sdk.web.mock_web_api_handler import MockHandler
5+
from tests.mock_web_api_server import setup_mock_web_api_server, cleanup_mock_web_api_server, assert_received_request_count
6+
7+
8+
class TestLegacyWebClientUrlFormat(TestCase):
9+
def setUp(self):
10+
setup_mock_web_api_server(self, MockHandler)
11+
self.client = LegacyWebClient(token="xoxb-api_test", base_url="http://localhost:8888")
12+
self.client_base_url_slash = LegacyWebClient(token="xoxb-api_test", base_url="http://localhost:8888/")
13+
14+
def tearDown(self):
15+
cleanup_mock_web_api_server(self)
16+
17+
def test_base_url_without_slash_api_method_without_slash(self):
18+
self.client.api_call("chat.postMessage")
19+
assert_received_request_count(self, "/chat.postMessage", 1)
20+
21+
def test_base_url_without_slash_api_method_with_slash(self):
22+
self.client.api_call("/chat.postMessage")
23+
assert_received_request_count(self, "/chat.postMessage", 1)
24+
25+
def test_base_url_with_slash_api_method_without_slash(self):
26+
self.client_base_url_slash.api_call("chat.postMessage")
27+
assert_received_request_count(self, "/chat.postMessage", 1)
28+
29+
def test_base_url_with_slash_api_method_with_slash(self):
30+
self.client_base_url_slash.api_call("/chat.postMessage")
31+
assert_received_request_count(self, "/chat.postMessage", 1)
32+
33+
def test_base_url_without_slash_api_method_with_slash_and_trailing_slash(self):
34+
self.client.api_call("/chat.postMessage/")
35+
assert_received_request_count(self, "/chat.postMessage/", 1)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from unittest import TestCase
2+
3+
from slack_sdk.web import WebClient
4+
from tests.slack_sdk.web.mock_web_api_handler import MockHandler
5+
from tests.mock_web_api_server import setup_mock_web_api_server, cleanup_mock_web_api_server, assert_received_request_count
6+
7+
8+
class TestWebClientUrlFormat(TestCase):
9+
def setUp(self):
10+
setup_mock_web_api_server(self, MockHandler)
11+
self.client = WebClient(token="xoxb-api_test", base_url="http://localhost:8888")
12+
self.client_base_url_slash = WebClient(token="xoxb-api_test", base_url="http://localhost:8888/")
13+
14+
def tearDown(self):
15+
cleanup_mock_web_api_server(self)
16+
17+
def test_base_url_without_slash_api_method_without_slash(self):
18+
self.client.api_call("chat.postMessage")
19+
assert_received_request_count(self, "/chat.postMessage", 1)
20+
21+
def test_base_url_without_slash_api_method_with_slash(self):
22+
self.client.api_call("/chat.postMessage")
23+
assert_received_request_count(self, "/chat.postMessage", 1)
24+
25+
def test_base_url_with_slash_api_method_without_slash(self):
26+
self.client_base_url_slash.api_call("chat.postMessage")
27+
assert_received_request_count(self, "/chat.postMessage", 1)
28+
29+
def test_base_url_with_slash_api_method_with_slash(self):
30+
self.client_base_url_slash.api_call("/chat.postMessage")
31+
assert_received_request_count(self, "/chat.postMessage", 1)
32+
33+
def test_base_url_without_slash_api_method_with_slash_and_trailing_slash(self):
34+
self.client.api_call("/chat.postMessage/")
35+
assert_received_request_count(self, "/chat.postMessage/", 1)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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

Comments
 (0)