Commit 8c43a9dc294b929284bfa0fc724feeafa68fb1dc

Authored by 175930106
Committed by liujiqiang
1 parent 3c333a76

将testcase和common-api的文件冗余注释和代码删除:每个testcase都预留了一个unittest用例加载代码,每个api类都预留一个请求调试代码。

src/commons/api/__pycache__/doAdd.cpython-36.pyc
No preview for this file type
src/commons/api/__pycache__/doAudit.cpython-36.pyc
No preview for this file type
src/commons/api/__pycache__/fieldConfig.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/doAdd.py
... ... @@ -40,6 +40,6 @@ class doAdd():
40 40  
41 41  
42 42  
43   -tt=doAdd()
44   -tt.post("user01",url=tt.url,headers=tt.header,json=tt.body,proxies={'http': 'http://localhost:8888'})
45   -
  43 +# tt=doAdd()
  44 +# re=tt.post("user01",url=tt.url,headers=tt.header,json=tt.body,proxies={'http': 'http://localhost:8888'})
  45 +# print(re.json())
... ...
src/commons/api/doAudit.py
... ... @@ -35,5 +35,6 @@ class doAudit():
35 35  
36 36  
37 37  
38   -tt=doAudit()
39   -# tt.get("user01",url=tt.url,headers=tt.header,proxies={'http': 'http://localhost:8888'})
  38 +# tt=doAudit()
  39 +# re=tt.get("user01",url=tt.url,headers=tt.header,proxies={'http': 'http://localhost:8888'})
  40 +# print(re.json())
40 41 \ No newline at end of file
... ...
src/commons/api/fieldConfig.py
... ... @@ -40,5 +40,5 @@ class fieldConfig(login):
40 40  
41 41  
42 42 # tt=fieldConfig()
43   -#
44   -# tt.post("user01",url=tt.url,headers=tt.header,json=tt.body,proxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'})
  43 +# re=tt.post("user01",url=tt.url,headers=tt.header,json=tt.body,proxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'})
  44 +# print(re.json())
45 45 \ No newline at end of file
... ...
src/commons/api/login.py
... ... @@ -3,6 +3,8 @@
3 3 import requests
4 4 import json
5 5 from commons import common as com
  6 +from commons.Logging import Logger
  7 +log=Logger()
6 8  
7 9 class login():
8 10 url="http://test.uap.diligrp.com/login/login.action"
... ... @@ -28,6 +30,15 @@ class login():
28 30 self.header=login.header
29 31 self.body=login.body
30 32  
  33 + def post(self,name,password,**kwargs):
  34 + #为登录接口单独写的一个POST请求方法;
  35 + #参数话账户和密码,通过再业务代码中传递不同的账户和密码,实现测试的不同场景
  36 + self.body=self.body.replace("sg_wenze", name)
  37 + self.body=self.body.replace("111111", password)
  38 + re=requests.post(url=self.url, headers=self.header,data=self.body,allow_redirects=False,**kwargs)
  39 + #返回请求对象,供断言使用
  40 + return re
  41 +
31 42 def get_session(self,account,**kwargs):
32 43 #如下代码,可以通过配置文件来控制登录的账户
33 44 self.body=self.body.replace("sg_wenze", com.get_global_config("global_data", "account", account).split("&")[0])
... ... @@ -44,17 +55,13 @@ class login():
44 55 #关闭session,释放缓存
45 56 self.se.close()
46 57  
47   - def post(self,name,password,**kwargs):
48   - #为登录接口单独写的一个POST请求方法;
49   - #参数话账户和密码,通过再业务代码中传递不同的账户和密码,实现测试的不同场景
50   - self.body=self.body.replace("sg_wenze", name)
51   - self.body=self.body.replace("111111", password)
52   - re=requests.post(url=self.url, headers=self.header,data=self.body,allow_redirects=False,**kwargs)
53   - #返回请求对象,供断言使用
54   - return re
55   -
56 58  
57 59 # t=login()
58   -# t.get_session2("user01",proxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'},allow_redirects=False)
59   -
  60 +# re=t.post("sg_wenze", "111111",proxies={'http': 'http://localhost:8888'})
  61 +# print(re.headers)
