企业微信接口测试实战、Swagger简介
企业微信接口测试实战、Swagger简介
#!/user/bin/env python
# -*- coding: utf-8 -*-
import json
import requests
corpid = "" # 企业id
corpsecret = ""
class Tag:
def __init__(self):
self.token = ""
def get_token(self):
"""获取token"""
r = requests.get(
params={"corpid": corpid, "corpsecret": corpsecret}
)
self.token = r.json()["access_token"]
def list(self):
"""获取tag列表"""
r = requests.get(
params={"access_token=": self.token},
json={
"tag_id":[]
}
)
print(json.dumps(r.json(), intent=2)) # intent=2 会让结果间隔两个空格
return r
def add(self, group_name, tags):
r = requests.post(
url,
params={"access_token": self.token},
json={
"group_id": "GROUP_ID",
"group_name": group_name,
"order": 1,
"tag": tags,
"agentid": 1000014
}
)
# print(r.json())
print(json.dumps(r.json(), intent=2)) # intent=2 会让结果间隔两个空格
return r
test_tag.py
#!/user/bin/env python
# -*- coding: utf-8 -*-
import pytest
from Exercises.service.tag import Tag
# todo: 代码冗余
# todo: 与底层架构耦合太多
# todo: 封装层次不足,不利于管理
class TestTag:
def setup_class(self):
# todo: 外汇跟单gendan5.com数据清理过程,把测试数据清空或还原
self.tag = Tag()
self.tag.get_token()
def test_tag_list(self):
"""获取标签列表"""
r = self.tag.list()
assert r.status_code == 200
assert r.json()["errcode"] == 0
@pytest.mark.parametrize("group_name, tag_names", [
["group1", [{"name": "tag1"}]],
["group2", [{"name": "tag2"}, {"name": "tag3"}]]
])
def test_tag_get(self, group_name, tag_names):
# todo: 完善功能测试
"""创建标签"""
r = self.tag.add(group_name=group_name, tags=tag_names)
assert r.status_code == 200
assert r.json()['errcode'] == 0
"""校验列表"""
r = self.tag.list()
assert r.status_code == 200
assert r.json()["errcode"] == 0
group = [group for group in r.json()["tag_group"] if group["group_name"] == group_name][0]
tags = [{"name": tag['name']} for tag in r.json()["tag"]]
print(group)
print(tags)
assert group['group_name'] == group_name
assert tags == tag_names
def test_tag_fail(self):
pass
发表评论
暂时没有评论,来抢沙发吧~