手把手教你学会接口自动化4系列-封装登录调用之后的代码展示

发布时间:2024年01月13日

我们之前写的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
文章来源:https://blog.csdn.net/pacermaker/article/details/135565895
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。