1
+ import pytest
2
+ from unittest .mock import patch , MagicMock
3
+ from requests import HTTPError , Response
4
+ from dpytools .http_clients .base import BaseHttpClient
5
+ from dpytools .slack .slack import SlackNotifier
6
+
7
+ @patch .object (BaseHttpClient , 'post' )
8
+ def test_notify (mock_post ):
9
+ """
10
+ Test that the notify method sends a POST request
11
+ """
12
+ webhook_url = 'http://example.com'
13
+ mock_response = MagicMock (Response )
14
+ mock_response .status_code = 200
15
+ mock_post .return_value = mock_response
16
+
17
+ notifier = SlackNotifier (webhook_url )
18
+ notifier .notify ({'text' : 'Test message' })
19
+
20
+ mock_post .assert_called_once_with (webhook_url , json = {'text' : 'Test message' })
21
+
22
+ @patch .object (BaseHttpClient , 'post' )
23
+ def test_msg_str (mock_post ):
24
+ """
25
+ Test that the msg_str method sends a POST request with a string message
26
+ """
27
+ webhook_url = 'http://example.com'
28
+ mock_response = MagicMock (Response )
29
+ mock_response .status_code = 200
30
+ mock_post .return_value = mock_response
31
+
32
+ notifier = SlackNotifier (webhook_url )
33
+ notifier .msg_str ('Test message' )
34
+
35
+ mock_post .assert_called_once_with (webhook_url , json = {'text' : 'Test message' })
0 commit comments