forked from SeldomQA/XTestRunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_send_dingtalk.py
72 lines (60 loc) · 1.97 KB
/
test_send_dingtalk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import unittest
from XTestRunner import HTMLTestRunner
from XTestRunner import DingTalk
"""
帮助文档:
https://open.dingtalk.com/document/group/enterprise-created-chatbot
* access_token: 钉钉机器人的access_token
* key: 如果钉钉机器人安全设置了关键字,则需要传入对应的关键字。
* app_secret: 如果钉钉机器人安全设置了签名,则需要传入对应的密钥。
* at_mobiles: 发送通知钉钉中要@人的手机号列表,如:[137xxx, 188xxx]。
* is_at_all: 是否@所有人,默认为False, 设为True则会@所有人。
"""
class TestDing(unittest.TestCase):
"""
测试用例说明
"""
def test_success(self):
self.assertEqual(2 + 3, 5)
@unittest.skip("skip case")
def test_skip(self):
pass
def test_fail(self):
self.assertEqual(5, 6)
def test_error(self):
self.assertEqual(a, 6)
if __name__ == '__main__':
suit = unittest.TestSuite()
suit.addTests([
TestDing("test_success"),
TestDing("test_skip"),
TestDing("test_fail"),
TestDing("test_error")
])
report = "./reports/test_send_dingtalk.html"
with open(report, 'wb') as fp:
runner = HTMLTestRunner(
stream=fp,
title='测试发送钉钉',
tester='虫师',
description=['类型:测试发送钉钉'],
language="zh-CN"
)
runner.run(suit)
# 方式一: send_dingtalk() 方法
runner.send_dingtalk(
access_token="690900b5ce6d5d10bb1218b8e64a4e2b55f96a6d116aaf50",
key="xxxx",
app_secret="xxxxx",
at_mobiles=[13700000000, 13800000000],
is_at_all=False,
)
# 方式二: DingTalk 类
ding = DingTalk(
access_token="690900b5ce6d5d10bb1218b8e64a4e2b55f96a6d116aaf50",
key="xxxx",
app_secret="xxxxx",
at_mobiles=[13700000000, 13800000000],
is_at_all=False
)
ding.sender()