|
2 | 2 | import socket |
3 | 3 | import unittest |
4 | 4 | import time |
| 5 | +from unittest.mock import patch |
5 | 6 |
|
6 | 7 | import slack_sdk.errors as err |
7 | 8 | from slack_sdk import WebClient |
@@ -246,3 +247,17 @@ def test_base_url_appends_trailing_slash_issue_15141(self): |
246 | 247 | def test_base_url_preserves_trailing_slash_issue_15141(self): |
247 | 248 | client = WebClient(base_url="http://localhost:8888/") |
248 | 249 | self.assertEqual(client.base_url, "http://localhost:8888/") |
| 250 | + |
| 251 | + def test_bodyless_requests_send_form_urlencoded_content_type(self): |
| 252 | + response = {"status": 200, "headers": {}, "body": '{"ok": true}'} |
| 253 | + with patch.object(self.client, "_perform_urllib_http_request", return_value=response) as transport: |
| 254 | + self.client.api_test() |
| 255 | + headers = transport.call_args[1]["args"]["headers"] |
| 256 | + self.assertEqual("application/x-www-form-urlencoded", headers["Content-Type"]) |
| 257 | + |
| 258 | + def test_json_requests_send_json_content_type(self): |
| 259 | + response = {"status": 200, "headers": {}, "body": '{"ok": true}'} |
| 260 | + with patch.object(self.client, "_perform_urllib_http_request", return_value=response) as transport: |
| 261 | + self.client.api_call("chat.postMessage", json={"channel": "C111", "text": "hi"}) |
| 262 | + headers = transport.call_args[1]["args"]["headers"] |
| 263 | + self.assertEqual("application/json;charset=utf-8", headers["Content-Type"]) |
0 commit comments