test_doAdd.py
2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import unittest
import urllib3
from commons import common as com
from commons.MySession import my
from commons.api.fieldConfig import fieldConfig
from commons.api.doAdd import doAdd
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
do=doAdd()
field=fieldConfig()
class test_doAdd(unittest.TestCase):
"新增登记接口"
@classmethod
def setUpClass(cls):
#通过字段配置接口提前配置新增页的字段配置
my.post(url=field.url,headers=field.header,json=field.body)
# @unittest.case_mark(my.mark("test"))
def test_doAdd_01(self):
"成功新增一个商品为大白菜的报备单,重量为111"
#请求数据不需要修改,直接POST请求
re=my.post(url=do.url,headers=do.header,json=do.body)
print(re.json())
#响应断言
self.assertEqual(re.status_code, 200)
self.assertTrue("'code':'200'" in str(re.json()).replace(" ",""))
@unittest.case_mark(my.mark())
def test_doAdd_02(self):
"成功新增一个商品为鲜花生的报备单,重量为111"
#请求数据需要修改
body=do.body.copy()
body["productName"]="鲜花生"
body["productId"]="3496"
#POST请求
re=my.post(url=do.url,headers=do.header,json=body)
print(re.json())
#响应断言
self.assertEqual(re.status_code, 200)
self.assertTrue("'code':'200'" in str(re.json()).replace(" ",""))
@unittest.case_mark(my.mark())
def test_doAdd_03(self):
"用错误的用户来新增,无法新增"
#请求数据需要修改
body=do.body.copy()
body["userId"]="516111"
#POST请求
re=my.post(url=do.url,headers=do.header,json=body)
print(re.json())
#响应断言
self.assertEqual(re.status_code, 200)
self.assertTrue("查询客户信息失败" in str(re.json()).replace(" ",""))
@unittest.case_mark(my.mark())
def test_doAdd_04(self):
"成功新增一个商品为大白菜的报备单,重量为666"
#请求数据不需要修改,直接POST请求
body=do.body.copy()
body["weight"]="666"
re=my.post(url=do.url,headers=do.header,json=body)
print(re.json())
#响应断言
self.assertEqual(re.status_code, 200)
self.assertTrue("'code':'200'" in str(re.json()).replace(" ",""))
@classmethod
def tearDownClass(cls):
pass
if __name__ == "__main__":
# unittest.main(verbosity=2)
com.run_one(test_doAdd("test_doAdd_03"))