基于postman的接口测试

 

一、接口返回码说明

接口返回code说明:

'00' : 成功

'01':用户已存在

'02':参数不合法

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

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

二、登陆模块

2.1 用户注册

register

 

POST /register/

 

Parameters:

 

参数描述

参数名称

约束

参数类型

示例

用户名

username

必填

String

“posttest”

密码

password

必填

string

“test12345”

邮箱

email

必填

String

“1364243976@qq.com”

 

参数规则说明:

username:

1、字母、数字组成

2、长度2~20位

3、字母不区分大小写

 

password:

1、长度8~20位

2、必须含有字母和数字

标准的email规则

 

请求的url: http://39.106.41.11:8080/register/

 

Json串格式参数,示例:

{"username":"posttest","password":"test12345","email":"1364243976@qq.com"}

 

Response

 

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

 

或者用python代码实现注册功能

example

 

#encoding=utf-8

import requests

import json

import os

import hashlib

m5 = hashlib.md5()

m5.update('wulaoshi12345'.encode("utf-8"))

pwd = m5.hexdigest()

print (pwd)

print ("login------")

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

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

print (r.status_code)

print (r.text)

print (type(r.json()))

print (str(r.json()))

2.2 用户登录

login

 

POST /login/

 

Parameters:

 

参数描述

参数名称

约束

参数类型

示例

用户名

username

必填

string

posttest

密码

password

必填

string,md5加密

c06db68e819be6ec3d26c6038d8e8d1f

Json串格式参数,示例:

{"username":"posttest", "password":"c06db68e819be6ec3d26c6038d8e8d1f"}

 

 

Response

 

{"token": "cccffcc674825668af61d375111a787f", "code": "00", "userid": 16, "login_time": "2018-07-16 11:36:02"}

 

example

 

#encoding=utf-8

import requests

import json

import os

import hashlib

m5 = hashlib.md5()

m5.update('wulaoshi12345'.encode("utf-8"))

pwd = m5.hexdigest()

print (pwd)

print ("login------")

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

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

print (r.status_code)

print (r.text)

print (type(r.json()))

print (str(r.json()))

 

三、博文编辑

3.1 新增博文

create

 

POST /create/

 

Parameters:

 

参数描述

参数名称

约束

参数类型

示例

用户id

userid

必填

int

16

token

token

必填

String

c06db68e819be6ec3d26c6038d8e8d1f

博文标题

title

必填

text

python

博文内容

content

必填

text

Port test

 

Json串格式参数,示例:

{"userid":16, "token": "cccffcc674825668af61d375111a787f", "title":"python", "content":"python port test"}

Response

 

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

 

example

 

#encoding=utf-8

import requests

import json

import os

import hashlib

m5 = hashlib.md5()

m5.update('posttest'.encode("utf-8"))

pwd = m5.hexdigest()

print (pwd)

print ("create post------")

data = json.dumps({'userid': 16, 'token': "cccffcc674825668af61d375111a787f", 'title':"mysql ", 'content':'mysql learn'}) 

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

print (r.text)

print (type(r.json()))

print (str(r.json()))

3.2修改博文

update

 

PUT /update/

 

Parameters:

 

参数描述

参数名称

约束

参数类型

示例

用户id

userid

必填

int

16

token

token

必填

String

cccffcc674825668af61d375111a787f

博文id

articleId

必填

int

2

博文标题

title

必填

text

python

博文内容

content

必填

text

Port test

 

Json串格式参数,示例:

{"userid":16, "token": "cccffcc674825668af61d375111a787f", "articleId":11, "title":"python", "content":"test test"}

Response

 

None

 

备注:说明程序有问题,需要修复

example

 

 

#encoding=utf-8

import requests

import json

import os

import hashlib

m5 = hashlib.md5()

m5.update('posttest'.encode("utf-8"))

pwd = m5.hexdigest()

print (pwd)

print ("update post------")

data = json.dumps({'userid': 16, "token": "cccffcc674825668af61d375111a787f", 'articleId': 4, 'title': 'about port', 'content': 'code code'}) #

r = requests.put('http://39.106.41.11:8080/update/', data = data)

