Commit 58ce55a3a9b0c8e2d8bcebe6376953c7e3a4cf9f

Authored by 175930106
Committed by liujiqiang
1 parent 7b71d8ba

新增用户账户和环境的参数化代码

src/commons/MyRequest.py
@@ -33,15 +33,18 @@ class myrequest(object): @@ -33,15 +33,18 @@ class myrequest(object):
33 log.info('响应body为{};'.format(res.json())) 33 log.info('响应body为{};'.format(res.json()))
34 return res 34 return res
35 35
36 - def post2(self,api,**kwargs): 36 + def post2(self,session,api,**kwargs):
  37 + self.se=session
37 self.api=api.split("_")[2] 38 self.api=api.split("_")[2]
38 self.api_num=(api.split("_")[2]+api.split("_")[1]) 39 self.api_num=(api.split("_")[2]+api.split("_")[1])
39 - self.method=com.get_api_config(self.api,self.api_num,'method')  
40 - self.body_format=com.get_api_config(self.api,self.api_num,'body_format')  
41 - self.url=com.get_api_config(self.api,self.api_num, 'url') 40 + #获取接口的请求方法,url,header,body_format,body等数据
  41 + self.method=com.get_api_config(self.api,self.api,'method')
  42 + self.body_format=com.get_api_config(self.api,self.api,'body_format')
  43 + self.url=com.get_api_config(self.api,self.api, 'url')
  44 + self.headers=json.loads(com.get_api_config(self.api,self.api,'header'))
  45 + #判断请求数据类型
42 self.data=None if self.body_format=="JSON" else com.get_api_config(self.api,self.api_num,'body') 46 self.data=None if self.body_format=="JSON" else com.get_api_config(self.api,self.api_num,'body')
43 self.json=None if self.body_format=="FORM" else json.loads(com.get_api_config(self.api,self.api_num,'body')) 47 self.json=None if self.body_format=="FORM" else json.loads(com.get_api_config(self.api,self.api_num,'body'))
44 - self.headers=json.loads(com.get_api_config(self.api,self.api_num,'header'))  
45 log.info('{0:=^80}'.format('请求接口为{}'.format(api))) 48 log.info('{0:=^80}'.format('请求接口为{}'.format(api)))
46 log.info('请求地址为{}; 请求方式为{}; 请求body格式为{};\n 请求body为{}{};'.format( 49 log.info('请求地址为{}; 请求方式为{}; 请求body格式为{};\n 请求body为{}{};'.format(
47 self.url, 50 self.url,
@@ -51,7 +54,7 @@ class myrequest(object): @@ -51,7 +54,7 @@ class myrequest(object):
51 self.json)) 54 self.json))
52 55
53 if self.method.upper()=="POST": 56 if self.method.upper()=="POST":
54 - res = self.se.post(self.url, data=self.data, json=self.json,proxies=self.proxies,headers=self.headers,**kwargs) 57 + res = self.se.post(self.url, data=self.data, json=self.json,headers=self.headers,**kwargs)
55 log.info('响应body为{};'.format(res.json())) 58 log.info('响应body为{};'.format(res.json()))
56 return res 59 return res
57 elif self.method.upper()=="GET": 60 elif self.method.upper()=="GET":
@@ -76,27 +79,6 @@ class myrequest(object): @@ -76,27 +79,6 @@ class myrequest(object):
76 def close_session(self): 79 def close_session(self):
77 self.se.close() 80 self.se.close()
78 81
79 -# def to_request(self,method,url,data=None,is_json=False,**kwargs): #最后加入**kwargs使可以传headers  
80 -# method = method.upper()  
81 -# if isinstance(data,str):  
82 -# try:  
83 -# data = json.load(data) #'{"mobilephone": "18911114444", "pwd": "123456", "regname": "youxiu"}'  
84 -# except Exception as e:  
85 -# # print("异常为{}".format(e))  
86 -# Logger.error("异常为{}".format(e))  
87 -# data = eval(data) #'{"mobilephone": '18911114444',1:"4545"}' 非json的字符串  
88 -# if method == 'GET':  
89 -# res = self.one_session.request(method,url,params=data,**kwargs)  
90 -# elif method == 'POST':  
91 -# if is_json:  
92 -# res = self.one_session.request(method, url, json=data,**kwargs)  
93 -# else:  
94 -# res = self.one_session.request(method, url, data=data,**kwargs)  
95 -# else:  
96 -# res = None  
97 -# # print("405 METHOD NOT ALLOWED")  
98 -# Logger.error("METHOD NOT ALLOWED".format(method))  
99 -# return res  
100 # 82 #
101 # test=myrequest() 83 # test=myrequest()
102 # # 获取session 84 # # 获取session
@@ -115,3 +97,6 @@ class myrequest(object): @@ -115,3 +97,6 @@ class myrequest(object):
115 # 97 #
116 # re3=test.post2("test_01_upStream",body="json") 98 # re3=test.post2("test_01_upStream",body="json")
117 # print(re3.json()) 99 # print(re3.json())
  100 +# a="test_04_upStream"
  101 +# print(a.split("_")[2])
  102 +# print(a.split("_")[2]+a.split("_")[1])
