Commit 9b595b0e7a69ec39bfea6294ef4413ac89ce8289
Merge remote-tracking branch 'origin/master'
Showing
7 changed files
with
49 additions
and
31 deletions
commons/MySession.py
... | ... | @@ -7,7 +7,7 @@ from commons.clientSession import cliSession |
7 | 7 | from commons.scripts.pwdCry import pwdCry |
8 | 8 | log=Logger() |
9 | 9 | |
10 | -class mysession(): | |
10 | +class mysession(requests.Session): | |
11 | 11 | "封装了requests的基类,以供后期统一使用" |
12 | 12 | |
13 | 13 | url = "http://test.uap.diligrp.com/login/login.action" |
... | ... | @@ -38,6 +38,7 @@ class mysession(): |
38 | 38 | |
39 | 39 | def __init__(self): |
40 | 40 | "如下代码,可以通过配置文件来控制测试环境和灰度环境,http和https" |
41 | + super().__init__() | |
41 | 42 | self.url = mysession.url.replace("http://test.", com.get_global_config("global_data", "environment", "en")) |
42 | 43 | self.header = mysession.header |
43 | 44 | self.body = mysession.body |
... | ... | @@ -48,8 +49,8 @@ class mysession(): |
48 | 49 | self.max_retries = 3 |
49 | 50 | self.keep_alive = False |
50 | 51 | self.ssl_verify = False |
51 | - self.proxies = None | |
52 | - # self.proxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'} | |
52 | + # self.proxies = None | |
53 | + self.proxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'} | |
53 | 54 | self.myproxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'} |
54 | 55 | self.allow_redirects = False |
55 | 56 | self.firmid={"group":"1","hd":"2","cd":"3","qqhe":"4","mdj":"5","gy":"6","cc":"7","sg":"8","sy":"9"} |
... | ... | @@ -103,9 +104,8 @@ class mysession(): |
103 | 104 | self.body_client.update( {"password": pwdCry(com.get_global_config("global_data", "account", account).split("&")[1])}) |
104 | 105 | # requests.session()会话保持,比如使用session成功的登录了某个网站, |
105 | 106 | # 则在再次使用该session对象求求该网站的其他网页都会默认使用该session之前使用的cookie等参数 |
106 | - self.se = requests.session() | |
107 | 107 | # 使用session对象的方法POST/GET等 |
108 | - self.re = self.se.post(url=self.url_client, headers=self.header_client, json=self.body_client, proxies=self.proxies, **kwargs) | |
108 | + self.re = super().post(url=self.url_client, headers=self.header_client, json=self.body_client, **kwargs) | |
109 | 109 | #获取user信息供其他接口使用 |
110 | 110 | self.user[account]=self.re.json()["data"]["user"] |
111 | 111 | #组装请求的cookie |
... | ... | @@ -113,14 +113,13 @@ class mysession(): |
113 | 113 | co.set("UAP_firmId", str(self.re.json()["data"]["user"]["firmId"]),domain=".diligrp.com") |
114 | 114 | co.set("UAP_accessToken", self.re.json()["data"]["accessToken"],domain=".diligrp.com") |
115 | 115 | co.set("UAP_refreshToken", self.re.json()["data"]["refreshToken"],domain=".diligrp.com") |
116 | - self.se.cookies.update(co) | |
116 | + self.cookies.update(co) | |
117 | 117 | # 返回session对象,供其他接口使用 |
118 | - return self.se | |
119 | - | |
118 | + return self | |
120 | 119 | |
121 | 120 | def close_session(self): |
122 | 121 | "关闭session" |
123 | - self.se.close() | |
122 | + self.close() | |
124 | 123 | |
125 | 124 | def check_login(self, account, **kwargs): |
126 | 125 | "验证登录接口" |
... | ... | @@ -168,7 +167,7 @@ class mysession(): |
168 | 167 | log.info("{0:=^86}".format('')) |
169 | 168 | log.info("{}\n{}\n".format(url, kwargs)) |
170 | 169 | # 进行请求 |
171 | - re = self.se.request(method , url, **kwargs, proxies=self.proxies, timeout=self.timeout) | |
170 | + re = super().request(method , url, **kwargs, proxies=self.proxies,timeout=self.timeout) | |
172 | 171 | return re |
173 | 172 | |
174 | 173 | |
... | ... | @@ -183,7 +182,7 @@ class mysession(): |
183 | 182 | log.info("{0:=^86}".format('')) |
184 | 183 | log.info("{}\n{}\n".format(url, kwargs)) |
185 | 184 | # 进行请求 |
186 | - re = self.se.get(url, **kwargs, proxies=self.proxies, timeout=self.timeout) | |
185 | + re = super().get(url, **kwargs) | |
187 | 186 | return re |
188 | 187 | |
189 | 188 | def post(self, url, data=None, json=None, **kwargs): |
... | ... | @@ -199,7 +198,7 @@ class mysession(): |
199 | 198 | log.info("{0:=^86}".format('')) |
200 | 199 | log.info("{}\n{}\n{}\n{}".format(url, data, json, kwargs)) |
201 | 200 | # 进行请求 |
202 | - re = self.se.post(url, data=data, json=json, proxies=self.proxies, **kwargs, timeout=self.timeout) | |
201 | + re = super().post(url, data=data, json=json, **kwargs) | |
203 | 202 | return re |
204 | 203 | |
205 | 204 | def options(self, url, **kwargs): |
... | ... | @@ -284,9 +283,8 @@ class mysession(): |
284 | 283 | my = mysession() |
285 | 284 | my.set_mark() |
286 | 285 | my.cliLogin() |
287 | -sy1 = my.get_session_client("sy_user01") | |
288 | -sy2 = my.get_session_client("sy_user02") | |
289 | -# heb1 = my.get_session_client("heb_user01") | |
290 | -# gy1=my.get_session_client("gy_user01") | |
291 | -# sg1=my.get_session_client("sg_user01") | |
292 | -# hs1=my.get_session_client("hs_user01") | |
286 | +sy1=mysession().get_session_client("sy_user01") | |
287 | +sy2=mysession().get_session_client("sy_user02") | |
288 | +# sg=mysession().get_session_client("sg_user01") | |
289 | + | |
290 | + | ... | ... |
commons/api/weighingServiceSave.py
... | ... | @@ -58,5 +58,5 @@ class weighingServiceSave(): |
58 | 58 | |
59 | 59 | |
60 | 60 | # tt=weighingServiceSave(sy1) |
61 | -# re=sy1.post(url=tt.url,headers=tt.header,json=tt.body,proxies=my.myproxies) | |
61 | +# re=sy1.post(url=tt.url,headers=tt.header,json=tt.body) | |
62 | 62 | # print(re.json()) |
63 | 63 | \ No newline at end of file | ... | ... |
commons/api/weightBizBill_doRefund.py
... | ... | @@ -3,7 +3,6 @@ |
3 | 3 | import urllib3 |
4 | 4 | from commons import common as com |
5 | 5 | from commons.MySession import my,sy1 |
6 | -from commons.basic.duplicateToken import duplicateToken | |
7 | 6 | urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) |
8 | 7 | |
9 | 8 | |
... | ... | @@ -26,6 +25,6 @@ class weightBizBill_doRefund(): |
26 | 25 | |
27 | 26 | |
28 | 27 | |
29 | -# tt=weightBizBill_listPage() | |
30 | -# re=sy1.post(url=tt.url,headers=tt.header,json=tt.body,proxies=my.myproxies) | |
28 | +# tt=weightBizBill_doRefund() | |
29 | +# re=sy1.post(url=tt.url,headers=tt.header,json=tt.body) | |
31 | 30 | # print(re.json()) |
32 | 31 | \ No newline at end of file | ... | ... |
commons/api/weightBizBill_listPage.py
... | ... | @@ -3,7 +3,6 @@ |
3 | 3 | import urllib3 |
4 | 4 | from commons import common as com |
5 | 5 | from commons.MySession import my,sy1 |
6 | -from commons.basic.duplicateToken import duplicateToken | |
7 | 6 | urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) |
8 | 7 | |
9 | 8 | |
... | ... | @@ -34,5 +33,5 @@ class weightBizBill_listPage(): |
34 | 33 | |
35 | 34 | |
36 | 35 | # tt=weightBizBill_listPage() |
37 | -# re=sy1.post(url=tt.url,headers=tt.header,json=tt.body,proxies=my.myproxies) | |
36 | +# re=sy1.post(url=tt.url,headers=tt.header,data=tt.body) | |
38 | 37 | # print(re.json()) |
39 | 38 | \ No newline at end of file | ... | ... |
commons/basic/duplicateToken.py
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | # -*- coding: UTF-8 -*- |
3 | 3 | import urllib3 |
4 | 4 | from commons import common as com |
5 | -from commons.MySession import my,sy1,sy2 | |
5 | +from commons.MySession import my,sy1 | |
6 | 6 | urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) |
7 | 7 | |
8 | 8 | |
... | ... | @@ -31,5 +31,3 @@ class duplicateToken(): |
31 | 31 | |
32 | 32 | |
33 | 33 | # print(duplicateToken(sy1).jmsf_duplicate_commit_token()) |
34 | -# du=duplicateToken(sy1) | |
35 | -# print(du.jmsf_duplicate_commit_token()) | ... | ... |
commons/common.py
... | ... | @@ -83,11 +83,15 @@ def run_one(name): |
83 | 83 | runner = unittest.TextTestRunner() |
84 | 84 | runner.run(test_suite) |
85 | 85 | |
86 | + | |
86 | 87 | def run_list(name): |
87 | 88 | test_suite = unittest.TestSuite() |
88 | 89 | test_suite.addTests(name) |
89 | 90 | #显示运行用例 |
90 | 91 | print("运行用例为{}".format(test_suite)) |
92 | + # with open(file="E:\\PycharmWorkspace\\jmsf-re-local\\report\\test.log", mode="a", encoding="utf-8") as file: | |
93 | + # runner = unittest.TextTestRunner(stream=file,verbosity=2) | |
94 | + # runner.run(test_suite) | |
91 | 95 | runner = unittest.TextTestRunner() |
92 | 96 | runner.run(test_suite) |
93 | 97 | |
... | ... | @@ -112,4 +116,10 @@ def run_Name(name): |
112 | 116 | runner = unittest.TextTestRunner() |
113 | 117 | runner.run(test_cases) |
114 | 118 | |
115 | -# print(get_market_config("test_config_hg2","loginInfo","userName")) | |
116 | 119 | \ No newline at end of file |
120 | +def mylog(func): | |
121 | + def RebackTest(self): | |
122 | + print(func.__name__) | |
123 | + print(dir(func)) | |
124 | + # print(self) | |
125 | + return func(self) | |
126 | + return RebackTest | |
117 | 127 | \ No newline at end of file | ... | ... |
testcase/weightBizBill/test_weighingServiceSave.py
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | # -*- coding: UTF-8 -*- |
3 | 3 | import unittest |
4 | 4 | import urllib3 |
5 | +from commons import common as com | |
5 | 6 | from commons.MySession import my,sy1 |
6 | 7 | from commons.api.weighingServiceSave import weighingServiceSave |
7 | 8 | from commons.basic.listCarType import listCarType |
... | ... | @@ -10,10 +11,18 @@ we=weighingServiceSave(sy1) |
10 | 11 | li=listCarType(sy1) |
11 | 12 | |
12 | 13 | |
13 | - | |
14 | +@com.mylog | |
14 | 15 | class test_weighingServiceSave(unittest.TestCase): |
15 | 16 | "称重服务" |
16 | 17 | |
18 | + @classmethod | |
19 | + def setUpClass(cls): | |
20 | + pass | |
21 | + | |
22 | + | |
23 | + def setUp(self) : | |
24 | + pass | |
25 | + | |
17 | 26 | @unittest.case_mark(my.mark()) |
18 | 27 | def test_weighingServiceSave_01(self): |
19 | 28 | "称重服务:成功新增一条称重服务单" |
... | ... | @@ -26,9 +35,14 @@ class test_weighingServiceSave(unittest.TestCase): |
26 | 35 | self.assertEqual(re.status_code, 200) |
27 | 36 | self.assertTrue("'message':'交费成功','result':'交费成功','success':True" in str(re.json()).replace(" ","")) |
28 | 37 | |
38 | + @com.mylog | |
39 | + @unittest.case_mark(my.mark()) | |
40 | + def test_weighingServiceSave_02(self): | |
41 | + "称重服务:成功新增一条称重服务单" | |
42 | + print("11111111111111111111111111111111111") | |
29 | 43 | |
30 | 44 | if __name__ == "__main__": |
31 | 45 | |
32 | - unittest.main(verbosity=2) | |
46 | + # unittest.main(verbosity=2) | |
33 | 47 | |
34 | - # com.run_one(test_weighingServiceSave("test_weighingServiceSave_01")) | |
48 | + com.run_list([test_weighingServiceSave("test_weighingServiceSave_01"),test_weighingServiceSave("test_weighingServiceSave_02")]) | ... | ... |