一、接口说明文档

环境准备:

安装火狐

安装插件: httprequester

https://addons.mozilla.org/en-US/firefox/addon/httprequester/

接口返回码:

接口返回code说明:

'00' : 成功

'01':用户已存在

'02':参数不合法

'03':参数错误(1、用户信息错误 2、参数错误,数据库中不存在相应数据)

'999':未知错误,看后台日志

请求接口例子:

Md5计算网站:

http://md5jiami.51240.com/

1、注册:post方法

请求地址:http:// 127.0.0.1:8080/register/

请求内容: {"username":"wulaoshi","password":"a12345678","email":"2055739@qq.com"}

返回内容:

{"code": "00", "userid": 5}

2、登录:post方法

请求地址:http://127.0.0.1:8080/login/

请求内容:{"username":"wulaoshi","password":"e9bc0e13a8a16cbb07b175d92a113126"}

返回内容:{"token": "94beb86afbf126a345b0cdf30e5e5202", "code": "00", "userid": 5, "login_time": "2016-10-13 22:50:24"}

3、新增博文:post方法

请求地址:http://127.0.0.1:8080/create/

请求内容:{"userid":5, "token": "94beb86afbf126a345b0cdf30e5e5202","title":"python", "content":"python port test"}

返回内容:{"data": [{"content": "python port test", "title": "python"}], "code": "00", "userid": 5}

4、修改博文:使用put方法

请求地址:http://127.0.0.1:8080/update/

请求内容:{"userid":5, "token": "94beb86afbf126a345b0cdf30e5e5202","articleId":11, "title":"gloryroad", "content":"test test!!!!!!!!!!!!!"}

返回内容:

{"articleId": 11, "update_time": "2016-10-13 23:11:36", "code": "00", "userid": 5}

5、查询用户博文:post方法

请求地址:http://127.0.0.1:8080/getBlogsOfUser/

请求内容:{"userid":5, "token": "94beb86afbf126a345b0cdf30e5e5202"}

返回内容:

{"data": [{"update_time": null, "title": "python", "content": "python port test", "articleId": 11, "owner": 5, "posted_on": "2016-10-13 22:56:49"}], "code": "00", "userid": 5}/

6、查询博文内容:get方法

请求地址:http://127.0.0.1:8080/getBlogContent/11

请求内容:空

返回内容:{"code": "00", "data": [{"update_time": "2016-10-13 23:11:36", "title": "gloryroad", "content": "test test!!!!!!!!!!!!!", "articleId": 11, "owner": 5, "posted_on": "2016-10-13 22:56:49"}]}/

7、批量查询博文内容:

请求地址:http://127.0.0.1:8080/getBlogsContent/articleIds=11,12

请求内容:空

返回内容:{"code": "00", "data": [{"update_time": "2016-10-13 23:11:36", "title": "gloryroad", "content": "test test!!!!!!!!!!!!!", "articleId": 11, "owner": 5, "posted_on": "2016-10-13 22:56:49"}, {"update_time": null, "title": "mysql0", "content": "mysql learn 0", "articleId": 12, "owner": 1, "posted_on": "2016-10-13 23:04:35"}]}/

8、删除博文:

请求地址:http://127.0.0.1:8080/delete/

请求内容:{"userid":5, "token": "94beb86afbf126a345b0cdf30e5e5202","articleId":[11]}

返回内容{"articleId": [11], "code": "00", "userid": 5}

Python2.7 代码实例

一、登录模块

1、用户注册

register

POST /register

Parameters:

参数规则说明:

username:

1、字母、数字组成

2、长度2~20位

3、字母不区分大小写

password:

1、长度8~20位

2、必须含有字母和数字

email:标准的email规则

Json串格式参数,示例:{"username":"lily","password":"lily","email":"lily@qq.com"}

Response:

{"code": "00", "userid": 2}

example

import requests

import json

print "register------"

data = json.dumps({'username': 'lily', 'password': 'wcx123wac', 'email':'lily@qq.com'}) #

r = requests.post('http://localhost:8080/register/', data= data)

print r.status_code

print r.text

print type(r.json())

print str(r.json())

2、用户登录

login

POST /login

Parameters:

Json串格式参数,示例:

{"username":"lily", "password":"0550876efca0820e30e7398c177fd30b"}

Response:

{"token": "a1c0738a6cf054606b055a419c3390f3", "code": "00", "userid": 3, "login_time": "2016-09-06 12:02:14"}

example

import requests

import json

import hashlib

m5 = hashlib.md5()

m5.update('wcx123wacs')

pwd = m5.hexdigest()

print pwd

print "login------"

data = json.dumps({'username': 'lily', 'password': pwd}) #

r = requests.post('http://localhost:8080/login/', data = data)

print r.status_code

print r.text

print type(r.json())

print str(r.json())

二、博文编辑模块

1、新增博文

create

POST /create

Parameters:

Json串格式参数,示例:

{"userid":3, "token": "a1c0738a6cf054606b055a419c3390f3", "title":"python", "content":"python port test"}

Response:

{"data": [{"content": "python port test", "title": "python"}], "code": "00", "userid": 3}

example

import requests