118 \ No newline at end of file 103 \ No newline at end of file
src/commons/MyRequest2.py deleted 100644 → 0
1 -#!/usr/bin/python  
2 -# -*- coding: UTF-8 -*-  
3 -import requests  
4 -import json  
5 -from commons import common as com  
6 -from commons.Logging import Logger  
7 -# from requests.adapters import HTTPAdapter HTTPAdapter(max_retries=3)  
8 -import urllib3  
9 -urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)  
10 -log=Logger()  
11 -  
12 -class myrequest(object):  
13 -  
14 - def __init__(self):  
15 - self.timeout = 60  
16 - self.max_retries = 3  
17 - self.keep_alive = False  
18 - self.ssl_verify=False  
19 - self.proxies=None  
20 - self.allow_redirects=False  
21 -  
22 - def get(self,url,**kwargs):  
23 - log.info('{0:=^80}'.format('进行GET请求'))  
24 - log.info('请求地址为{};\n'.format(url))  
25 - res = self.se.get(url, proxies=self.proxies,**kwargs)  
26 - log.info('响应body为{};'.format(res.json()))  
27 - return res  
28 -  
29 - def post(self,api,url, data=None, json=None, header=None,**kwargs):  
30 - log.info('{0:=^80}'.format('进行POST请求'))  
31 - log.info('请求地址为{};\n 请求body为{};\n'.format(url,data))  
32 - res = self.se.post(url, data=data, json=json,  
33 - headers=header,  
34 - timeout=self.timeout,  
35 - max_retries=self.max_retries,  
36 - keep_alive=self.keep_alive,  
37 - proxies=self.proxies,  
38 - allow_redirects=self.allow_redirects )  
39 - log.info('响应body为{};'.format(res.json()))  
40 - return res  
41 -  
42 - def put(self,url, data=None, **kwargs):  
43 - res = self.se.put(url, data=data, **kwargs)  
44 - return res  
45 -  
46 - def delete(self,url, **kwargs):  
47 - res = self.se.delete(url, **kwargs)  
48 - return res  
49 -  
50 - def patch(self,url, data=None, **kwargs):  
51 - res = self.se.patch(url,data=data, **kwargs)  
52 - return res  
53 -  
54 - def head(self, url, **kwargs):  
55 - res = self.se.patch(url,data=None, **kwargs)  
56 - return res  
57 -  
58 - def close(self):  
59 - self.se.close()  
60 -  
61 -# return res  
62 -  
63 -# test=myrequest()  
64 -# re=test.getSession(True)  
65 -# print(re.headers)  
66 \ No newline at end of file 0 \ No newline at end of file
src/commons/__pycache__/ConfigDB.cpython-36.pyc
No preview for this file type
src/commons/__pycache__/Logging.cpython-36.pyc
No preview for this file type
src/commons/__pycache__/MyRequest.cpython-36.pyc
No preview for this file type
src/commons/__pycache__/MyRequest2.cpython-36.pyc
No preview for this file type
src/commons/__pycache__/__init__.cpython-36.pyc
No preview for this file type
src/commons/__pycache__/common.cpython-36.pyc
No preview for this file type
src/commons/api/__pycache__/__init__.cpython-36.pyc
No preview for this file type
src/commons/api/__pycache__/login.cpython-36.pyc
No preview for this file type
src/commons/api/__pycache__/upStream.cpython-36.pyc
No preview for this file type
src/commons/api/login.py
@@ -28,8 +28,7 @@ class login(): @@ -28,8 +28,7 @@ class login():
28 body="userName=sg_wenze&password=111111" 28 body="userName=sg_wenze&password=111111"
29 29
30 def __init__(self): 30 def __init__(self):
31 - self.login_url="test2"  
32 - self.url=login.url 31 + self.url=login.url.replace("test.uap.diligrp.com",com.get_global_config("global_data", "environment", "en") )
33 self.header=login.header 32 self.header=login.header
34 self.body=login.body 33 self.body=login.body
35 34
@@ -37,20 +36,16 @@ class login(): @@ -37,20 +36,16 @@ class login():
37 self.body=login.body.replace("sg_wenze", name) 36 self.body=login.body.replace("sg_wenze", name)
38 self.body=login.body.replace("111111", password) 37 self.body=login.body.replace("111111", password)
39 self.se=requests.session() 38 self.se=requests.session()
40 -# self.se.post(url=self.url, headers=self.header,data=self.body,**kwargs)  
41 self.se.post(url=login.url, headers=login.header,data=login.body,**kwargs) 39 self.se.post(url=login.url, headers=login.header,data=login.body,**kwargs)
42 return self.se 40 return self.se
43 41
44 def get_session2(self,account,**kwargs): 42 def get_session2(self,account,**kwargs):
45 - self.body=login.body.replace("sg_wenze", com.get_global_config("account", "account", "sg_username01"))  
46 - self.body=login.body.replace("111111", com.get_global_config("account", "account", "sg_password01")) 43 + self.body=self.body.replace("sg_wenze", com.get_global_config("global_data", "account", account).split("&")[0])
  44 + self.body=self.body.replace("111111", com.get_global_config("global_data", "account", account).split("&")[1])
47 self.se=requests.session() 45 self.se=requests.session()
48 -# self.se.post(url=self.url, headers=self.header,data=self.body,**kwargs)  
49 - self.se.post(url=login.url, headers=login.header,data=login.body,**kwargs) 46 + re=self.se.post(url=self.url, headers=self.header,data=self.body,**kwargs)
50 return self.se 47 return self.se
51 48
52 -  
53 -  
54 def close_session(self): 49 def close_session(self):
55 print("close session") 50 print("close session")
56 self.se.close() 51 self.se.close()
@@ -58,16 +53,16 @@ class login(): @@ -58,16 +53,16 @@ class login():
58 def post(self,name,password,firmid,**kwargs): 53 def post(self,name,password,firmid,**kwargs):
59 self.body=self.body.replace("sg_wenze", name) 54 self.body=self.body.replace("sg_wenze", name)
60 self.body=self.body.replace("111111", password) 55 self.body=self.body.replace("111111", password)
61 -# re=requests.post(url=self.url, headers=self.header,data=self.body,proxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'})  
62 re=requests.post(url=self.url, headers=self.header,data=self.body,**kwargs) 56 re=requests.post(url=self.url, headers=self.header,data=self.body,**kwargs)
63 57
64 print(re.headers) 58 print(re.headers)
65 return re 59 return re
66 -  
67 60
68 61
69 # t=login() 62 # t=login()
70 -# 63 +# print(t.url)
  64 +# t.get_session2("user01",proxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'},allow_redirects=False)
  65 +
71 # t.post("sg_wenze", "111111",proxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'}) 66 # t.post("sg_wenze", "111111",proxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'})
72 # def tt(**kwargs): 67 # def tt(**kwargs):
73 # print(kwargs) 68 # print(kwargs)
src/config/account.conf
@@ -24,3 +24,11 @@ password02=111 @@ -24,3 +24,11 @@ password02=111
24 [evnironment] 24 [evnironment]
25 25
26 26
  27 +
  28 +[Database]
  29 +dbhost=10.28.10.169
  30 +dbport=3306
  31 +dbname=trace
  32 +dbuser=root
  33 +dbpassword=123456
  34 +dbcharset=utf8