print (r.status_code)

print (r.text)

print (type(r.json()))

print (str(r.json()))

3.3查询用户的博文

getBlogsOfUser

POST /getBlogsOfUser/

 

Parameters:

 

 

获取指定用户的博文(支持偏移量)

参数描述

参数名称

约束

参数类型

示例

用户id

userid

必填

int

16

token

token

必填

String

cccffcc674825668af61d375111a787f

偏移量

offset

非必填

int

3

指定所取条数

lines

非必填

int

2

Offset与lines结合使用,表示跳过offset条取lines条数据,当不传offset或lines时,获取用户全部博文。

Json串格式参数,示例:

{"userid":16, "token": "cccffcc674825668af61d375111a787f"}

{"userid":16, "token": "cccffcc674825668af61d375111a787f", "offset":2, "lines":3}

Response

 

{"data": [{"update_time": null, "title": "python", "content": "python port test", "articleId": 11, "owner": 16, "posted_on": "2018-07-16 12:00:56"},

{"data": [], "code": "00", "userid": 16}

example

 

#encoding=utf-8

import requests

import json

import os

print ("query posts of user------")

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

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

print (r.status_code)

print (r.text)

print (type(r.json()))

print (str(r.json()))

 

3.4查询博文内容

getBlogContent

GET /getBlogContent/

 

Parameters:

 

 

参数描述

参数名称

约束

参数类型

示例

博文id

articieId

必填

int

1

请求地址示例:

http://39.106.41.11:8080/getBlogContent/1

Response

 

{"code": "00", "data": [{"update_time": null, "title": "lshmysql ", "content": "lsh_mysql learn", "articleId": 1, "owner": 2, "posted_on": "2018-07-15 21:11:11"}]}

example

 

#encoding=utf-8

import requests

import json

import os

print ("query post------")

articleId = 2

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

print (r.status_code)

print (r.text)

print (type(r.json()))

print (str(r.json()))

3.5批量查询博文

getBlogsContent

GET /getBlogsContent/

 

Parameters:

 

 

参数描述

参数名称

约束

参数类型

示例

博文id

articieIds

必填

String,id组成的字符串,以逗号隔开

1,2,3

请求地址示例:

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

 

Response

 

{"code": "00", "data": [{"update_time": null, "title": "lshmysql ", "content": "lsh_mysql learn", "articleId": 1, "owner": 2, "posted_on": "2018-07-15 21:11:11"}, {"update_time": null, "title": "lshmysql ", "content": "lsh_mysql learn", "articleId": 2, "owner": 2, "posted_on": "2018-07-15 21:11:13"}, {"update_time": null, "title": "lshmysql ", "content": "lsh_mysql learn", "articleId": 3, "owner": 2, "posted_on": "2018-07-15 21:11:16"}]}

 

example

 

#encoding=utf-8

import requests

import json

import os

print ("query posts by blogId------")

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

print (r.status_code)

print (r.text)

print (type(r.json()))

print (str(r.json()))

3.6删除博文

delete

 

POST /delete/

 

Parameters:

 

参数描述

参数名称

约束

参数类型

示例

用户id

userid

必填

int

16

token

token

必填

String

cccffcc674825668af61d375111a787f

博文id列表

articleId

必填

int

[2,3,23]

 

Json串格式参数,示例:

{"userid":16, "token": "cccffcc674825668af61d375111a787f", "articleId":[1,2,3]}

Response

 

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

example

 

#encoding=utf-8

import requests

import json

import os

import hashlib

m5 = hashlib.md5()

m5.update('posttest'.encode("utf-8"))

pwd = m5.hexdigest()

print (pwd)

print ("delete post------")

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

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

print (r.status_code)

print (r.text)

print (type(r.json()))

print (str(r.json()))

四、注意事项

1 token 使用一段时间会过期,失效后需重新获取

2 python程序做接口测试,传参时,键值对间可以存在空格;其他工具(如httprequest)做接口测试,传参时,键值对间不可以存在空格

3 使用python代码做接口测试,引入包时需先确认该包已经被安装,example部分是用Python 3.6实现的

 

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值