def __call__( self, text: Union[str, dict] = "", blocks: Optional[List[Union[dict, Block]]] = None, attachments: Optional[List[Union[dict, Attachment]]] = None, response_type: Optional[str] = None, replace_original: Optional[bool] = None, delete_original: Optional[bool] = None, ) -> WebhookResponse: if self.response_url is not None: client = WebhookClient(self.response_url) text_or_whole_response: Union[str, dict] = text if isinstance(text_or_whole_response, str): text = text_or_whole_response message = _build_message( text=text, blocks=blocks, attachments=attachments, response_type=response_type, replace_original=replace_original, delete_original=delete_original, ) return client.send_dict(message) elif isinstance(text_or_whole_response, dict): message = _build_message(**text_or_whole_response) return client.send_dict(message) else: raise ValueError( f"The arg is unexpected type ({type(text_or_whole_response)})" ) else: raise ValueError( "respond is unsupported here as there is no response_url")
def test_user_agent_customization_issue_769(self): client = WebhookClient( url="http://localhost:8888/user-agent-this_is-test", user_agent_prefix="this_is", user_agent_suffix="test", ) resp = client.send_dict({"text": "hi!"}) self.assertEqual(resp.body, "ok")
def test_if_it_uses_custom_logger_issue_921(self): logger = CustomLogger("test-logger") client = WebhookClient(url="http://localhost:8888", logger=logger) client.send_dict({"text": "hi!"}) self.assertTrue(logger.called)
def test_proxy_issue_714(self): client = WebhookClient(url="http://localhost:8888", proxy="http://invalid-host:9999") with self.assertRaises(urllib.error.URLError): client.send_dict({"text": "hello!"})
def test_error_response(self): client = WebhookClient(url="http://localhost:8888/error") resp: WebhookResponse = client.send_dict({"text": "hello!"}) self.assertEqual(500, resp.status_code) self.assertTrue(resp.body.startswith("<!DOCTYPE html>"))
def test_timeout_issue_712(self): client = WebhookClient(url="http://localhost:8888/timeout", timeout=1) with self.assertRaises(socket.timeout): client.send_dict({"text": "hello!"})
def test_send_dict(self): client = WebhookClient("http://localhost:8888") resp: WebhookResponse = client.send_dict({"text": "hello!"}) self.assertEqual(200, resp.status_code) self.assertEqual("ok", resp.body)