src/config/api/upStream.conf
1 # -*- coding: UTF-8 -*- 1 # -*- coding: UTF-8 -*-
2 -  
3 -[upStream01] 2 +[upStream]
4 method=post 3 method=post
5 url=http://test.trace.diligrp.com:8393/upStream/listPage.action 4 url=http://test.trace.diligrp.com:8393/upStream/listPage.action
6 body_format=JSON 5 body_format=JSON
@@ -17,8 +16,36 @@ header={ @@ -17,8 +16,36 @@ header={
17 "Accept-Encoding": "gzip,deflate", 16 "Accept-Encoding": "gzip,deflate",
18 "Accept-Language": "zh-CN,zh-TW;q=0.9,zh;q=0.8,en;q=0.7"} 17 "Accept-Language": "zh-CN,zh-TW;q=0.9,zh;q=0.8,en;q=0.7"}
19 18
  19 +[upStream01]
  20 +body={"rows":10,"page":1,"sort":"id","order":"desc","metadata":{"created":"{\"provider\":\"datetimeProvider\",\"index\":10,\"field\":\"created\"}","upORdown":"{\"provider\":\"userFlagProvider\",\"index\":20,\"field\":\"upORdown\"}","upstreamType":"{\"provider\":\"upStreamTypeProvider\",\"index\":30,\"field\":\"upstreamType\"}"}}
  21 +
  22 +
  23 +[upStream02]
  24 +body={"rows":10,"page":1,"sort":"id","order":"desc","metadata":{"created":"{\"provider\":\"datetimeProvider\",\"index\":10,\"field\":\"created\"}","upORdown":"{\"provider\":\"userFlagProvider\",\"index\":20,\"field\":\"upORdown\"}","upstreamType":"{\"provider\":\"upStreamTypeProvider\",\"index\":30,\"field\":\"upstreamType\"}"}}
  25 +
  26 +
  27 +[upStream03]
  28 +body={"rows":10,"page":1,"sort":"id","order":"desc","metadata":{"created":"{\"provider\":\"datetimeProvider\",\"index\":10,\"field\":\"created\"}","upORdown":"{\"provider\":\"userFlagProvider\",\"index\":20,\"field\":\"upORdown\"}","upstreamType":"{\"provider\":\"upStreamTypeProvider\",\"index\":30,\"field\":\"upstreamType\"}"}}
  29 +
  30 +
  31 +[upStream04]
20 body={"rows":10,"page":1,"sort":"id","order":"desc","metadata":{"created":"{\"provider\":\"datetimeProvider\",\"index\":10,\"field\":\"created\"}","upORdown":"{\"provider\":\"userFlagProvider\",\"index\":20,\"field\":\"upORdown\"}","upstreamType":"{\"provider\":\"upStreamTypeProvider\",\"index\":30,\"field\":\"upstreamType\"}"}} 32 body={"rows":10,"page":1,"sort":"id","order":"desc","metadata":{"created":"{\"provider\":\"datetimeProvider\",\"index\":10,\"field\":\"created\"}","upORdown":"{\"provider\":\"userFlagProvider\",\"index\":20,\"field\":\"upORdown\"}","upstreamType":"{\"provider\":\"upStreamTypeProvider\",\"index\":30,\"field\":\"upstreamType\"}"}}
21 33
22 34
  35 +[upStream05]
  36 +body={"rows":10,"page":1,"sort":"id","order":"desc","metadata":{"created":"{\"provider\":\"datetimeProvider\",\"index\":10,\"field\":\"created\"}","upORdown":"{\"provider\":\"userFlagProvider\",\"index\":20,\"field\":\"upORdown\"}","upstreamType":"{\"provider\":\"upStreamTypeProvider\",\"index\":30,\"field\":\"upstreamType\"}"}}
  37 +
  38 +
  39 +[upStream06]
  40 +body={"rows":10,"page":1,"sort":"id","order":"desc","metadata":{"created":"{\"provider\":\"datetimeProvider\",\"index\":10,\"field\":\"created\"}","upORdown":"{\"provider\":\"userFlagProvider\",\"index\":20,\"field\":\"upORdown\"}","upstreamType":"{\"provider\":\"upStreamTypeProvider\",\"index\":30,\"field\":\"upstreamType\"}"}}
  41 +
  42 +
  43 +[upStream07]
  44 +body={"rows":10,"page":1,"sort":"id","order":"desc","metadata":{"created":"{\"provider\":\"datetimeProvider\",\"index\":10,\"field\":\"created\"}","upORdown":"{\"provider\":\"userFlagProvider\",\"index\":20,\"field\":\"upORdown\"}","upstreamType":"{\"provider\":\"upStreamTypeProvider\",\"index\":30,\"field\":\"upstreamType\"}"}}
  45 +
