参考资料
- 文档 - 企业微信开发者中心
- 接口文档 - 企业微信开发者中心
- 接口调试工具 https://work.weixin.qq.com/api/devtools/devtool.php
- 大课地址 霍格沃兹测试开发_霍格沃兹测试开发<!-- -->腾讯课堂官网<!-- -->
加入企业微信
获取token
- corpid= wwd6da61649bd66fea
- secret= C7uGOrNyxWWzwBsUyWEbLSNwj55XOKL9dtGUm_2p_Fw
token
hk4qPSljFvj93LkfVaujVvSaGwbDmNhE3ueub9cCN1y_TdKapd-5TJ-LmLgA7BHjZxQQRCArmOgfwoUdk_TffS2JWPynefFfRYocrHJ6Y98QetBh84Mp4CG2CcxnJUWlw7FPqvBwi2IUpY5uquq8V1kNveYZwho7VlJ-liKcfxhnaqWOQ0D6VyPBR0_PyKdbK68mHvzxE5No3mKgDURP9g
代码示例
import requests
from wework.wework import WeWork
#todo: 封装框架,实现与requests无关的实现,如果接口将来变成了xml、或者dubbo等rpc协议,仍然可以轻松支持
#todo:数据驱动,将接口的定义从编码变成从配置文件、har文件、数据文件中读取
#todo:专题测试 diff、schema自动校验、自动生成用例、自动生成测试数据
#todo:测试的平台,管理测试数据、测试接口定义,测试的报告
#todo:测试中台,让研发与运维可以使用和对接
class Department:
def list(self, id=1058):
r = requests.get('https://qyapi.weixin.qq.com/cgi-bin/department/list', params={
'access_token': WeWork.get_token(),
'id': id
})
print(r.json())
# assert r.json()['errcode'] == 0
return r.json()
def create(self, name, parentid=1058, **kwargs):
r = requests.post("https://qyapi.weixin.qq.com/cgi-bin/department/create", params={
'access_token': WeWork.get_token()
}, json={
'name': name,
'parentid': parentid
})
return r.json()
def delete(self, id):
r = requests.get("https://qyapi.weixin.qq.com/cgi-bin/department/delete", params={
'access_token': WeWork.get_token(),
'id': id
})
return r.json()
def update(self, id, name, **kwargs):
r = requests.post('https://qyapi.weixin.qq.com/cgi-bin/department/update',
params={
'access_token': WeWork.get_token()
},
json={
'id': id,
'name': name
}
)
return r.json()
测试用例
import pytest
import requests
from wework.department.department import Department
from wework.wework import WeWork
class TestWeWork:
token = ""
@classmethod
def setup_class(cls):
cls.token = WeWork.get_token()
cls.department = Department()
# todo: 封装api
@pytest.mark.parametrize("id", [
1058, 1059, 1060
])
def test_department_list(self, id):
# todo: 完善用例设计,增加更多用例,更多断言
r = self.department.list(id)
assert r['errcode'] == 0
@pytest.mark.parametrize("name", [
"demo6", "demo7", "demo8"
])
def test_department_create(self, name):
r = self.department.create(name=name, parentid=1058)
assert r['errcode'] == 0
# done: 反复调用了api
r = self.department.list(1058)
# json path
assert r['department'][-1]['name'] == name
def test_department_delete(self):
name = "delete_1"
r = self.department.create(name, 1058)
assert r['errcode'] == 0
r = self.department.list(1058)
assert r['department'][-1]['name'] == name
id = r['department'][-1]['id']
self.department.delete(id)
r = self.department.list(1058)
assert r['department'][-1]['name'] != name
def test_department_update(self):
name = "update_1"
name_new = f"{name}_update"
self.department.create(name)
r = self.department.list(1058)
assert r['department'][-1]['name'] == name
id = r['department'][-1]['id']
r = self.department.update(id, name_new, name_en="name_en_demo")
print(r)
assert r['errcode'] == 0
r = self.department.list(1058)
assert r['department'][-1]['name'] == name_new