import json

import hashlib

m5 = hashlib.md5()

m5.update('lily')

pwd = m5.hexdigest()

print pwd

print "create post------"

data = json.dumps({'userid': 1, token: "a1c0738a6cf054606b055a419c3390f3"s,'title':"mysql", 'content':'mysql learn'})

r = requests.post('http://localhost:8080/create/', data = data)

print r.text

print type(r.json())

print str(r.json())

2、修改博文

update

POST /update

Parameters:

Json串格式参数,示例:

{"userid":3, "token": "a1c0738a6cf054606b055a419c3390f3", "articleId":11, "title":"python", "content":"test test"}

Response:

{"data": [{"content": "python port test", "title": "python"}], "code": "00", "userid": 3}

example

import requests

import json

print "query posts of user------"

data = json.dumps({'userid':3, "token": "a1c0738a6cf054606b055a419c3390f3", 'offset':2, 'lines':3})

r = requests.post('http://localhost:8080/getBlogsOfUser/', data = data)

print r.status_code

print r.text

print type(r.json())

print str(r.json())

3、查询用户的博文

getBlogsOfUser

POST /getBlogsOfUser

Parameters:

Json串格式参数,示例:

{"userid":3, "token": "a1c0738a6cf054606b055a419c3390f3"}

{"userid":3,"token": "a1c0738a6cf054606b055a419c3390f3", "offset":2, "lines":3}

Response:

{"data": [{"update_time": null, "title": "oracle", "content": "oracle test", "articleId": 5, "owner": 2, "posted_on": "2016-09-02 14:24:58"}, {"update_time": null, "title": "C", "content": "C test", "articleId": 4, "owner": 2, "posted_on": "2016-09-02 14:24:49"}], "code": "00", "userid": 2}

example:

import requests

import json

print "query posts of user------"

data = json.dumps({'userid':3, "token": "a1c0738a6cf054606b055a419c3390f3",'offset':2, 'lines':3})

r = requests.post('http://localhost:8080/getBlogsOfUser/', data = data)

print r.status_code

print r.text

print type(r.json())

print str(r.json())

4、查询博文内容

getBlogContent

POST /getBlogContent

Parameters:

请求地址,示例:

http://localhost:8080/getBlogContent/1

Response:

{"code": "00", "data": [{"update_time": null, "title": "python", "content": "python port test", "articleId": 1, "owner": 2, "posted_on": "2016-09-02 14:24:24"}]}

example:

import requests

print "query post------"

articleId = 2

r = requests.get('http://localhost:8080/getBlogContent/'+ str(articleId))

print r.status_code

print r.text

print type(r.json())

print str(r.json())

5、批量查询博文

getBlogsContent

POST /getBlogsContent

Parameters:

请求地址,示例:

http://localhost:8080/getBlogsContent/articleIds=1,2,3

Response:

{"code": "00", "data": [{"update_time": null, "title": "python", "content": "python port test", "articleId": 1, "owner": 2, "posted_on": "2016-09-02 14:24:24"}, {"update_time": null, "title": "java", "content": "java port test", "articleId": 2, "owner": 2, "posted_on": "2016-09-02 14:24:32"}, {"update_time": null, "title": "C++", "content": "C++ test", "articleId": 3, "owner": 2, "posted_on": "2016-09-02 14:24:42"}]}

example:

import requests

print "query posts by blogId------"

r = requests.get('http://localhost:8080/getBlogsContent/'+ str("articleIds=1,2,3"))

print r.status_code

print r.text

print type(r.json())

print str(r.json())

6、删除博文

delete

POST /delete

Parameters:

Json串格式参数,示例:

{"userid":1, "token": "868d26e05666c5aaeb76d361faa7448c", "articleId":[1,2,3]}

Response:

{"articleId": [1, 2, 3], "code": "00", "userid": 1}

example:

import requests

import json

import hashlib

m5 = hashlib.md5()

m5.update('lily')

pwd = m5.hexdigest()

print pwd

print "delete post------"

data = json.dumps({"userid":1, "token":"868d26e05666c5aaeb76d361faa7448c", "articleId":[3,4,5]}) #

r = requests.delete('http://localhost:8080/delete/', data = data)

print r.status_code

print r.text

print type(r.json())

print str(r.json())

说明

如果在一些接口请求插件(比如httprequester)中请求这些接口时,传参时,键值对间不能存在空格,并且字符串必须用双引号引起来,跟使用Python程序请求有区别。

