-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #730 from seratch/issue-728-file-upload-bytes
Fix #728 by adding bytearray support in files_upload (sync mode)
- Loading branch information
Showing
2 changed files
with
42 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,40 @@ | ||
import os | ||
import unittest | ||
|
||
from integration_tests.env_variable_names import \ | ||
SLACK_SDK_TEST_BOT_TOKEN, \ | ||
SLACK_SDK_TEST_WEB_TEST_CHANNEL_ID | ||
from integration_tests.helpers import async_test | ||
from slack import WebClient | ||
|
||
|
||
class TestWebClient(unittest.TestCase): | ||
"""Runs integration tests with real Slack API | ||
https://github.com/slackapi/python-slackclient/issues/728 | ||
""" | ||
|
||
def setUp(self): | ||
if not hasattr(self, "logger"): | ||
self.bot_token = os.environ[SLACK_SDK_TEST_BOT_TOKEN] | ||
self.channel_ids = ",".join([os.environ[SLACK_SDK_TEST_WEB_TEST_CHANNEL_ID]]) | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_bytes_for_file_param(self): | ||
client: WebClient = WebClient(token=self.bot_token, run_async=False) | ||
bytes = bytearray("This is a test", "utf-8") | ||
upload = client.files_upload(file=bytes, filename="test.txt", channels=self.channel_ids) | ||
self.assertIsNotNone(upload) | ||
deletion = client.files_delete(file=upload["file"]["id"]) | ||
self.assertIsNotNone(deletion) | ||
|
||
@async_test | ||
async def test_bytes_for_file_param_async(self): | ||
client: WebClient = WebClient(token=self.bot_token, run_async=True) | ||
bytes = bytearray("This is a test", "utf-8") | ||
upload = await client.files_upload(file=bytes, filename="test.txt", channels=self.channel_ids) | ||
self.assertIsNotNone(upload) | ||
deletion = await client.files_delete(file=upload["file"]["id"]) | ||
self.assertIsNotNone(deletion) |
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