-
Notifications
You must be signed in to change notification settings - Fork 835
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
860bf9b
commit 5464f89
Showing
3 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |