Commit 6c5ac0483c463ed95752de7582aa575b60836ccc

Authored by lixi
1 parent a82f9e0e

更新接口封装的方法

commons/MySession.py
... ... @@ -53,7 +53,7 @@ class mysession():
53 53 self.myproxies={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'}
54 54 self.allow_redirects = False
55 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 58 def cliLogin(self):
59 59 self.webHeaders, self.clientHeaders, self.userInfo = cliSession().loginUser()
... ... @@ -106,6 +106,8 @@ class mysession():
106 106 self.se = requests.session()
107 107 # 使用session对象的方法POST/GET等
108 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 111 #组装请求的cookie
110 112 co = requests.cookies.RequestsCookieJar()
111 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 290 # gy1=my.get_session_client("gy_user01")
289 291 # sg1=my.get_session_client("sg_user01")
290 292 # hs1=my.get_session_client("hs_user01")
291   -
... ...
commons/api/weighingServiceSave.py
... ... @@ -2,10 +2,10 @@
2 2 # -*- coding: UTF-8 -*-
3 3 import urllib3
4 4 from commons import common as com
5   -from commons.MySession import sy1
  5 +from commons.MySession import my,sy1
6 6 from commons.basic.duplicateToken import duplicateToken
7 7 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
8   -du=duplicateToken()
  8 +
9 9  
10 10 class weighingServiceSave():
11 11 url = "http://test.gateway.diligrp.com:8285/jmsf-web/api/entrace/weighingServiceSave"
... ... @@ -42,18 +42,19 @@ class weighingServiceSave():
42 42 "accountId": 0,
43 43 "protocolId": None}
44 44  
45   - def __init__(self):
  45 + def __init__(self,market):
  46 + self.market=market
46 47 self.url = weighingServiceSave.url.replace("http://test.", com.get_global_config("global_data", "environment", "en"))
47 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 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 59 # re=sy1.post(url=tt.url,headers=tt.header,json=tt.body,proxies=my.myproxies)
59 60 # print(re.json())
60 61 \ No newline at end of file
... ...
commons/basic/duplicateToken.py
... ... @@ -16,18 +16,20 @@ class duplicateToken():
16 16 "Host": "test.gateway.diligrp.com:8285",
17 17 "Connection":"Keep-Alive"}
18 18  
19   - def __init__(self):
  19 + def __init__(self,market):
  20 + self.market=market
20 21 self.url = duplicateToken.url.replace("http://test.", com.get_global_config("global_data", "environment", "en"))
21 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 26 self.header["Host"] = com.get_global_config("global_data", "host", "gateway")
26 27  
27 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 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 35 # print(du.jmsf_duplicate_commit_token())
... ...
commons/basic/listCarType.py
... ... @@ -18,17 +18,18 @@ class listCarType():
18 18 "Content-Length": "23"}
19 19 body = {"businessCode":"jmsf"}
20 20  
21   - def __init__(self):
  21 + def __init__(self,market):
  22 + self.market=market
22 23 self.url = listCarType.url.replace("http://test.", com.get_global_config("global_data", "environment", "en"))
23 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 28 self.header["Host"] = com.get_global_config("global_data", "host", "gateway")
28 29  
29 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 32 return re.json()
32 33  
33   -# tt=listCarType()
  34 +# tt=listCarType(sy1)
34 35 # print(tt.car_list())
35 36 \ No newline at end of file
... ...
testcase/weightBizBill/test_weighingServiceSave.py
... ... @@ -6,8 +6,8 @@ from commons.MySession import my,sy1
6 6 from commons.api.weighingServiceSave import weighingServiceSave
7 7 from commons.basic.listCarType import listCarType
8 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  
... ...