Commit 6c5ac0483c463ed95752de7582aa575b60836ccc
1 parent
a82f9e0e
更新接口封装的方法
Showing
5 changed files
with
29 additions
and
24 deletions
commons/MySession.py
@@ -53,7 +53,7 @@ class mysession(): | @@ -53,7 +53,7 @@ class mysession(): | ||
53 | self.myproxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'} | 53 | self.myproxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'} |
54 | self.allow_redirects = False | 54 | self.allow_redirects = False |
55 | self.firmid={"group":"1","hd":"2","cd":"3","qqhe":"4","mdj":"5","gy":"6","cc":"7","sg":"8","sy":"9"} | 55 | self.firmid={"group":"1","hd":"2","cd":"3","qqhe":"4","mdj":"5","gy":"6","cc":"7","sg":"8","sy":"9"} |
56 | - | 56 | + self.user={} |
57 | 57 | ||
58 | def cliLogin(self): | 58 | def cliLogin(self): |
59 | self.webHeaders, self.clientHeaders, self.userInfo = cliSession().loginUser() | 59 | self.webHeaders, self.clientHeaders, self.userInfo = cliSession().loginUser() |
@@ -106,6 +106,8 @@ class mysession(): | @@ -106,6 +106,8 @@ class mysession(): | ||
106 | self.se = requests.session() | 106 | self.se = requests.session() |
107 | # 使用session对象的方法POST/GET等 | 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 = self.se.post(url=self.url_client, headers=self.header_client, json=self.body_client, proxies=self.proxies, **kwargs) |
109 | + #获取user信息供其他接口使用 | ||
110 | + self.user[account]=self.re.json()["data"]["user"] | ||
109 | #组装请求的cookie | 111 | #组装请求的cookie |
110 | co = requests.cookies.RequestsCookieJar() | 112 | co = requests.cookies.RequestsCookieJar() |
111 | co.set("UAP_firmId", str(self.re.json()["data"]["user"]["firmId"]),domain=".diligrp.com") | 113 | co.set("UAP_firmId", str(self.re.json()["data"]["user"]["firmId"]),domain=".diligrp.com") |
@@ -288,4 +290,3 @@ sy2 = my.get_session_client("sy_user02") | @@ -288,4 +290,3 @@ sy2 = my.get_session_client("sy_user02") | ||
288 | # gy1=my.get_session_client("gy_user01") | 290 | # gy1=my.get_session_client("gy_user01") |
289 | # sg1=my.get_session_client("sg_user01") | 291 | # sg1=my.get_session_client("sg_user01") |
290 | # hs1=my.get_session_client("hs_user01") | 292 | # hs1=my.get_session_client("hs_user01") |
291 | - |
commons/api/weighingServiceSave.py
@@ -2,10 +2,10 @@ | @@ -2,10 +2,10 @@ | ||
2 | # -*- coding: UTF-8 -*- | 2 | # -*- coding: UTF-8 -*- |
3 | import urllib3 | 3 | import urllib3 |
4 | from commons import common as com | 4 | from commons import common as com |
5 | -from commons.MySession import sy1 | 5 | +from commons.MySession import my,sy1 |
6 | from commons.basic.duplicateToken import duplicateToken | 6 | from commons.basic.duplicateToken import duplicateToken |
7 | urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | 7 | urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) |
8 | -du=duplicateToken() | 8 | + |
9 | 9 | ||
10 | class weighingServiceSave(): | 10 | class weighingServiceSave(): |
11 | url = "http://test.gateway.diligrp.com:8285/jmsf-web/api/entrace/weighingServiceSave" | 11 | url = "http://test.gateway.diligrp.com:8285/jmsf-web/api/entrace/weighingServiceSave" |
@@ -42,18 +42,19 @@ class weighingServiceSave(): | @@ -42,18 +42,19 @@ class weighingServiceSave(): | ||
42 | "accountId": 0, | 42 | "accountId": 0, |
43 | "protocolId": None} | 43 | "protocolId": None} |
44 | 44 | ||
45 | - def __init__(self): | 45 | + def __init__(self,market): |
46 | + self.market=market | ||
46 | self.url = weighingServiceSave.url.replace("http://test.", com.get_global_config("global_data", "environment", "en")) | 47 | self.url = weighingServiceSave.url.replace("http://test.", com.get_global_config("global_data", "environment", "en")) |
47 | self.header = weighingServiceSave.header | 48 | self.header = weighingServiceSave.header |
48 | - self.header["jmsf_duplicate_commit_token"] = du.jmsf_duplicate_commit_token() | ||
49 | - self.header["UAP_accessToken"] = sy1.cookies["UAP_accessToken"] | ||
50 | - self.header["UAP_refreshToken"] = sy1.cookies["UAP_refreshToken"] | ||
51 | - self.header["UAP_firmId"] = sy1.cookies["UAP_firmId"] | 49 | + self.header["jmsf_duplicate_commit_token"] = duplicateToken(market).jmsf_duplicate_commit_token() |
50 | + self.header["UAP_accessToken"] = self.market.cookies["UAP_accessToken"] | ||
51 | + self.header["UAP_refreshToken"] = self.market.cookies["UAP_refreshToken"] | ||
52 | + self.header["UAP_firmId"] = self.market.cookies["UAP_firmId"] | ||
52 | self.header["Host"] = com.get_global_config("global_data", "host", "gateway") | 53 | self.header["Host"] = com.get_global_config("global_data", "host", "gateway") |
53 | 54 | ||
54 | 55 | ||
55 | 56 | ||
56 | 57 | ||
57 | -# tt=weighingServiceSave() | 58 | +# tt=weighingServiceSave(sy1) |
58 | # re=sy1.post(url=tt.url,headers=tt.header,json=tt.body,proxies=my.myproxies) | 59 | # re=sy1.post(url=tt.url,headers=tt.header,json=tt.body,proxies=my.myproxies) |
59 | # print(re.json()) | 60 | # print(re.json()) |
60 | \ No newline at end of file | 61 | \ No newline at end of file |
commons/basic/duplicateToken.py
@@ -16,18 +16,20 @@ class duplicateToken(): | @@ -16,18 +16,20 @@ class duplicateToken(): | ||
16 | "Host": "test.gateway.diligrp.com:8285", | 16 | "Host": "test.gateway.diligrp.com:8285", |
17 | "Connection":"Keep-Alive"} | 17 | "Connection":"Keep-Alive"} |
18 | 18 | ||
19 | - def __init__(self): | 19 | + def __init__(self,market): |
20 | + self.market=market | ||
20 | self.url = duplicateToken.url.replace("http://test.", com.get_global_config("global_data", "environment", "en")) | 21 | self.url = duplicateToken.url.replace("http://test.", com.get_global_config("global_data", "environment", "en")) |
21 | self.header = duplicateToken.header | 22 | self.header = duplicateToken.header |
22 | - self.header["UAP_accessToken"] = sy1.cookies["UAP_accessToken"] | ||
23 | - self.header["UAP_refreshToken"] = sy1.cookies["UAP_refreshToken"] | ||
24 | - self.header["UAP_firmId"] = sy1.cookies["UAP_firmId"] | 23 | + self.header["UAP_accessToken"] = self.market.cookies["UAP_accessToken"] |
24 | + self.header["UAP_refreshToken"] = self.market.cookies["UAP_refreshToken"] | ||
25 | + self.header["UAP_firmId"] = self.market.cookies["UAP_firmId"] | ||
25 | self.header["Host"] = com.get_global_config("global_data", "host", "gateway") | 26 | self.header["Host"] = com.get_global_config("global_data", "host", "gateway") |
26 | 27 | ||
27 | def jmsf_duplicate_commit_token(self): | 28 | def jmsf_duplicate_commit_token(self): |
28 | - re = sy1.get(url=self.url, headers=self.header) | 29 | + re = self.market.get(url=self.url, headers=self.header) |
29 | return re.json()["data"] | 30 | return re.json()["data"] |
30 | 31 | ||
31 | 32 | ||
32 | -# du=duplicateToken() | 33 | +# print(duplicateToken(sy1).jmsf_duplicate_commit_token()) |
34 | +# du=duplicateToken(sy1) | ||
33 | # print(du.jmsf_duplicate_commit_token()) | 35 | # print(du.jmsf_duplicate_commit_token()) |
commons/basic/listCarType.py
@@ -18,17 +18,18 @@ class listCarType(): | @@ -18,17 +18,18 @@ class listCarType(): | ||
18 | "Content-Length": "23"} | 18 | "Content-Length": "23"} |
19 | body = {"businessCode":"jmsf"} | 19 | body = {"businessCode":"jmsf"} |
20 | 20 | ||
21 | - def __init__(self): | 21 | + def __init__(self,market): |
22 | + self.market=market | ||
22 | self.url = listCarType.url.replace("http://test.", com.get_global_config("global_data", "environment", "en")) | 23 | self.url = listCarType.url.replace("http://test.", com.get_global_config("global_data", "environment", "en")) |
23 | self.header = listCarType.header | 24 | self.header = listCarType.header |
24 | - self.header["UAP_accessToken"] = sy1.cookies["UAP_accessToken"] | ||
25 | - self.header["UAP_refreshToken"] = sy1.cookies["UAP_refreshToken"] | ||
26 | - self.header["UAP_firmId"] = sy1.cookies["UAP_firmId"] | 25 | + self.header["UAP_accessToken"] = self.market .cookies["UAP_accessToken"] |
26 | + self.header["UAP_refreshToken"] = self.market .cookies["UAP_refreshToken"] | ||
27 | + self.header["UAP_firmId"] = self.market .cookies["UAP_firmId"] | ||
27 | self.header["Host"] = com.get_global_config("global_data", "host", "gateway") | 28 | self.header["Host"] = com.get_global_config("global_data", "host", "gateway") |
28 | 29 | ||
29 | def car_list(self): | 30 | def car_list(self): |
30 | - re = sy1.post(url=self.url, headers=self.header,json=self.body) | 31 | + re = self.market .post(url=self.url, headers=self.header,json=self.body) |
31 | return re.json() | 32 | return re.json() |
32 | 33 | ||
33 | -# tt=listCarType() | 34 | +# tt=listCarType(sy1) |
34 | # print(tt.car_list()) | 35 | # print(tt.car_list()) |
35 | \ No newline at end of file | 36 | \ No newline at end of file |
testcase/weightBizBill/test_weighingServiceSave.py
@@ -6,8 +6,8 @@ from commons.MySession import my,sy1 | @@ -6,8 +6,8 @@ from commons.MySession import my,sy1 | ||
6 | from commons.api.weighingServiceSave import weighingServiceSave | 6 | from commons.api.weighingServiceSave import weighingServiceSave |
7 | from commons.basic.listCarType import listCarType | 7 | from commons.basic.listCarType import listCarType |
8 | urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | 8 | urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) |
9 | -we=weighingServiceSave() | ||
10 | -li=listCarType() | 9 | +we=weighingServiceSave(sy1) |
10 | +li=listCarType(sy1) | ||
11 | 11 | ||
12 | 12 | ||
13 | 13 |