Commit f2da266e908bd7a21a275bcf764eaab08704c0aa
1 parent
62fbebb0
更新部分方法和用例
Showing
7 changed files
with
108 additions
and
42 deletions
commons/MySession.py
1 | 1 | #!/usr/bin/python |
2 | 2 | # -*- coding: UTF-8 -*- |
3 | 3 | import requests |
4 | +import re | |
4 | 5 | from commons import common as com |
5 | 6 | from commons.Logging import log |
6 | 7 | from commons.clientSession import cliSession |
... | ... | @@ -36,9 +37,10 @@ class mysession(requests.Session): |
36 | 37 | body = "userName=sg_wenze&password=111111" |
37 | 38 | body_client= {"userName":"sg_wenze","password":"111111"} |
38 | 39 | |
39 | - def __init__(self): | |
40 | + def __init__(self,host=None): | |
40 | 41 | "如下代码,可以通过配置文件来控制测试环境和灰度环境,http和https" |
41 | 42 | super().__init__() |
43 | + self.user={} | |
42 | 44 | self.url = mysession.url.replace("http://test.", com.get_global_config("global_data", "environment", "en")) |
43 | 45 | self.header = mysession.header |
44 | 46 | self.body = mysession.body |
... | ... | @@ -55,36 +57,48 @@ class mysession(requests.Session): |
55 | 57 | self.allow_redirects = False |
56 | 58 | self.firmid={"group":"1","hd":"2","cd":"3","qqhe":"4","mdj":"5","gy":"6","cc":"7","sg":"8","sy":"9"} |
57 | 59 | self.market={"sy":"沈阳","heb":"哈尔滨","sg":"寿光","gy":"贵阳","cc":"长春","hs":"杭水","hg":"杭果"} |
58 | - self.user={} | |
60 | + self.host= None if host==None else eval(com.get_global_config("global_data", "host_ip", host)) | |
61 | + | |
59 | 62 | |
60 | 63 | def cliLogin(self,user="sy_userName_01"): |
61 | 64 | self.webHeaders, self.clientHeaders, self.userInfo = cliSession().loginUser(user=user) |
62 | 65 | return self |
63 | 66 | |
64 | - def get_session(self, account, **kwargs): | |
65 | - "如下代码,可以通过配置文件来控制登录的账户session" | |
66 | - self.body = self.body.replace("sg_wenze", | |
67 | - com.get_global_config("global_data", "account", account).split("&")[0]) | |
68 | - self.body = self.body.replace("111111", | |
69 | - com.get_global_config("global_data", "account", account).split("&")[1]) | |
70 | - self.se = requests.session() | |
71 | - co = requests.cookies.RequestsCookieJar() | |
72 | - #加入UAP_firmId属性 | |
73 | - firm=account.split("_")[0] | |
74 | - co.set("UAP_firmId", self.firmid[firm]) | |
75 | - self.se.cookies.update(co) | |
76 | - # 进行登录请求 | |
77 | - re = self.se.post(url=self.url, headers=self.header, data=self.body, proxies=self.proxies, **kwargs) | |
78 | - self.UAP_accessToken=self.se.cookies["UAP_accessToken"] | |
79 | - self.UAP_refreshToken=self.se.cookies["UAP_refreshToken"] | |
80 | - return self.se | |
67 | + # def get_session(self, account, **kwargs): | |
68 | + # "如下代码,可以通过配置文件来控制登录的账户session" | |
69 | + # self.body = self.body.replace("sg_wenze", | |
70 | + # com.get_global_config("global_data", "account", account).split("&")[0]) | |
71 | + # self.body = self.body.replace("111111", | |
72 | + # com.get_global_config("global_data", "account", account).split("&")[1]) | |
73 | + # self.se = requests.session() | |
74 | + # co = requests.cookies.RequestsCookieJar() | |
75 | + # #加入UAP_firmId属性 | |
76 | + # firm=account.split("_")[0] | |
77 | + # co.set("UAP_firmId", self.firmid[firm]) | |
78 | + # self.se.cookies.update(co) | |
79 | + # # 进行登录请求 | |
80 | + # re = self.se.post(url=self.url, headers=self.header, data=self.body, proxies=self.proxies, **kwargs) | |
81 | + # self.UAP_accessToken=self.se.cookies["UAP_accessToken"] | |
82 | + # self.UAP_refreshToken=self.se.cookies["UAP_refreshToken"] | |
83 | + # return self.se | |
84 | + # | |
85 | + # def get_login_info(self, account, **kwargs): | |
86 | + # "用于获取用户信息" | |
87 | + # self.body_client.update({"userName":com.get_global_config("global_data", "account", account).split("&")[0]}) | |
88 | + # self.body_client.update({"password":pwdCry(com.get_global_config("global_data", "account", account).split("&")[1])}) | |
89 | + # tmp = requests.post(url=self.url_client, headers=self.header_client, json=self.body_client, proxies=self.proxies, **kwargs) | |
90 | + # return tmp | |
81 | 91 | |
82 | - def get_login_info(self, account, **kwargs): | |
83 | - "用于获取用户信息" | |
84 | - self.body_client.update({"userName":com.get_global_config("global_data", "account", account).split("&")[0]}) | |
85 | - self.body_client.update({"password":pwdCry(com.get_global_config("global_data", "account", account).split("&")[1])}) | |
86 | - tmp = requests.post(url=self.url_client, headers=self.header_client, json=self.body_client, proxies=self.proxies, **kwargs) | |
87 | - return tmp | |
92 | + def url_pro(self, url, host): | |
93 | + # url = url.replace(" ", "") | |
94 | + if host!=None: | |
95 | + if "http:" in url: | |
96 | + d1 = re.match(r"http://(.+?)/", url).group(1).split(":")[0] | |
97 | + url = re.sub(r"http://(.+?)/", r"http://" + host[d1] + "/", url) | |
98 | + elif "https:" in url: | |
99 | + d1 = re.match(r"https://(.+?)/", url).group(1).split(":")[0] | |
100 | + url = re.sub(r"https://(.+?)/", r"https://" + host[d1] + "/", url) | |
101 | + return url | |
88 | 102 | |
89 | 103 | def get_session_client(self, account, **kwargs): |
90 | 104 | "get_session和get_session_client的方法只能用一个" |
... | ... | @@ -151,6 +165,8 @@ class mysession(requests.Session): |
151 | 165 | """ |
152 | 166 | # 记录日志 |
153 | 167 | log.info("{0:=^86}".format('')) |
168 | + log.info(url) | |
169 | + url=self.url_pro(url,self.host) | |
154 | 170 | log.info("{}\n{}\n".format(url, kwargs)) |
155 | 171 | # 进行请求 |
156 | 172 | re = super().request(method , url, **kwargs,timeout=self.timeout) |
... | ... | @@ -262,15 +278,15 @@ class mysession(requests.Session): |
262 | 278 | |
263 | 279 | my = mysession() |
264 | 280 | my.set_mark() |
265 | - | |
266 | 281 | # 沈阳客户端session |
267 | 282 | sessionSy = mysession().cliLogin("sy_userName_01") |
268 | 283 | # 哈尔滨客户端session |
269 | 284 | sessionHeb = mysession().cliLogin("hd_userName_01") |
270 | -# print(sessionSy.userInfo) | |
271 | -# print(sessionHeb.userInfo) | |
272 | - | |
273 | -sy1=mysession().get_session_client("sy_user01") | |
274 | -heb=mysession().get_session_client("heb_user01") | |
275 | -# sg=mysession().get_session_client("sg_user01") | |
276 | - | |
285 | +#获取对应市场session | |
286 | +sy1=mysession("host1").get_session_client("sy_user01") | |
287 | +heb=mysession("host1").get_session_client("heb_user01") | |
288 | +hg=mysession("host2").get_session_client("hg_user01") | |
289 | +# 检测登录接口 | |
290 | +sy1.check_login("sy_user01") | |
291 | +# 检测登录接口 | |
292 | +hg.check_login("hg_user01") | |
277 | 293 | \ No newline at end of file | ... | ... |
commons/api/entranceFeeBill_details.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 sy1,heb | |
5 | +from commons.MySession import sy1 | |
6 | 6 | urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) |
7 | 7 | |
8 | 8 | |
... | ... | @@ -16,6 +16,7 @@ class entranceFeeBill_details(): |
16 | 16 | "User-Agent": "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36", |
17 | 17 | "Content-Type": "application/json", |
18 | 18 | "Accept-Language": "zh-CN,zh;q=0.9", |
19 | + "Host": "test.jmsf.diligrp.com:8385", | |
19 | 20 | "Accept-Encoding": "gzip, deflate"} |
20 | 21 | url_tail = """?rows=10&page=1 |
21 | 22 | &metadata[charge_total_amount]={"provider":"moneyProvider","index":10,"field":"charge_total_amount"} |
... | ... | @@ -76,5 +77,5 @@ class entranceFeeBill_details(): |
76 | 77 | return self.sql |
77 | 78 | |
78 | 79 | # tt=entranceFeeBill_details() |
79 | -# re=sy1.get(url=tt.url,headers=tt.header) | |
80 | +# re=sy1.get(url=tt.url,headers=tt.header,proxies=sy1.myproxies) | |
80 | 81 | # print(str(re.json()).replace(" ","")) |
81 | 82 | \ No newline at end of file | ... | ... |
commons/api/entranceFeeBill_provesPage.py
... | ... | @@ -17,6 +17,7 @@ class entranceFeeBill_provesPage(): |
17 | 17 | "User-Agent": "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36", |
18 | 18 | "Content-Type": "application/x-www-form-urlencoded", |
19 | 19 | "Accept-Language": "zh-CN,zh;q=0.9", |
20 | + "Host": "test.jmsf.diligrp.com:8385", | |
20 | 21 | "Accept-Encoding": "gzip, deflate"} |
21 | 22 | body = """rows=10&page=1&sort=et.created&order=desc |
22 | 23 | &metadata[actualPrice]={"provider":"moneyProvider","index":10,"field":"actualPrice"} | ... | ... |
commons/api/weightBizBill_doRefund.py
... | ... | @@ -16,6 +16,7 @@ class weightBizBill_doRefund(): |
16 | 16 | "User-Agent": "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36", |
17 | 17 | "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", |
18 | 18 | "Accept-Language": "zh-CN,zh;q=0.9", |
19 | + "Host": "test.jmsf.diligrp.com:8385", | |
19 | 20 | "Accept-Encoding": "gzip, deflate"} |
20 | 21 | body = "id=206&reason=退款原因_test_123" |
21 | 22 | ... | ... |
commons/api/weightBizBill_listPage.py
... | ... | @@ -16,6 +16,7 @@ class weightBizBill_listPage(): |
16 | 16 | "User-Agent": "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36", |
17 | 17 | "Content-Type": "application/x-www-form-urlencoded", |
18 | 18 | "Accept-Language": "zh-CN,zh;q=0.9", |
19 | + "Host": "test.jmsf.diligrp.com:8385", | |
19 | 20 | "Accept-Encoding": "gzip, deflate"} |
20 | 21 | body = '''rows=10&page=1&sort=id&order=desc&metadata[fee]={"provider":"moneyProvider","index":10,"field": |
21 | 22 | "fee"}&metadata[created]={"provider":"datetimeProvider","index":20,"field": | ... | ... |
config/global_data.conf
... | ... | @@ -14,6 +14,7 @@ sy_user02=sygangda&111111 |
14 | 14 | heb_user01=哈尔滨田太子&a123456 |
15 | 15 | heb_user02=sy_wenze&111111 |
16 | 16 | sg_user01=sg_wenze&111111 |
17 | +hg_user01=111222&111111 | |
17 | 18 | |
18 | 19 | [userId] |
19 | 20 | #冗余配置字段,可不配置 |
... | ... | @@ -34,7 +35,7 @@ demo=["heb1","P3","v1.6","沈阳",None] |
34 | 35 | |
35 | 36 | |
36 | 37 | [environment] |
37 | -#格式只能为一下几种 | |
38 | +#格式只能为一下几种,用于区分环境 | |
38 | 39 | #http://test. |
39 | 40 | #https://test. |
40 | 41 | #http:// |
... | ... | @@ -56,8 +57,54 @@ gateway=test.gateway.diligrp.com:8285 |
56 | 57 | |
57 | 58 | |
58 | 59 | |
59 | - | |
60 | - | |
61 | - | |
62 | - | |
60 | +[host_ip] | |
61 | +#重构host | |
62 | +host1={ | |
63 | + "test.customer.diligrp.com": "10.35.100.45:8382", | |
64 | + "test.bd.diligrp.com": "10.35.100.45:8384", | |
65 | + "test.jmsf.diligrp.com": "10.35.100.44:8385", | |
66 | + "test.account.diligrp.com": "10.35.100.44:8186", | |
67 | + "test.card.diligrp.com": "10.35.100.44:8386", | |
68 | + "test.trading.diligrp.com": "10.35.100.47:8387", | |
69 | + "test.logger.diligrp.com": "10.35.100.47:8283", | |
70 | + "test.orders.diligrp.com": "10.35.100.47:8185", | |
71 | + "test.rule.diligrp.com": "10.35.100.54:8284", | |
72 | + "test.gateway.diligrp.com": "10.35.100.54:8285", | |
73 | + "test.message.diligrp.com": "10.35.100.54:8289", | |
74 | + "test.dfs.diligrp.com": "10.35.100.55:9527", | |
75 | + "test.report.diligrp.com": "10.35.100.56:8388", | |
76 | + "test.exporter.diligrp.com": "10.35.100.56:8288", | |
77 | + "test.appmanager.diligrp.com": "10.35.100.56:9000", | |
78 | + "test.uid.diligrp.com": "10.35.100.56:8282", | |
79 | + "test.nacos.diligrp.com": "10.35.100.37:8848", | |
80 | + "test.scheduler.diligrp.com": "10.35.100.47:8281", | |
81 | + "test.bpmc.diligrp.com": "10.35.100.54:8617", | |
82 | + "test.route.diligrp.com": "10.35.100.54:8286", | |
83 | + "test.uap.diligrp.com": "10.35.100.55:80", | |
84 | + "test.trace.diligrp.com": "10.35.100.55:8082", | |
85 | + "test.xorder.diligrp.com": "10.35.100.56:8090"} | |
86 | + | |
87 | +#杭果host | |
88 | +host2={ | |
89 | + "test.uap.diligrp.com": "10.28.12.150:80", | |
90 | + "test.bpmc.diligrp.com": "10.28.12.150:8617", | |
91 | + "test.as.diligrp.com": "10.28.12.150", | |
92 | + "test.logger.diligrp.com": "10.28.11.149:8283", | |
93 | + "test.scheduler.diligrp.com": "10.28.11.149", | |
94 | + "test.account.diligrp.com": "10.28.11.149:8186", | |
95 | + "test.rule.diligrp.com": "10.28.10.127:8284", | |
96 | + "test.bd.diligrp.com": "10.28.10.127", | |
97 | + "test.customer.diligrp.com": "10.28.10.127:8384", | |
98 | + "test.report.diligrp.com": "10.28.10.127:8388", | |
99 | + "test.jmsf.diligrp.com": "10.28.10.127:8385", | |
100 | + "test.uid.diligrp.com": "10.28.11.180:8282", | |
101 | + "test.message.diligrp.com": "10.28.11.190:8289", | |
102 | + "test.dfs.diligrp.com": "10.28.11.190:9527", | |
103 | + "test.gateway.diligrp.com": "10.28.10.159:8285", | |
104 | + "test.route.diligrp.com": "10.28.10.159:8286", | |
105 | + "test.card.diligrp.com": "10.28.10.159:8386", | |
106 | + "test.exporter.diligrp.com": "10.28.11.183", | |
107 | + "test.ia.diligrp.com": "10.28.11.183", | |
108 | + "test.settlement.diligrp.com": "10.28.11.183:8383", | |
109 | + "test.hg.diligrp.com": "10.28.12.239"} | |
63 | 110 | ... | ... |
main.py
... | ... | @@ -76,9 +76,7 @@ def Send_email(filename): |
76 | 76 | if __name__ == "__main__": |
77 | 77 | #检测数据库 |
78 | 78 | db.mysql_conn_test() |
79 | - #检测登录接口 | |
80 | - my.check_login("sy_user01") | |
81 | 79 | #创建测试套,运行测试用例,生成报告 |
82 | 80 | report=Run_Testcase(Create_Testcase_suite()) |
83 | 81 | #发送邮件 |
84 | 82 | - Send_email(report) |
83 | + Send_email(report) | |
85 | 84 | \ No newline at end of file | ... | ... |