23 expect_response={"code":"200","data":951,"message":"创建客户订单成功","result":"创建客户订单成功","success":true} 46 expect_response={"code":"200","data":951,"message":"创建客户订单成功","result":"创建客户订单成功","success":true}
24 47
  48 +
  49 +
  50 +
  51 +
src/config/global_data.conf
1 # -*- coding: UTF-8 -*- 1 # -*- coding: UTF-8 -*-
2 2
  3 +[account]
  4 +user01=sg_wenze&111111
  5 +user02=sy_wenze&111111
  6 +user03=hz_wenze&111111
  7 +
  8 +[environment]
  9 +en=test.uap.diligrp.com
  10 +
  11 +[Database]
  12 +dbhost=10.28.10.169
  13 +dbport=3306
  14 +dbname=trace
  15 +dbuser=root
  16 +dbpassword=123456
  17 +dbcharset=utf8
  18 +
  19 +
  20 +
3 21
4 [RequstHeader_fresh] 22 [RequstHeader_fresh]
5 header = { 23 header = {
@@ -35,11 +53,4 @@ instert_coupon=INSERT INTO `customer_coupon` VALUES ('10014', '0', '00010966', ' @@ -35,11 +53,4 @@ instert_coupon=INSERT INTO `customer_coupon` VALUES ('10014', '0', '00010966', '
35 53
36 54
37 55
38 -[Database]  
39 -dbhost=10.28.10.169  
40 -dbport=3306  
41 -dbname=tms  
42 -dbuser=root  
43 -dbpassword=123456  
44 -dbcharset=utf8  
45 56
src/testcase/test_tms_myrequest/test_upStream.py
@@ -7,83 +7,103 @@ from commons import ConfigDB as db @@ -7,83 +7,103 @@ from commons import ConfigDB as db
7 from commons import common as com 7 from commons import common as com
8 from commons.api.login import login 8 from commons.api.login import login
9 from commons.api.upStream import upStream 9 from commons.api.upStream import upStream
  10 +from commons.MyRequest import myrequest
10 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) 11 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
11 ll=login() 12 ll=login()
12 uu=upStream() 13 uu=upStream()
  14 +my=myrequest()
  15 +
13 16
14 -#列表查询  
15 class test_upStream(unittest.TestCase): 17 class test_upStream(unittest.TestCase):
16 - 18 + '''分别封装各个接口和数据,数据处理过程写入代码'''
17 @classmethod 19 @classmethod
18 def setUpClass(cls): 20 def setUpClass(cls):
19 - #新增登记单 21 + #获取session
20 cls.se=ll.get_session("sg_wenze", "111111") 22 cls.se=ll.get_session("sg_wenze", "111111")
21 - print(cls.se)  
22 - #由于可能有多种情况所以使用传统的setup 23 +
23 def setUp(self): 24 def setUp(self):
24 -# #新增登记单  
25 pass 25 pass
26 26
27 def test_01_upStream(self): 27 def test_01_upStream(self):
28 #成功查询上下游企业,无过滤条件---直接调用登陆类的方法,session可以保持一致 28 #成功查询上下游企业,无过滤条件---直接调用登陆类的方法,session可以保持一致
29 - url=uu.url  
30 - header=uu.header  
31 - body=uu.body  
32 - self.se.post(url=url,headers=header,json=body)  
33 -# re=uu.post(url=url,headers=header,json=body)  
34 -# print(self.se.json())  
35 - 29 + #直接把接口和数据一起封装,测试时直接调用接口数据(请求数据没有修改的情况)
  30 + re=self.se.post(url=uu.url,headers=uu.header,json=uu.body)
  31 + print(re.json())
  32 + self.assertEqual(re.status_code, 200)
  33 +
36 def test_02_upStream(self): 34 def test_02_upStream(self):
37 - #成功查询上下游企业,加入企业/个人名称过滤条件----直接调用自己类的方法,session和其他用了可能不一致  
38 - url=uu.url  
39 - header=uu.header 35 + #成功查询上下游企业,加入企业/个人名称过滤条件----直接调用登陆类的方法,session可以保持一致
  36 + #直接把接口和数据一起封装,测试时直接调用接口数据(需要修改请求数据的情况)
40 body=uu.body.copy() 37 body=uu.body.copy()
41 body["likeName"]="111" 38 body["likeName"]="111"
42 print("test_02_upStream",body) 39 print("test_02_upStream",body)
43 - re=uu.post("sg_wenze", "111111",url=url,headers=header,json=body) 40 + re=self.se.post(url=uu.url,headers=uu.header,json=uu.body)
44 print(re.json()) 41 print(re.json())
45 - 42 + self.assertEqual(re.status_code, 200)
  43 +
46 def test_03_upStream(self): 44 def test_03_upStream(self):
47 - #成功查询上下游企业,加入业户名称名称过滤条件----直接调用自己类的方法,session和其他用了可能不一致  
48 - url=uu.url  
49 - header=uu.header  
50 - body=uu.body.copy()  
51 - body["likeUserName"]="地利人和"  
52 - print("test_03_upStream",body)  
53 - re=uu.post("sg_wenze", "111111",url=url,headers=header,json=body) 45 + #成功查询上下游企业,加入业户名称名称过滤条件---实验直接传session给接口类使用(封装使用)
  46 + re=uu.post2(self.se,"sg_wenze", "111111",url=uu.url,headers=uu.header,json=uu.body)
  47 + print("test_03_upStream",re.json())
54 print(re.json()) 48 print(re.json())
55 - 49 + self.assertEqual(re.status_code, 200)
  50 +
56 def test_04_upStream(self): 51 def test_04_upStream(self):
57 - #成功查询上下游企业,加入业户名称名称过滤条件---实验直接传session给接口类使用  
58 - url=uu.url  
59 - header=uu.header  
60 - body=uu.body  
61 -# self.se.post(url=url,headers=header,json=body)  
62 - re=uu.post2(self.se,"sg_wenze", "111111",url=url,headers=header,json=body) 52 + #成功查询上下游企业,加入业户名称名称过滤条件
  53 + #使用公共的请求方法,数据需要单独维护
  54 + re=my.post2(self.se,"test_01_upStream")
63 print("test_04_upStream",re.json()) 55 print("test_04_upStream",re.json())
64 -  
65 -  
66 - def tearDown(self): 56 + self.assertEqual(re.status_code, 200)
67 57
  58 + def tearDown(self):
68 print("tearDown") 59 print("tearDown")
69 - 60 +
70 @classmethod 61 @classmethod
71 def tearDownClass(cls): 62 def tearDownClass(cls):
  63 + cls.se.close()
  64 +
  65 +
  66 +
  67 +class test_demo(unittest.TestCase):
  68 + '''提供一个封装好的公共方法,请求数据需求提前存储到配置文件'''
  69 + @classmethod
  70 + def setUpClass(cls):
  71 + #获取session
  72 + cls.se=ll.get_session("sg_wenze", "111111")
  73 +
  74 + def setUp(self):
72 pass 75 pass
  76 +
  77 + def test_01_demo(self):
  78 + #成功查询上下游企业,加入业户名称名称过滤条件
  79 + #使用公共的请求方法,数据需要单独维护
  80 + re=my.post2(self.se,"test_01_upStream")
  81 + print("test_01_upStream",re.json())
  82 + self.assertEqual(re.status_code, 200)
  83 +
  84 + def tearDown(self):
  85 + print("tearDown")
  86 +
  87 + @classmethod
  88 + def tearDownClass(cls):
  89 + cls.se.close()
  90 +
  91 +
  92 +
73 93
74 if __name__ == "__main__": 94 if __name__ == "__main__":
75 #unittest.main()方法会搜索该模块文件下所有以test开头的测试用例方法,并自动执行它们。 95 #unittest.main()方法会搜索该模块文件下所有以test开头的测试用例方法,并自动执行它们。
76 #如果不加下面这个语句,那么在通过unittest的方法添加测试用例时,这个文件里面的用例不会被搜索到。 96 #如果不加下面这个语句,那么在通过unittest的方法添加测试用例时,这个文件里面的用例不会被搜索到。
77 97
78 - unittest.main(verbosity=2) 98 +# unittest.main(verbosity=2)
79 99
80 # # 以下代码可以调试单个测试用例,用例中打印的语句不会展示到控制台,使用前需要注释上面的代码unittest.main(),如果不使用下面代码, 100 # # 以下代码可以调试单个测试用例,用例中打印的语句不会展示到控制台,使用前需要注释上面的代码unittest.main(),如果不使用下面代码,
81 # # 在有unittest.main()的情况下点击ctrl+f11,会直接运行当前页面所有用例,并且把用例用有打印的语句显示到控制台 101 # # 在有unittest.main()的情况下点击ctrl+f11,会直接运行当前页面所有用例,并且把用例用有打印的语句显示到控制台
82 -# current_suite = unittest.TestSuite()  
83 -# current_suite.addTest(submitOrder("test_01")) 102 + current_suite = unittest.TestSuite()
  103 + current_suite.addTest(test_upStream("test_08_upStream"))
84 # #以列表形式添加多个测试用例 104 # #以列表形式添加多个测试用例
85 # # current_suite.addTests([submitOrder_With_Coupon("test_01"),submitOrder_With_Coupon("test_02")]) 105 # # current_suite.addTests([submitOrder_With_Coupon("test_01"),submitOrder_With_Coupon("test_02")])
86 # # 执行测试 106 # # 执行测试
87 -# runner = unittest.TextTestRunner()  
88 -# #runner.run(可以直接添加测试用例如submitOrder_With_Coupon("test_01"))  
89 -# runner.run(current_suite)  
90 \ No newline at end of file 107 \ No newline at end of file
  108 + runner = unittest.TextTestRunner()
  109 +## runner.run(可以直接添加测试用例如submitOrder_With_Coupon("test_01"))
  110 + runner.run(current_suite)
91 \ No newline at end of file 111 \ No newline at end of file
src/testcase/test_tms_myrequest/test_upStream2.py 0 → 100644
  1 +#!/usr/bin/python
  2 +# -*- coding: UTF-8 -*-
  3 +import unittest
  4 +import json
  5 +import urllib3
  6 +from commons import ConfigDB as db
  7 +from commons import common as com
  8 +from commons.api.login import login
  9 +from commons.api.upStream import upStream
  10 +from commons.MyRequest import myrequest
  11 +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
  12 +ll=login()
  13 +uu=upStream()
  14 +my=myrequest()
  15 +
  16 +#列表查询
  17 +class test_upStream2(unittest.TestCase):
  18 +
  19 + @classmethod
  20 + def setUpClass(cls):
  21 + #新增登记单
  22 + cls.se=ll.get_session2("user01")
  23 +
  24 + def setUp(self):
  25 + pass
  26 +
  27 + def test_01_upStream(self):
  28 + #成功查询上下游企业,无过滤条件---直接调用登陆类的方法,session可以保持一致
  29 + #直接把接口和数据一起封装,测试时直接调用接口数据(请求数据没有修改的情况)
  30 + re=self.se.post(url=uu.url,headers=uu.header,json=uu.body)
  31 + print(re.json())
  32 + self.assertEqual(re.status_code, 200)
  33 +
  34 + def test_02_upStream(self):
  35 + #成功查询上下游企业,加入企业/个人名称过滤条件----直接调用登陆类的方法,session可以保持一致
  36 + #直接把接口和数据一起封装,测试时直接调用接口数据(需要修改请求数据的情况)
  37 + body=uu.body.copy()
  38 + body["likeName"]="111"
  39 + print("test_02_upStream",body)
  40 + re=self.se.post(url=uu.url,headers=uu.header,json=uu.body)
  41 + print(re.json())
  42 + self.assertEqual(re.status_code, 200)
  43 +
  44 + def test_03_upStream(self):
  45 + #成功查询上下游企业,加入业户名称名称过滤条件---实验直接传session给接口类使用(封装使用)
  46 + re=uu.post2(self.se,"sg_wenze", "111111",url=uu.url,headers=uu.header,json=uu.body)
  47 + print("test_03_upStream",re.json())
  48 + print(re.json())
  49 + self.assertEqual(re.status_code, 200)
  50 +
  51 + def test_04_upStream(self):
  52 + #成功查询上下游企业,加入业户名称名称过滤条件
  53 + #使用公共的请求方法,数据需要单独维护
  54 + re=my.post2(self.se,"test_01_upStream")
  55 + print("test_04_upStream",re.json())
  56 + self.assertEqual(re.status_code, 200)
  57 +
  58 + def tearDown(self):
  59 + print("tearDown")
  60 +
  61 + @classmethod
  62 + def tearDownClass(cls):
  63 + cls.se.close()
  64 +
  65 +
  66 +if __name__ == "__main__":
  67 +#unittest.main()方法会搜索该模块文件下所有以test开头的测试用例方法,并自动执行它们。
  68 +#如果不加下面这个语句,那么在通过unittest的方法添加测试用例时,这个文件里面的用例不会被搜索到。
  69 +
  70 +# unittest.main(verbosity=2)
  71 +
  72 +# # 以下代码可以调试单个测试用例,用例中打印的语句不会展示到控制台,使用前需要注释上面的代码unittest.main(),如果不使用下面代码,
  73 +# # 在有unittest.main()的情况下点击ctrl+f11,会直接运行当前页面所有用例,并且把用例用有打印的语句显示到控制台
  74 + current_suite = unittest.TestSuite()
  75 + current_suite.addTest(test_upStream2("test_01_upStream"))
  76 +# #以列表形式添加多个测试用例
  77 +# # current_suite.addTests([submitOrder_With_Coupon("test_01"),submitOrder_With_Coupon("test_02")])
  78 +# # 执行测试
  79 + runner = unittest.TextTestRunner()
  80 +## runner.run(可以直接添加测试用例如submitOrder_With_Coupon("test_01"))
  81 + runner.run(current_suite)
0 \ No newline at end of file 82 \ No newline at end of file
src/testcase/test_tms_myrequest/test_upStream3.py 0 → 100644
  1 +#!/usr/bin/python
  2 +# -*- coding: UTF-8 -*-
  3 +import unittest
  4 +import json
  5 +import urllib3
  6 +from commons import ConfigDB as db
  7 +from commons import common as com
  8 +from commons.api.login import login
  9 +from commons.api.upStream import upStream
  10 +from commons.MyRequest import myrequest
  11 +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
  12 +ll=login()
  13 +uu=upStream()
  14 +my=myrequest()
  15 +
  16 +class test_upStream3(unittest.TestCase):
  17 + '''每个接口都单独提供一个登录方法'''
  18 +
  19 + @classmethod
  20 + def setUpClass(cls):
  21 + pass
  22 + def setUp(self):
  23 + pass
  24 +
  25 + def test_01_upStream(self):
  26 + #成功查询上下游企业,加入企业/个人名称过滤条件----直接调用自己类的方法,session和其他用了可以不一致
  27 + #直接把接口和数据一起封装,测试时直接调用接口数据(需要修改请求数据的情况)
  28 + body=uu.body.copy()
  29 + body["likeName"]="111"
  30 + re=uu.post("sg_wenze", "111111",url=uu.url,headers=uu.header,json=body)
  31 + print(re.json())
  32 + self.assertEqual(re.status_code, 200)
  33 +
  34 + def test_02_upStream(self):
  35 + #成功查询上下游企业,加入业户名称名称过滤条件----直接调用自己类的方法,session和其他用了可以不一致
  36 + body=uu.body.copy()
  37 + body["likeUserName"]="地利人和"
  38 + re=uu.post("sg_wenze", "111111",url=uu.url,headers=uu.header,json=body)
  39 + print(re.json())
  40 + self.assertEqual(re.status_code, 200)
  41 +
  42 + def tearDown(self):
  43 + pass
  44 + @classmethod
  45 + def tearDownClass(cls):
  46 + pass
  47 +
  48 +
  49 +
  50 +if __name__ == "__main__":
  51 +#unittest.main()方法会搜索该模块文件下所有以test开头的测试用例方法,并自动执行它们。
  52 +#如果不加下面这个语句,那么在通过unittest的方法添加测试用例时,这个文件里面的用例不会被搜索到。
  53 +
  54 +# unittest.main(verbosity=2)
  55 +
  56 +# # 以下代码可以调试单个测试用例,用例中打印的语句不会展示到控制台,使用前需要注释上面的代码unittest.main(),如果不使用下面代码,
  57 +# # 在有unittest.main()的情况下点击ctrl+f11,会直接运行当前页面所有用例,并且把用例用有打印的语句显示到控制台
  58 + current_suite = unittest.TestSuite()
  59 + current_suite.addTest(test_upStream3("test_08_upStream"))
  60 +# #以列表形式添加多个测试用例
  61 +# # current_suite.addTests([submitOrder_With_Coupon("test_01"),submitOrder_With_Coupon("test_02")])
  62 +# # 执行测试
  63 + runner = unittest.TextTestRunner()
  64 +## runner.run(可以直接添加测试用例如submitOrder_With_Coupon("test_01"))
  65 + runner.run(current_suite)
0 \ No newline at end of file 66 \ No newline at end of file