|
| 1 | +import unittest |
| 2 | + |
| 3 | +import slack.errors as err |
| 4 | +from slack import WebClient |
| 5 | +from tests.helpers import async_test |
| 6 | +from tests.web.mock_web_api_server import ( |
| 7 | + setup_mock_web_api_server, |
| 8 | + cleanup_mock_web_api_server, |
| 9 | +) |
| 10 | + |
| 11 | + |
| 12 | +class TestWebClient_Issue_829(unittest.TestCase): |
| 13 | + def setUp(self): |
| 14 | + setup_mock_web_api_server(self) |
| 15 | + self.client = WebClient(token="xoxp-1234", base_url="http://localhost:8888", ) |
| 16 | + self.async_client = WebClient( |
| 17 | + token="xoxp-1234", run_async=True, base_url="http://localhost:8888", |
| 18 | + ) |
| 19 | + |
| 20 | + def tearDown(self): |
| 21 | + cleanup_mock_web_api_server(self) |
| 22 | + |
| 23 | + def test_html_response_body_issue_829(self): |
| 24 | + client = WebClient(base_url="http://localhost:8888") |
| 25 | + try: |
| 26 | + client.users_list(token="xoxb-error_html_response") |
| 27 | + self.fail("SlackApiError expected here") |
| 28 | + except err.SlackApiError as e: |
| 29 | + self.assertTrue( |
| 30 | + str(e).startswith("Failed to parse the response body: Expecting value: "), |
| 31 | + e, |
| 32 | + ) |
| 33 | + |
| 34 | + @async_test |
| 35 | + async def test_html_response_body_issue_829_async(self): |
| 36 | + client = WebClient(base_url="http://localhost:8888", run_async=True) |
| 37 | + try: |
| 38 | + await client.users_list(token="xoxb-error_html_response") |
| 39 | + self.fail("SlackApiError expected here") |
| 40 | + except err.SlackApiError as e: |
| 41 | + self.assertEqual( |
| 42 | + "The request to the Slack API failed.\n" |
| 43 | + "The server responded with: {}", |
| 44 | + str(e) |
| 45 | + ) |
0 commit comments