|
| 1 | +import os |
| 2 | +import unittest |
| 3 | + |
| 4 | +from integration_tests.env_variable_names import \ |
| 5 | + SLACK_SDK_TEST_BOT_TOKEN, \ |
| 6 | + SLACK_SDK_TEST_WEB_TEST_CHANNEL_ID |
| 7 | +from integration_tests.helpers import async_test |
| 8 | +from slack import WebClient |
| 9 | + |
| 10 | + |
| 11 | +class TestWebClient(unittest.TestCase): |
| 12 | + """Runs integration tests with real Slack API |
| 13 | +
|
| 14 | + https://github.com/slackapi/python-slackclient/issues/728 |
| 15 | + """ |
| 16 | + |
| 17 | + def setUp(self): |
| 18 | + if not hasattr(self, "logger"): |
| 19 | + self.bot_token = os.environ[SLACK_SDK_TEST_BOT_TOKEN] |
| 20 | + self.channel_ids = ",".join([os.environ[SLACK_SDK_TEST_WEB_TEST_CHANNEL_ID]]) |
| 21 | + |
| 22 | + def tearDown(self): |
| 23 | + pass |
| 24 | + |
| 25 | + def test_bytes_for_file_param(self): |
| 26 | + client: WebClient = WebClient(token=self.bot_token, run_async=False) |
| 27 | + bytes = bytearray("This is a test", "utf-8") |
| 28 | + upload = client.files_upload(file=bytes, filename="test.txt", channels=self.channel_ids) |
| 29 | + self.assertIsNotNone(upload) |
| 30 | + deletion = client.files_delete(file=upload["file"]["id"]) |
| 31 | + self.assertIsNotNone(deletion) |
| 32 | + |
| 33 | + @async_test |
| 34 | + async def test_bytes_for_file_param_async(self): |
| 35 | + client: WebClient = WebClient(token=self.bot_token, run_async=True) |
| 36 | + bytes = bytearray("This is a test", "utf-8") |
| 37 | + upload = await client.files_upload(file=bytes, filename="test.txt", channels=self.channel_ids) |
| 38 | + self.assertIsNotNone(upload) |
| 39 | + deletion = await client.files_delete(file=upload["file"]["id"]) |
| 40 | + self.assertIsNotNone(deletion) |
0 commit comments