55
66from dingtalkchatbot .chatbot import DingtalkChatbot , is_not_null_and_blank_str , ActionCard , FeedLink , CardItem
77
8- __author__ = 'Devin -- http://zhangchuzhao.site'
9-
8+ __author__ = 'Devin - https://zhuifengshen.github.io'
109
1110class TestDingtalkChatbot (unittest .TestCase ):
1211 """DingtalkChatbot 测试用例"""
1312
1413 @classmethod
1514 def setUpClass (cls ):
15+ # 1.无加签
1616 cls .webhook = 'https://oapi.dingtalk.com/robot/send?access_token=77eb420ff2761ad516d974e1428c3e198b84faabc9c9ef8e86b2c71ac60bd0ea'
1717 cls .xiaoding = DingtalkChatbot (cls .webhook )
18+ # 2.有加签
19+ #cls.webhook = 'https://oapi.dingtalk.com/robot/send?access_token=fab4f070e0214d2e3f7429acd18bc38848cc7043f9191ed1f96fa090ab25b943'
20+ #cls.xiaoding = DingtalkChatbot(cls.webhook, secret='SEC225443235b43d49959eaca83b15b5b93ec747d662ad347a2b3483a7e67d8b96b')
21+
1822
1923 def test_is_not_null_and_blank_str (self ):
2024 """测试字符串不为空函数"""
@@ -31,12 +35,12 @@ def test_send_text(self):
3135
3236 def test_send_image (self ):
3337 """测试发送表情图片消息函数"""
34- result = self .xiaoding .send_image (pic_url = 'http://uc-test-manage-00.umlife.net/jenkins/pic/flake8.png ' )
38+ result = self .xiaoding .send_image (pic_url = 'http://www.sinaimg.cn/dy/slidenews/5_img/2013_28/453_28488_469248.jpg ' )
3539 self .assertEqual (result ['errcode' ], 0 )
3640
3741 def test_send_link (self ):
3842 """测试发送链接消息函数"""
39- result = self .xiaoding .send_link (title = '万万没想到,某小璐竟然...' , text = '故事是这样子的...' , message_url = 'http ://www.kwongwah .com.my/?p=454748 ' , pic_url = 'https ://pbs.twimg.com/media/CEwj7EDWgAE5eIF.jpg ' )
43+ result = self .xiaoding .send_link (title = '万万没想到,某小璐竟然...' , text = '故事是这样子的...' , message_url = 'https ://open.dingtalk .com/document/group/custom-robot-access ' , pic_url = 'http ://www.songshan.es/wp-content/uploads/2016/01/Yin-Yang.png ' )
4044 self .assertEqual (result ['errcode' ], 0 )
4145
4246 def test_send_markdown (self ):
@@ -49,28 +53,28 @@ def test_send_markdown(self):
4953 self .assertEqual (result ['errcode' ], 0 )
5054
5155 def test_send_actioncard (self ):
52- """测试发送整体跳转ActionCard消息功能(CardItem新API )"""
53- btns1 = [CardItem (title = "查看详情" , url = "https://www .dingtalk.com/" )]
56+ """1. 测试发送整体跳转ActionCard消息功能(基于CardItem新API )"""
57+ btns1 = [CardItem (title = "查看详情" , url = "https://open .dingtalk.com/document/group/custom-robot-access " )]
5458 actioncard1 = ActionCard (title = '万万没想到,竟然...' ,
55- text = ' \n ### 故事是这样子的...' ,
59+ text = ' \n ### 故事是这样子的...' ,
5660 btns = btns1 ,
5761 btn_orientation = 1 ,
5862 hide_avatar = 1 )
5963 result = self .xiaoding .send_action_card (actioncard1 )
6064 self .assertEqual (result ['errcode' ], 0 )
6165
62- """测试发送单独跳转ActionCard消息功能"""
63- btns2 = [CardItem (title = "支持" , url = "https://www.dingtalk.com/" ), CardItem (title = "反对" , url = "http ://www.back china .com/news/2018/01/11/537468.html " )]
66+ """2. 测试发送单独跳转ActionCard消息功能(基于CardItem新API) """
67+ btns2 = [CardItem (title = "支持" , url = "https://www.dingtalk.com/" ), CardItem (title = "反对" , url = "https ://www.baidu .com/" )]
6468 actioncard2 = ActionCard (title = '万万没想到,竟然...' ,
65- text = ' \n ### 故事是这样子的...' ,
69+ text = ' \n ### 故事是这样子的...' ,
6670 btns = btns2 ,
6771 btn_orientation = 1 ,
6872 hide_avatar = 1 )
6973 result = self .xiaoding .send_action_card (actioncard2 )
7074 self .assertEqual (result ['errcode' ], 0 )
7175
7276 def test_send_actioncard_old_api (self ):
73- """测试发送整体跳转ActionCard消息功能(数据列表btns旧API )"""
77+ """ 1. 测试发送整体跳转ActionCard消息功能(基于字典旧API )"""
7478 btns1 = [{"title" : "查看详情" , "actionURL" : "https://www.dingtalk.com/" }]
7579 actioncard1 = ActionCard (title = '万万没想到,竟然...' ,
7680 text = ' \n ### 故事是这样子的...' ,
@@ -80,9 +84,9 @@ def test_send_actioncard_old_api(self):
8084 result = self .xiaoding .send_action_card (actioncard1 )
8185 self .assertEqual (result ['errcode' ], 0 )
8286
83- """测试发送单独跳转ActionCard消息功能"""
87+ """2. 测试发送单独跳转ActionCard消息功能(基于字典旧API) """
8488 btns2 = [{"title" : "支持" , "actionURL" : "https://www.dingtalk.com/" },
85- {"title" : "反对" , "actionURL" : "http ://www.back china .com/news/2018/01/11/537468.html " }]
89+ {"title" : "反对" , "actionURL" : "https ://www.baidu .com/" }]
8690 actioncard2 = ActionCard (title = '万万没想到,竟然...' ,
8791 text = ' \n ### 故事是这样子的...' ,
8892 btns = btns2 ,
@@ -92,19 +96,19 @@ def test_send_actioncard_old_api(self):
9296 self .assertEqual (result ['errcode' ], 0 )
9397
9498 def test_send_feedcard (self ):
95- """测试发送FeedCard类型消息功能(CardItem新API )"""
96- carditem1 = CardItem (title = "氧气美女" , url = "https://www.dingtalk.com/" , pic_url = "http://pic1.win4000.com/wallpaper/2020-03-11/5e68b0557f3a6 .jpg" )
97- carditem2 = CardItem (title = "氧眼美女" , url = "https://www.dingtalk.com/" , pic_url = "http://pic1.win4000.com/wallpaper/2020-03-11/5e68b0557f3a6.jpg " )
98- carditem3 = CardItem (title = "氧神美女" , url = "https://www.dingtalk.com/" , pic_url = "http://pic1.win4000.com/wallpaper/2020-03-11/5e68b0557f3a6.jpg " )
99+ """测试发送FeedCard类型消息功能(基于CardItem新API )"""
100+ carditem1 = CardItem (title = "氧气美女" , url = "https://www.dingtalk.com/" , pic_url = "http://www.sinaimg.cn/dy/slidenews/5_img/2013_28/453_28488_469248 .jpg" )
101+ carditem2 = CardItem (title = "氧眼美女" , url = "https://www.dingtalk.com/" , pic_url = "http://www.songshan.es/wp-content/uploads/2016/01/Yin-Yang.png " )
102+ carditem3 = CardItem (title = "氧神美女" , url = "https://www.dingtalk.com/" , pic_url = "http://www.songshan.es/wp-content/uploads/2016/01/Yin-Yang.png " )
99103 cards = [carditem1 , carditem2 , carditem3 ]
100104 result = self .xiaoding .send_feed_card (cards )
101105 self .assertEqual (result ['errcode' ], 0 )
102106
103107 def test_send_feedcard_old_api (self ):
104- """测试发送FeedCard类型消息功能(FeedLink旧API )"""
105- feedlink1 = FeedLink (title = "氧气美女" , message_url = "https://www.dingtalk.com/" , pic_url = "http://pic1.win4000.com/wallpaper/2020-03-11/5e68b0557f3a6 .jpg" )
106- feedlink2 = FeedLink (title = "氧眼美女" , message_url = "https://www.dingtalk.com/" , pic_url = "http://pic1.win4000.com/wallpaper/2020-03-11/5e68b0557f3a6.jpg " )
107- feedlink3 = FeedLink (title = "氧神美女" , message_url = "https://www.dingtalk.com/" , pic_url = "http://pic1.win4000.com/wallpaper/2020-03-11/5e68b0557f3a6.jpg " )
108+ """测试发送FeedCard类型消息功能(基于FeedLink旧API )"""
109+ feedlink1 = FeedLink (title = "氧气美女" , message_url = "https://www.dingtalk.com/" , pic_url = "http://www.sinaimg.cn/dy/slidenews/5_img/2013_28/453_28488_469248 .jpg" )
110+ feedlink2 = FeedLink (title = "氧眼美女" , message_url = "https://www.dingtalk.com/" , pic_url = "http://www.songshan.es/wp-content/uploads/2016/01/Yin-Yang.png " )
111+ feedlink3 = FeedLink (title = "氧神美女" , message_url = "https://www.dingtalk.com/" , pic_url = "http://www.songshan.es/wp-content/uploads/2016/01/Yin-Yang.png " )
108112 links = [feedlink1 , feedlink2 , feedlink3 ]
109113 result = self .xiaoding .send_feed_card (links )
110114 self .assertEqual (result ['errcode' ], 0 )
0 commit comments