Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: ensure consistent behavior around url format #1600

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions tests/slack_sdk/web/test_legacy_web_client_url_format.py
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)
35 changes: 35 additions & 0 deletions tests/slack_sdk/web/test_web_client_url_format.py
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)
45 changes: 45 additions & 0 deletions tests/slack_sdk_async/web/test_web_client_url_format.py
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)
Loading