60 62  
  63 +# log.info(re.headers)
  64 +# log.info(re.cookies)
  65 +# log.info(t.body)
  66 +# log.info(t.header)
  67 +# t.get_session("user01",proxies={'http': 'http://localhost:8888'},allow_redirects=False)
61 68 \ No newline at end of file
... ...
src/commons/api/upStream.py
... ... @@ -42,26 +42,5 @@ class upStream():
42 42  
43 43  
44 44 # tt=upStream()
45   -# print(tt.url)
46   -# print(id(tt.body))
47   -# print(id(upStream.body))
48   -# tt.body["order"]=111
49   -# print(tt.body)
50   -# print(upStream.body)
51   -# print(id(tt.body))
52   -# print(id(upStream.body))
53   -# #深拷贝
54   -# t1=tt.body.copy()
55   -# print(id(t1))
56   -# print(id(tt.body))
57   -# t1["rows"]="666"
58   -# print(id(t1))
59   -# print(id(tt.body))
60   -# print(t1)
61   -# print(tt.body)
62   -
63   -# tt.post("sg_wenze", "111111",url=tt.url,headers=tt.header,json=tt.body,proxies={'http': 'http://localhost:8888'})
64   -
65   -# # print(tt.class_var)
66   -# # print(tt.login_url)
67   -# tt.demo("sg_wenze", "111111",proxies={'http': 'http://localhost:8888'})
  45 +# re=tt.post("user01",url=tt.url,headers=tt.header,json=tt.body,proxies={'http': 'http://localhost:8888'})
  46 +# print(re.json())
68 47 \ No newline at end of file
... ...
src/testcase/doAdd/test_doAdd.py
... ... @@ -11,48 +11,50 @@ ll=login()
11 11 do=doAdd()
12 12 field=fieldConfig()
13 13  
14   -#列表查询
  14 +#新增登记接口
15 15 class test_doAdd(unittest.TestCase):
16 16  
17 17 @classmethod
18 18 def setUpClass(cls):
19   - #获取session
  19 + #通过登录接口获取session
20 20 cls.se=ll.get_session("user01",allow_redirects=False)
21   - #提前配置新增页的字段配置
  21 + #通过字段配置接口提前配置新增页的字段配置
22 22 field.post("user01",url=field.url,headers=field.header,json=field.body)
23   -
24   - def setUp(self):
25   - pass
26 23  
27 24 def test_01_doAdd(self):
28 25 #成功新增一个商品为大白菜的报备单,重量为111
  26 + #请求数据不需要修改,直接POST请求
