## 什么是接口

>> Application Programming Interface

>

> 主要目的是提供应用程序与开发人员以访问一组例程的能力,而又无需访问源码,或理解内部工作机制的细节

## 为什么要做接口测试

> 接口测试是测试系统组件间接的一种测试。

>

>  接口测试主要用于检测外部系统与系统之间以及内部各个子系统之间的交互

>

> 测试的重点是要检查数据的交换、传递、控制管理过程、以及系统间相互逻辑的依赖

## 接口测试的主要测试内容

> 业务功能测试
>
> 参数组合测试
>
> 异常情况的测试
>
> 性能测试
>
> 安全测试等

 

## 接口测试环境准备

> 接口项目部署
>
> Python3 + Requests环境准备

 

## 利用Requests发送请求

```python
import requests
response = requests.get(r"http://www.baidu.com")
print(response.status_code)
print(response.text)
```

 

## Requests中的重定向(allow_redirects)

```python
import requests
response = requests.get(r"http://github.com")
print(response.status_code)
print(response.history)
```

## Session

> 跨请求保持cookie等信息

```python
from requests import Session
with Session() as s:
return s
```

 

## SSL及CA认证

```python
import requests
requests.get("https://host:port/path")

# output:
# requests.exceptions.SSLError
```

抛出SSL隧道异常,解决方案:

```python
import requests
requests.get("httpps://host:port/path",verify=True)
requests.get("httpps://host:port/path",verify="/path/to/certfile")
```

CA证书认证:

```python
import requests
requests.get('https://kennethreitz.org', cert=('/path/client.cert', '/path/client.key'))
requests.get('https://kennethreitz.org', cert='/wrong_path/client.pem')
```

 

posted on 2019-08-24 08:22  雨窝无瓜  阅读(86)  评论(0编辑  收藏  举报