Python接口测试自动化说明及代码实例:含get、post、put、delete等方法的更多相关文章

  1. python接口测试自动化框架-发送邮件,邮箱报错: 535 Error, authentication failed

    1.无意中把腾讯企业邮箱设置为安全登录,接口测试自动化发送邮件,不能被正常接收.错误信息为:535 Error, authentication failed. 原因:认证安全登录后,原来新的邮箱代码传 ...

  2. python接口测试自动化之python基础语法

    一.pycharm的使用和python基本语法 (一).pycharm的使用和python环境 1.python以及pycharm的安装 python 的版本选择:3.x 版本,不要安装2.x 版本, ...

  3. Python接口测试框架实战与自动化进阶☝☝☝

    Python接口测试框架实战与自动化进阶☝☝☝  一.fiddler在工作中的运用  1.如何抓接口 抓紧手机端接口 ①.在电脑终端输入:ipconfig ,找到电脑ip ②.打开手机,连接WiFi, ...

  4. 【转】python文件和目录操作方法大全(含实例)

    python文件和目录操作方法大全(含实例) 这篇文章主要介绍了python文件和目录的操作方法,简明总结了文件和目录操作中常用的模块.方法,并列举了一个综合实例,需要的朋友可以参考下一.python ...

  5. python 解析XML python模块xml.dom解析xml实例代码

    分享下python中使用模块xml.dom解析xml文件的实例代码,学习下python解析xml文件的方法. 原文转自:http://www.jbxue.com/article/16587.html ...

  6. Python+reuqests自动化接口测试

    1.最近自己在摸索Python+reuqests自动化接口测试,要实现某个功能,首先自己得有清晰的逻辑思路!这样效率才会很快! 思路--1.通过python读取Excel中的接口用例,2.通过pyth ...

  7. Python模拟登陆淘宝并统计淘宝消费情况的代码实例分享

    Python模拟登陆淘宝并统计淘宝消费情况的代码实例分享 支付宝十年账单上的数字有点吓人,但它统计的项目太多,只是想看看到底单纯在淘宝上支出了多少,于是写了段脚本,统计任意时间段淘宝订单的消费情况,看 ...

  8. 接口测试时遇到 java 代码加密请求数据,用 python 的我该怎么办?

    前言 自动化测试应用越来越多了,尤其是接口自动化测试. 在接口测试数据传递方面,很多公司都会选择对请求数据进行加密处理. 而目前为主,大部分公司的产品都是java语言实现的.所以加密处理也是java实 ...

  9. Python中类的继承代码实例

    Python中类的继承代码实例 这篇文章主要介绍了Python中类的继承代码实例,本文直接给出代码及运行效果,需要的朋友可以参考下 相对于C 的继承编写,Python更简洁,而且效率也是很高的,下面编 ...

随机推荐

  1. IPV6与IPV4的区别

    IPv4协议的地址长度是32位,IPv6协议的地址长度是128位. 1.表示方式 IPv4地址表示为点分十进制格式,32位的地址分成4个8位分组,每个8位以十进制数显式,中间用点号分隔. 而IPv6采 ...

  2. mysql为什么范围查询(>,<,between,%like,like%)之后的索引无效

    因为使用了范围索引,所以会使用满足范围的所有的值,也就是说存储引擎在这个时候会提取出满足之后条件的所有值,并遍历获取满足之后条件的值. http://www.itpub.net/thread-1901 ...

  3. html&css笔记(1)

    本文是在阅读<head first html and css>时记下的一些需要注意的地方. 第3章 浏览器不会显示html文本中的空白符和换行. 标签的属性用来定义一个元素.p53 hre ...

  4. Python beautifulsoup 选择器 select 选择<meta/>等不需要成对结尾标签未写‘/’

    一些不需要成对的标签<meta/> <img/>d等使用bs4的css选择器时出现的情况: 选择某一标签,输出内容超出范围过多 from bs4 import Beautifu ...

  5. 【Ubuntu 16】 wifi连接 并解决无桌面图标问题

    笔记本上装了win10和ubuntu16双系统,ubuntu16有半年多没使用了,今天一登录成功后,没有桌面啦,一个干净的壁纸映入眼帘,真操蛋. 上网搜索后总结:应该是应用软件中心出了问题,可是,没法 ...

  6. python之路第二天 随便记记 今天主要很郁闷

    为何要有操作系统 为了让程序员更轻松的完成命令电脑工作而存在的,控制硬件,服务于软件. 操作系统的位置 操作系统位于软件和硬件之间.操作系统由内核(运行于内核态,控制硬件)和系统调用(运行于用户态,为 ...

  7. 使用canvas进行图像编辑

    前面的话 本文将分为几个小功能的形式来详细介绍canvas图像编辑 缩放 下面是一张分析图,假设默认情况下,图片和canvas宽高相同.图片的缩放(scale)范围为0.5到3,缩放时改变的是图片的大 ...

  8. AOP 面向切面的编程

    一.面向切面的编程需求的产生 代码混乱:越来越多的非业务需求(日志和验证等)加入后,原有的业务方法急剧膨胀.每个方法在处理核心逻辑的同时还必须兼顾其他多个关注点. 代码分散: 以日志需求为例,只是为了 ...

  9. 虚拟机搭建hadoop环境

    这里简单用三台虚拟机,搭建了一个两个数据节点的hadoop机群,仅供新人学习.零零碎碎,花了大概一天时间,总算完成了. 环境 Linux版本:CentOS 6.5 VMware虚拟机 jdk1.6.0 ...

  10. postman 第3节 API请求和查看响应结果(转)

    请求 postman支持很多请求类型,界面左侧可以看到请求类型:get.post.put.patch等,右侧是发送和保存按钮,下方是请求支持的认证方式.信息头.信息体.私有脚本和测试结果.下面我们介绍 ...