我们之前写的demo里面有一个重复的工作,每次做业务测试的时候,都需要把登录的步骤写在代码里面,如下:
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2024/01
# @Author : Laopi
import json
import requests
'''
调用登录获取token
'''
url = "http://192.168.0.134:8081/login"
headers={"Content-Type":"application/x-www-form-urlencoded"}
data={"username":"admin","password":"123456"}
response = requests.post(url=url,
headers=headers,
data=data)
cookie = response.json()['Admin-Token']
url = "http://192.168.0.134:8081/CrmLeads/addOrUpdate"
headers={"Content-Type":"application/json","Admin-Token":cookie}
data ={"entity": {
"leads_name": "收到就好2",
"telephone": "15991710522",
"mobile": "15991710522",
"address": "111",
"next_time": "2024-01-08 00:00:00",
"remark": "11111111"
},
"field": [
{
"fieldId": 2,
"formType": "select",
"isNull": 0,
"name": "线索来源",
"options": "促销,搜索引擎,广告,转介绍,线上注册,线上询价,预约上门,电话咨询,邮件咨询",
"isUnique": 0,
"inputTips": "null",
"type": 3,
"value": "搜索引擎",
"fieldType": 0,
"fieldName": "线索来源",
"setting": [
"促销",
"搜索引擎",
"广告",
"转介绍",
"线上注册",
"线上询价",
"预约上门",
"电话咨询",
"邮件咨询"
]
},
{
"fieldI