test_doAdd.py 2.58 KB
#!/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"))