Skip to content

Commit d410e8d

Browse files
committed
Remove async class
1 parent 4d5d95b commit d410e8d

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

integration_tests/webhook/test_async_webhook.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from tests.helpers import async_test
23
import unittest
34
import time
45

@@ -15,8 +16,9 @@
1516
from slack_sdk.models.blocks.basic_components import MarkdownTextObject, PlainTextObject
1617

1718

18-
class TestAsyncWebhook(unittest.IsolatedAsyncioTestCase):
19-
async def asyncSetUp(self):
19+
class TestAsyncWebhook(unittest.TestCase):
20+
@async_test
21+
async def setUp(self):
2022
if not hasattr(self, "channel_id"):
2123
token = os.environ[SLACK_SDK_TEST_BOT_TOKEN]
2224
channel_name = os.environ[
@@ -35,6 +37,7 @@ async def asyncSetUp(self):
3537
def tearDown(self):
3638
pass
3739

40+
@async_test
3841
async def test_webhook(self):
3942
url = os.environ[SLACK_SDK_TEST_INCOMING_WEBHOOK_URL]
4043
webhook = AsyncWebhookClient(url)
@@ -49,6 +52,7 @@ async def test_webhook(self):
4952
actual_text = history["messages"][0]["text"]
5053
self.assertEqual("Hello!", actual_text)
5154

55+
@async_test
5256
async def test_with_unfurls_off(self):
5357
url = os.environ[SLACK_SDK_TEST_INCOMING_WEBHOOK_URL]
5458
token = os.environ[SLACK_SDK_TEST_BOT_TOKEN]
@@ -68,6 +72,7 @@ async def test_with_unfurls_off(self):
6872
self.assertIsNotNone(history)
6973
self.assertTrue("attachments" not in history["messages"][0])
7074

75+
@async_test
7176
async def test_with_unfurls_on(self):
7277
# Slack API rate limits unfurls of unique links so test will
7378
# fail when repeated. For testing, either use a different URL
@@ -90,6 +95,7 @@ async def test_with_unfurls_on(self):
9095
self.assertIsNotNone(history)
9196
self.assertTrue("attachments" in history["messages"][0])
9297

98+
@async_test
9399
async def test_with_blocks(self):
94100
url = os.environ[SLACK_SDK_TEST_INCOMING_WEBHOOK_URL]
95101
webhook = AsyncWebhookClient(url)
@@ -130,6 +136,7 @@ async def test_with_blocks(self):
130136
self.assertEqual(200, response.status_code)
131137
self.assertEqual("ok", response.body)
132138

139+
@async_test
133140
async def test_with_blocks_dict(self):
134141
url = os.environ[SLACK_SDK_TEST_INCOMING_WEBHOOK_URL]
135142
webhook = AsyncWebhookClient(url)
@@ -198,6 +205,7 @@ async def test_with_blocks_dict(self):
198205
self.assertEqual(200, response.status_code)
199206
self.assertEqual("ok", response.body)
200207

208+
@async_test
201209
async def test_with_attachments(self):
202210
url = os.environ[SLACK_SDK_TEST_INCOMING_WEBHOOK_URL]
203211
webhook = AsyncWebhookClient(url)
@@ -231,6 +239,7 @@ async def test_with_attachments(self):
231239
self.assertEqual(200, response.status_code)
232240
self.assertEqual("ok", response.body)
233241

242+
@async_test
234243
async def test_with_attachments_dict(self):
235244
url = os.environ[SLACK_SDK_TEST_INCOMING_WEBHOOK_URL]
236245
webhook = AsyncWebhookClient(url)

tests/webhook/test_async_webhook.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from tests.helpers import async_test
12
import unittest
23

34
from slack.web.classes.attachments import Attachment, AttachmentField
@@ -9,13 +10,14 @@
910
)
1011

1112

12-
class TestAsyncWebhook(unittest.IsolatedAsyncioTestCase):
13+
class TestAsyncWebhook(unittest.TestCase):
1314
def setUp(self):
1415
setup_mock_web_api_server(self)
1516

1617
def tearDown(self):
1718
cleanup_mock_web_api_server(self)
1819

20+
@async_test
1921
async def test_send(self):
2022
client = AsyncWebhookClient("http://localhost:8888")
2123

@@ -26,6 +28,7 @@ async def test_send(self):
2628
resp = await client.send(text="hello!", response_type="in_channel")
2729
self.assertEqual("ok", resp.body)
2830

31+
@async_test
2932
async def test_send_with_url_unfurl_opts_issue_1045(self):
3033
client = AsyncWebhookClient("http://localhost:8888")
3134
resp: WebhookResponse = await client.send(
@@ -36,6 +39,7 @@ async def test_send_with_url_unfurl_opts_issue_1045(self):
3639
self.assertEqual(200, resp.status_code)
3740
self.assertEqual("ok", resp.body)
3841

42+
@async_test
3943
async def test_send_blocks(self):
4044
client = AsyncWebhookClient("http://localhost:8888")
4145

@@ -87,6 +91,7 @@ async def test_send_blocks(self):
8791
)
8892
self.assertEqual("ok", resp.body)
8993

94+
@async_test
9095
async def test_send_attachments(self):
9196
client = AsyncWebhookClient("http://localhost:8888")
9297

@@ -156,24 +161,28 @@ async def test_send_attachments(self):
156161
)
157162
self.assertEqual("ok", resp.body)
158163

164+
@async_test
159165
async def test_send_dict(self):
160166
client = AsyncWebhookClient("http://localhost:8888")
161167
resp: WebhookResponse = await client.send_dict({"text": "hello!"})
162168
self.assertEqual(200, resp.status_code)
163169
self.assertEqual("ok", resp.body)
164170

171+
@async_test
165172
async def test_timeout_issue_712(self):
166173
client = AsyncWebhookClient(url="http://localhost:8888/timeout", timeout=1)
167174
with self.assertRaises(Exception):
168175
await client.send_dict({"text": "hello!"})
169176

177+
@async_test
170178
async def test_proxy_issue_714(self):
171179
client = AsyncWebhookClient(
172180
url="http://localhost:8888", proxy="http://invalid-host:9999"
173181
)
174182
with self.assertRaises(Exception):
175183
await client.send_dict({"text": "hello!"})
176184

185+
@async_test
177186
async def test_user_agent_customization_issue_769(self):
178187
client = AsyncWebhookClient(
179188
url="http://localhost:8888/user-agent-this_is-test",

0 commit comments

Comments
 (0)