import requests from requests.auth import HTTPBasicAuth # 这个是必须要有的 import pytest import yaml
# 打开我的Headers.yaml文件 with open('E:/wj/saas/UwbNetworkServer/common/YamlFile/MyHeaders.yaml','r',encoding='utf-8') as f: Headers = yaml.safe_load(f) with open('E:/wj/saas/UwbNetworkServer/common/YamlFile/uwb_network_api.yaml','r',encoding='utf-8') as f: my_host = yaml.safe_load(f) host = my_host['host1'] # 新建组织 def test_organization(): api = '/v1/organization' # 添加的url url = host + api my_body = { "maxApplicationCount": 10, "maxGatewayCount": 10, "maxRegionCount": 10, "maxTerminalCount": 10, "name": "我的组织" } rp = requests.request(method='post', url=url, auth=HTTPBasicAuth('xxxx@qq.com','12345678'), json=my_body) #
print(rp.text) assert rp.status_code == 200 assert "success" in rp.text
tips:HTTPBasicAuth是一个基础验证,参数是username,password,仅限于内部信任的网络使用,外部尽量不要用~