python - 接口自动化,存放 URL 请求,解决接口直接的上下文依赖
前言
1、很多人问再做接口自动化时,对于接口上下文的依赖怎么处理?
例如,下个接口 url 依赖上一个请求成功后的参数
这里给个示例做参考,完美解决 URL 依赖问题
# -*- coding:utf-8 -*-
class QciUrl(object):
@staticmethod
def create_project_URI():
return "/platform/project/create"
@staticmethod
def create_init_depot_URI(current_team, project_name):
return "/user/{}/project/{}/depot".format(current_team, project_name)
@staticmethod
def create_ci_job_URI(current_team, project_name):
return "/user/{}/project/{}/ci".format(current_team, project_name)
@staticmethod
def get_project_URI():
return "/platform/project/pages"
@staticmethod
def delete_project_URI(project_id):
return "/platform/project/{}".format(project_id)
封装一个静态类,供所有请求直接调用即可