29 27 re=self.se.post(url=do.url,headers=do.header,json=do.body,proxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'})
30 28 print(re.json())
  29 + #响应断言
31 30 self.assertEqual(re.status_code, 200)
32 31 self.assertTrue("'code':'200'" in str(re.json()).replace(" ",""))
33 32  
34 33 def test_02_doAdd(self):
35 34 #成功新增一个商品为鲜花生的报备单,重量为111
  35 + #请求数据需要修改
36 36 body=do.body.copy()
37 37 body["productName"]="鲜花生"
38 38 body["productId"]="3496"
  39 + body["weight"]="666"
  40 + #POST请求
39 41 re=self.se.post(url=do.url,headers=do.header,json=body,proxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'})
40 42 print(re.json())
  43 + #响应断言
41 44 self.assertEqual(re.status_code, 200)
42 45 self.assertTrue("'code':'200'" in str(re.json()).replace(" ",""))
43 46  
44 47 def test_03_doAdd(self):
45 48 #用错误的用户来新增,无法新增
  49 + #请求数据需要修改
46 50 body=do.body.copy()
47 51 body["userId"]="516111"
  52 + #POST请求
48 53 re=self.se.post(url=do.url,headers=do.header,json=body,proxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'})
49 54 print(re.json())
  55 + #响应断言
50 56 self.assertEqual(re.status_code, 200)
51 57 self.assertTrue("查询客户信息失败" in str(re.json()).replace(" ",""))
52   -
53   -
54   - def tearDown(self):
55   - pass
56 58  
57 59 @classmethod
58 60 def tearDownClass(cls):
... ... @@ -61,18 +63,9 @@ class test_doAdd(unittest.TestCase):
61 63  
62 64  
63 65 if __name__ == "__main__":
64   -#unittest.main()方法会搜索该模块文件下所有以test开头的测试用例方法,并自动执行它们。
65   -#如果不加下面这个语句,那么在通过unittest的方法添加测试用例时,这个文件里面的用例不会被搜索到。
66   -
67   -# unittest.main(verbosity=2)
  66 + unittest.main(verbosity=2)
68 67  
69   -# # 以下代码可以调试单个测试用例,用例中打印的语句不会展示到控制台,使用前需要注释上面的代码unittest.main(),如果不使用下面代码,
70   -# # 在有unittest.main()的情况下点击ctrl+f11,会直接运行当前页面所有用例,并且把用例用有打印的语句显示到控制台
71   - current_suite = unittest.TestSuite()
72   - current_suite.addTest(test_doAdd("test_03_doAdd"))
73   -# #以列表形式添加多个测试用例
74   -# # current_suite.addTests([submitOrder_With_Coupon("test_01"),submitOrder_With_Coupon("test_02")])
75   -# # 执行测试
76   - runner = unittest.TextTestRunner()
77   -## runner.run(可以直接添加测试用例如submitOrder_With_Coupon("test_01"))
78   - runner.run(current_suite)
79 68 \ No newline at end of file
  69 +# current_suite = unittest.TestSuite()
  70 +# current_suite.addTest(test_doAdd("test_03_doAdd"))
  71 +# runner = unittest.TextTestRunner()
  72 +# runner.run(current_suite)
80 73 \ No newline at end of file
... ...
src/testcase/doAudit/test_doAudit.py
1 1 #!/usr/bin/python
2 2 # -*- coding: UTF-8 -*-
3   -#Python自带模块,直接import就行
4 3 import unittest
5 4 import json
6 5 import urllib3
... ... @@ -25,9 +24,9 @@ class test_doAudit(unittest.TestCase):
25 24  
26 25 @classmethod
27 26 def setUpClass(cls):
28   - #获取session
  27 + #通过登录接口获取session
29 28 cls.se=lo.get_session("user01",allow_redirects=False)
30   - #提前配置新增页的字段配置
  29 + #通过字段配置接口提前配置新增页的字段配置
31 30 cls.se.post(url=field.url,headers=field.header,json=field.body,proxies={'http': 'http://localhost:8888'})
32 31  
33 32 def setUp(self):
... ... @@ -82,9 +81,6 @@ class test_doAudit(unittest.TestCase):
82 81 self.assertEqual(re.status_code, 200)
83 82 #断言响应数据中是否存在期望字符串
84 83 self.assertTrue("'result':'操作失败,数据状态已改变'" in str(re.json()).replace(" ",""))
85   -
86   - def tearDown(self):
87   - pass
88 84  
89 85 @classmethod
90 86 def tearDownClass(cls):
... ... @@ -93,18 +89,10 @@ class test_doAudit(unittest.TestCase):
93 89  
94 90  
95 91 if __name__ == "__main__":
96   -#unittest.main()方法会搜索该模块文件下所有以test开头的测试用例方法,并自动执行它们。
97   -#如果不加下面这个语句,那么在通过unittest的方法添加测试用例时,这个文件里面的用例不会被搜索到。
98 92  
99 93 unittest.main(verbosity=2)
100 94  
101   -# # 以下代码可以调试单个测试用例,用例中打印的语句不会展示到控制台,使用前需要注释上面的代码unittest.main(),如果不使用下面代码,
102   -# # 在有unittest.main()的情况下点击ctrl+f11,会直接运行当前页面所有用例,并且把用例用有打印的语句显示到控制台
103 95 # current_suite = unittest.TestSuite()
104 96 # current_suite.addTest(test_doAudit("test_01_doAudit"))
105   -# # #以列表形式添加多个测试用例
106   -# # # current_suite.addTests([submitOrder_With_Coupon("test_01"),submitOrder_With_Coupon("test_02")])
107   -# # # 执行测试
108 97 # runner = unittest.TextTestRunner()
109   -# ## runner.run(可以直接添加测试用例如submitOrder_With_Coupon("test_01"))
110 98 # runner.run(current_suite)
111 99 \ No newline at end of file
... ...
src/testcase/fieldConfig/test_fieldConfig.py
... ... @@ -2,11 +2,8 @@
2 2 # -*- coding: UTF-8 -*-
3 3 import unittest
4 4 import json
5   -import urllib3
6   -from testcase.login import test_login
7   -urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
8   -
9 5  
  6 +###############################Unittest用例结构的简单的认识################################
10 7 class test_fieldConfig(unittest.TestCase):
11 8  
12 9 @classmethod
... ... @@ -47,7 +44,6 @@ class test_fieldConfig(unittest.TestCase):
47 44  
48 45 if __name__ == "__main__":
49 46 #上述函数为引导执行代码,当模块被直接运行时,以下代码块将被运行,当模块是被导入时,代码块不被运行
50   -
51 47 unittest.main(verbosity=2)
52 48 #unittest.main()为运行的入口/初始化函数,方法会搜索该模块文件下所有以test开头的测试用例方法,并自动执行它们。
53 49 # verbosity是一个选项,表示测试结果的信息复杂度,有0、1、2 三个值
... ...
src/testcase/login/test_login.py
... ... @@ -7,60 +7,36 @@ from commons.api.login import login
7 7 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
8 8 lo=login()
9 9  
  10 +#登录接口demo
10 11 class test_login(unittest.TestCase):
11   -
12   - @classmethod
13   - def setUpClass(cls):
14   - #初始化工作:该类的所有用例执行前会执行一次,且只执行一次,优先级高于setup,非必要代码
15   - print("setUpClass")
16   -
17   - def setUp(self):
18   - #初始化工作:每个用例执行前都会执行一次,N个用例就执行N次,非必要代码
19   - print("setUp")
20 12  
21 13 def test_01_login(self):
22 14 #账户密码都正确
  15 + #进行POST请求
23 16 re=lo.post("sg_wenze", "111111")
24   -# print(re.headers)
  17 + #print(re.headers)
  18 + #断言响应
25 19 self.assertTrue("Set-Cookie" in re.headers.keys())
26 20  
27 21 def test_02_login(self):
28 22 #密码错误
  23 + #进行POST请求
29 24 re=lo.post("sg_wenze", "111111111111")
30   -# print(re.text)
  25 + #print(re.text)
  26 + #断言响应
31 27 self.assertTrue("用户名或密码错误" in re.text)
32 28  
33 29 def test_03_login(self):
34 30 #账户错误
  31 + #进行POST请求
35 32 re=lo.post("sg_wenze11111111", "11111")
36   -# print(re.text)
  33 + #print(re.text)
  34 + #断言响应
37 35 self.assertTrue("用户名或密码错误" in re.text)
38 36  
39   -
40   - def tearDown(self):
41   - #清理工作:每个用例执行后都会执行一次,N个用例就执行N次,非必要代码
42   - print("tearDown:")
43   -
44   - @classmethod
45   - def tearDownClass(cls):
46   - #清理工作:该类的所有用例执行完成后会执行一次,且只执行一次,非必要代码
47   - print("tearDownClass")
48   -
49 37  
50 38 if __name__ == "__main__":
51   -#unittest.main()方法会搜索该模块文件下所有以test开头的测试用例方法,并自动执行它们。
52   -#如果不加下面这个语句,那么在通过unittest的方法添加测试用例时,这个文件里面的用例不会被搜索到。
53 39  
54 40 unittest.main(verbosity=2)
55 41  
56   -# # 以下代码可以调试单个测试用例,用例中打印的语句不会展示到控制台,使用前需要注释上面的代码unittest.main(),如果不使用下面代码,
57   -# # 在有unittest.main()的情况下点击ctrl+f11,会直接运行当前页面所有用例,并且把用例用有打印的语句显示到控制台
58   -# current_suite = unittest.TestSuite()
59   -# current_suite.addTest(test_upStream("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)
66 42  
... ...
src/testcase/upStream/test_upStream.py
... ... @@ -9,36 +9,35 @@ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
9 9 ll=login()
10 10 uu=upStream()
11 11  
12   -#列表查询
  12 +#上游企业列表查询接口
13 13 class test_upStream1(unittest.TestCase):
14 14  
15 15 @classmethod
16 16 def setUpClass(cls):
17   - #新增登记单
  17 + #通过登录接口获取session
18 18 cls.se=ll.get_session("user01",allow_redirects=False)
19 19  
20   - def setUp(self):
21   - pass
22   -
23 20 def test_01_upStream1(self):
24 21 #成功查询上下游企业,无过滤条件
  22 + #请求数据不需要修改,直接POST请求
25 23 re=self.se.post(url=uu.url,headers=uu.header,json=uu.body,proxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'})
26 24 print(re.json())
  25 + #响应断言
27 26 self.assertEqual(re.status_code, 200)
28 27 self.assertTrue("total" in re.json().keys())
29 28 self.assertTrue("上游" in str(re.json()).replace(" ",""))
30 29  
31 30 def test_02_upStream1(self):
32 31 #成功查询上下游企业,加入企业/个人名称过滤条件
  32 + #请求数据需要修改
33 33 body=uu.body.copy()
34 34 body["likeName"]="111"
  35 + #POST请求
35 36 re=self.se.post(url=uu.url,headers=uu.header,json=body,proxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'})
36 37 print(re.json())
  38 + #响应断言
37 39 self.assertEqual(re.status_code, 200)
38 40 self.assertTrue("legalPerson':'哈哈哈'" in str(re.json()).replace(" ",""))
39   -
40   - def tearDown(self):
41   - pass
42 41  
43 42 @classmethod
44 43 def tearDownClass(cls):
... ... @@ -49,10 +48,13 @@ class test_upStream2(unittest.TestCase):
49 48  
50 49 def test_01_upStream2(self):
51 50 #成功查询上下游企业,加入企业/个人名称过滤条件
  51 + #请求数据需要修改
52 52 body=uu.body.copy()
53 53 body["likeName"]="111"
  54 + #POST请求
54 55 re=uu.post("user01",url=uu.url,headers=uu.header,json=body)
55 56 print(re.json())
  57 + #响应断言
56 58 self.assertEqual(re.status_code, 200)
57 59 self.assertTrue("legalPerson':'哈哈哈'" in str(re.json()).replace(" ",""))
58 60  
... ... @@ -60,25 +62,18 @@ class test_upStream2(unittest.TestCase):
60 62 #成功查询上下游企业,加入业户名称名称过滤条件
61 63 body=uu.body.copy()
62 64 body["likeUserName"]="地利人和"
  65 + #POST请求
63 66 re=uu.post("user01",url=uu.url,headers=uu.header,json=body)
64 67 print(re.json())
  68 + #响应断言
65 69 self.assertEqual(re.status_code, 200)
66 70 self.assertTrue("userNames':'地利人和'" in str(re.json()).replace(" ",""))
67 71  
68 72  
69 73 if __name__ == "__main__":
70   -#unittest.main()方法会搜索该模块文件下所有以test开头的测试用例方法,并自动执行它们。
71   -#如果不加下面这个语句,那么在通过unittest的方法添加测试用例时,这个文件里面的用例不会被搜索到。
72   -
73   -# unittest.main(verbosity=2)
  74 + unittest.main(verbosity=2)
74 75  
75   -# # 以下代码可以调试单个测试用例,用例中打印的语句不会展示到控制台,使用前需要注释上面的代码unittest.main(),如果不使用下面代码,
76   -# # 在有unittest.main()的情况下点击ctrl+f11,会直接运行当前页面所有用例,并且把用例用有打印的语句显示到控制台
77   - current_suite = unittest.TestSuite()
78   - current_suite.addTest(test_upStream1("test_01_upStream1"))
79   -# #以列表形式添加多个测试用例
80   -# # current_suite.addTests([submitOrder_With_Coupon("test_01"),submitOrder_With_Coupon("test_02")])
81   -# # 执行测试
82   - runner = unittest.TextTestRunner()
83   -## runner.run(可以直接添加测试用例如submitOrder_With_Coupon("test_01"))
84   - runner.run(current_suite)
85 76 \ No newline at end of file
  77 +# current_suite = unittest.TestSuite()
  78 +# current_suite.addTest(test_upStream1("test_01_upStream1"))
  79 +# runner = unittest.TextTestRunner()
  80 +# runner.run(current_suite)
86 81 \ No newline at end of file
... ...