diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index ee1c36c..838eedd 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -27,104 +27,91 @@
-
-
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
@@ -135,13 +122,6 @@
@@ -193,10 +180,10 @@
true
-
-
-
-
+
+
+
+
@@ -221,7 +208,6 @@
-
@@ -240,15 +226,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -263,9 +306,9 @@
+
-
@@ -276,95 +319,95 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -534,19 +577,19 @@
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
@@ -564,17 +607,17 @@
-
+
-
+
-
+
@@ -606,21 +649,11 @@
-
+
-
-
-
-
-
-
-
-
-
-
@@ -775,218 +808,222 @@
-
+
-
-
-
+
+
-
+
-
-
-
+
+
-
+
-
-
-
+
+
-
+
-
-
-
+
+
-
+
-
-
-
-
-
+
+
-
+
-
-
-
+
+
-
+
-
-
-
-
-
+
+
-
+
-
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
+
-
+
-
-
+
+
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
+
diff --git a/BLL/Bhttpbase.py b/BLL/Bhttpbase.py
index 235a446..de7ac34 100644
--- a/BLL/Bhttpbase.py
+++ b/BLL/Bhttpbase.py
@@ -10,4 +10,6 @@ def get(self, url, params={}):
return self.mh.get(url, params)
def post(self, url, files=None, params=None):
- return self.mh.post(url, files, params)
\ No newline at end of file
+ return self.mh.post(url, files, params)
+
+ # def check_param(self):
diff --git a/BLL/__pycache__/Bhttpbase.cpython-34.pyc b/BLL/__pycache__/Bhttpbase.cpython-34.pyc
index 9dbd342..03237ce 100644
Binary files a/BLL/__pycache__/Bhttpbase.cpython-34.pyc and b/BLL/__pycache__/Bhttpbase.cpython-34.pyc differ
diff --git a/COMMON/BaseGoals.py b/COMMON/BaseGoals.py
index ab68124..81cba90 100644
--- a/COMMON/BaseGoals.py
+++ b/COMMON/BaseGoals.py
@@ -1,6 +1,5 @@
__author__ = 'Administrator'
class Goals(object):
- URL = '' # 接收接口url
PARAMS = {} # 接收接口参数
RESULT = 'Fail' # 接收测试结果
REALLY_RESULT = ""
@@ -9,4 +8,3 @@ class Goals(object):
SUCCESS_SUM = 0
ERROR_NUM = 0
CASE_TOTAL = 0
- HEADER = {'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','User-Agent':'Mozilla/5.0 (Windows NT 6.1; rv:29.0) Gecko/20100101 Firefox/29.0'}
\ No newline at end of file
diff --git a/COMMON/__pycache__/BaseGoals.cpython-34.pyc b/COMMON/__pycache__/BaseGoals.cpython-34.pyc
index c2f8ca4..ff73cbd 100644
Binary files a/COMMON/__pycache__/BaseGoals.cpython-34.pyc and b/COMMON/__pycache__/BaseGoals.cpython-34.pyc differ
diff --git a/COMMON/__pycache__/http_param.cpython-34.pyc b/COMMON/__pycache__/http_param.cpython-34.pyc
new file mode 100644
index 0000000..d91a0dc
Binary files /dev/null and b/COMMON/__pycache__/http_param.cpython-34.pyc differ
diff --git a/COMMON/http_param.py b/COMMON/http_param.py
new file mode 100644
index 0000000..f8bbeeb
--- /dev/null
+++ b/COMMON/http_param.py
@@ -0,0 +1,21 @@
+__author__ = 'Administrator'
+# 参数化请求
+def str__post_param(list_param):
+ result = {}
+ for i in list_param:
+ result[i["name"]] = i["value"]
+ return result
+
+def str_get_param(list_param, param):
+ result = "?"
+ result += list_param["name"] + "=" + list_param["value"] + "&"
+ return str_sub(0, len(result)-1, result) + "&" + for_dict(param)
+
+def for_dict(d):
+ result = ""
+ for (k, v) in d.items():
+ result += str(k) + "=" + str(v)
+ return result
+
+def str_sub(start, end, str):
+ return str[start:end]
diff --git a/COMMON/operateXML.py b/COMMON/operateXML.py
index 31589de..2222f6c 100644
--- a/COMMON/operateXML.py
+++ b/COMMON/operateXML.py
@@ -1,9 +1,6 @@
__author__ = 'Administrator'
from xml.etree import ElementTree as ET
-
def getXML(xml, mhttp):
- """
- """
tree = ET.parse(xml)
root = tree.getroot()
i_base = {}
@@ -15,15 +12,22 @@ def getXML(xml, mhttp):
interfaceName.append(i_base)
for elem in root.findall("InterfaceList"):
- i_app = {}
+ i_app = {"param":[]}
i_app["id"] = elem.find('id').text
i_app["name"] = elem.find('name').text
i_app["method"] = elem.find('method').text
i_app["url"] = elem.find('url').text
- i_app["params"] = elem.find('params').text
i_app["hope"] = elem.find('hope').text
i_app["login"] = elem.find('login').text
i_app["isList"] = elem.find('isList').text
+ # interfaceName.append(i_app)
+ for p in elem.findall("params"):
+ param = {}
+ param["name"] = p.find("name").text
+ param["type"] = p.find("name").attrib.get("type")
+ param["value"] = p.find("value").text
+ param["must"] = p.find("must").text
+ i_app["param"].append(param)
interfaceName.append(i_app)
# print(interfaceName)
return interfaceName, mhttp
diff --git a/DAL/Dhttpbase.py b/DAL/Dhttpbase.py
index 0b5f7ea..d2f3dcc 100644
--- a/DAL/Dhttpbase.py
+++ b/DAL/Dhttpbase.py
@@ -6,9 +6,10 @@ class ConfigHttp():
def __init__(self, mhttpbase):
self.mhttpbase = mhttpbase
def get(self, url, params):
- url = "http://" + self.mhttpbase.host + ":" + self.mhttpbase.port + url
+ url = "http://" + self.mhttpbase.host + ":" + self.mhttpbase.port + "/" + url + params
+ print(url)
try:
- r = requests.get(url, params=params, headers={'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
+ r = requests.get(url, headers={'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; rv:29.0) Gecko/20100101 Firefox/29.0'})
r.encoding = 'UTF-8'
return r.text
@@ -17,9 +18,9 @@ def get(self, url, params):
return {}
# 封装HTTP POST请求方法,支持上传图片
def post(self, url, files=None, data=None):
- data = eval(data)
- url = 'http://' + self.mhttpbase.host + ':' + self.mhttpbase.port + url
+ # data = eval(data)
+ url = 'http://' + self.mhttpbase.host + ':' + self.mhttpbase.port + "/" + url
r =requests.post(url, files=files, data=data)
- # print(data)
json_response = r.text
+ print(json_response)
return json_response
\ No newline at end of file
diff --git a/DAL/__pycache__/Dhttpbase.cpython-34.pyc b/DAL/__pycache__/Dhttpbase.cpython-34.pyc
index 4364e58..e565e3a 100644
Binary files a/DAL/__pycache__/Dhttpbase.cpython-34.pyc and b/DAL/__pycache__/Dhttpbase.cpython-34.pyc differ
diff --git a/README.md b/README.md
index c4c24db..83524a1 100644
--- a/README.md
+++ b/README.md
@@ -123,4 +123,9 @@ def compare(exJson,factJson,isList=0):
### 2016-9-7
* ܹعϵͳ
+### 2016-9-8
+* ӿڲչ
+ * Ƿ
+ * ֵǷȷ
+
diff --git a/email.ini b/email.ini
index af6d007..68a3a07 100644
--- a/email.ini
+++ b/email.ini
@@ -2,7 +2,7 @@
to_addr = ["284772894@qq.com", "ashikun@126.com"]
mail_host = smtp.qq.com
mail_user = 284772894@qq.com
-mail_pass = tagdcyaqvbkqbjff
+mail_pass = 1111
port = 465
headerMsg = 接口测试
attach = 接口测试
\ No newline at end of file
diff --git a/model/Mhttpbase.py b/model/Mhttpbase.py
index eea9737..cda8d29 100644
--- a/model/Mhttpbase.py
+++ b/model/Mhttpbase.py
@@ -5,7 +5,7 @@
import configparser
from schematics.models import Model
from schematics.types import StringType, URLType
-from schematics.types.compound import MultiType
+from schematics.types.compound import MultiType,ListType
# BaseHttp类
class BaseHttp(Model):
@@ -15,6 +15,7 @@ class BaseHttp(Model):
port = StringType(required=True)
No = StringType(required=True)
file = StringType()
- param = StringType()
+ param = ListType(MultiType())
data = MultiType()
+
diff --git a/model/__pycache__/Mhttpbase.cpython-34.pyc b/model/__pycache__/Mhttpbase.cpython-34.pyc
index a9fff39..29591ac 100644
Binary files a/model/__pycache__/Mhttpbase.cpython-34.pyc and b/model/__pycache__/Mhttpbase.cpython-34.pyc differ
diff --git a/report.xlsx b/report.xlsx
index a89b31f..4000061 100644
Binary files a/report.xlsx and b/report.xlsx differ
diff --git a/runner_m.py b/runner_m.py
index 98a4170..09c7bf3 100644
--- a/runner_m.py
+++ b/runner_m.py
@@ -9,14 +9,16 @@
from MODEL import Memail
from BLL import BgetEmail,BsendEmail
from BLL import BexcelReport as excel
-from COMMON import operateXML
+from COMMON import operateXML as om
from BLL import Bhttpbase
from MODEL import Mhttpbase
from BLL import Bresult, BresultDetail
from MODEL import Mresult, MresultDetail
+from COMMON import http_param as hp
import json
+
mresult = Mresult.result()
mresult.info = []
def get_email():
@@ -31,7 +33,7 @@ def excel_report(wd, data, worksheet_init, worksheet_detail):
ex.detail(worksheet_detail, data[1])
def get_api():
- return operateXML.getXML("d:\\app\\auto_http34_test\\test3.xml", Mhttpbase.BaseHttp())
+ return om.getXML("d:\\app\\auto_http34_test\\test4.xml", Mhttpbase.BaseHttp())
def configHttp(httpbase):
return Bhttpbase.ConfigHttp(httpbase)
@@ -58,14 +60,15 @@ def function(self):
response = ""
if self.index == 1:
if gm[self.index]["method"] == "POST":
- response = self.config_http.post(url=go.URL, params=go.PARAMS)
+ response = self.config_http.post(url=gm[self.index]["url"], params=hp.str__post_param(gm[self.index]["param"]))
go.REALLY_RESULT = eval(response)
hope = eval(self.hope)
# temp = testJson.compareJson(hope, go.REALLY_RESULT, gm[self.index]["isList"])
temp = check.compare(hope, go.REALLY_RESULT)
if temp:
- go.LOGIN_KY = gm[1]["login"]
- go.LOGIN_VALUE = go.REALLY_RESULT["content"][0][go.LOGIN_KY]
+ go.LOGIN_KEY = gm[self.index]["login"]
+ print(go.LOGIN_KEY)
+ go.LOGIN_VALUE = go.REALLY_RESULT["content"][0][go.LOGIN_KEY]
go.RESULT = 'Pass'
go.SUCCESS_SUM += 1
else:
@@ -75,17 +78,17 @@ def function(self):
if gm[self.index]["login"] != "0":
go.PARAMS[go.LOGIN_KEY] = go.LOGIN_VALUE
if gm[self.index]["method"] == "POST":
- response = self.config_http.post(go.URL, go.PARAMS)
+ go.PARAMS = hp.str__post_param(gm[self.index]["param"])
+ response = self.config_http.post(gm[self.index]["url"], go.PARAMS)
if gm[self.index]["method"] == "GET":
- response = self.config_http.get(go.URL)
+ go.PARAMS = hp.str_get_param(gm[self.index]["param"][0], go.PARAMS)
+ response = self.config_http.get(gm[self.index]["url"], go.PARAMS)
go.REALLY_RESULT = eval(str(response))
hope = eval(self.hope)
- # temp = testJson.compareJson(hope, go.REALLY_RESULT, gm[self.index]["isList"])
temp = check.compare(hope, go.REALLY_RESULT, gm[self.index]["isList"])
if temp:
go.RESULT = 'Pass'
go.SUCCESS_SUM += 1
- # except AssertionError:
else:
go.RESULT = 'Fail'
go.ERROR_NUM += 1
@@ -95,35 +98,30 @@ def function(self):
def get_test_suite(index):
test_suite = unittest.TestSuite()
hope = gm[index]["hope"] # 预期值
- test_suite.addTest(TestInterfaceCase("function", hope,index))
+ test_suite.addTest(TestInterfaceCase("function", hope, index))
return test_suite
# 运行测试用例函数
def run_case(runner):
case_list = httpbase.No
case_list = eval(case_list) # 把字符串类型的list转换为list
- temp_case = ""
if len(case_list) == False: #判断是否执行指定的用例ID
temp_case = gm
for index in range(1, len(temp_case)):
- go.URL = gm[index]['url']
- go.PARAMS = gm[index]["params"]
test_suite = get_test_suite(index)
runner.run(test_suite)
# 记录运行结果
- mresult.info.append(json.loads(json.dumps(resultInfo(MresultDetail.resultInfo(), t_id=gm[index]["id"], t_name=gm[index]["name"], t_url=gm[0]["host"] + gm[index]["url"],
- t_param=gm[index]["params"], t_actual=go.REALLY_RESULT, t_hope=gm[index]["hope"], t_result=go.RESULT,
+ mresult.info.append(json.loads(json.dumps(resultInfo(MresultDetail.resultInfo(), t_id=gm[index]["id"], t_name=gm[index]["name"], t_url=gm[0]["host"] +"/" + gm[index]["url"],
+ t_param=str(go.PARAMS), t_actual=go.REALLY_RESULT, t_hope=gm[index]["hope"], t_result=go.RESULT,
t_method=gm[index]["method"]).to_primitive())))
else:
for i in case_list:
for j in range(1, len(gm)):
if str(i) == gm[j]['id']:
- go.URL = gm[j]['url']
- go.PARAMS = gm[j]["params"]
test_suite = get_test_suite(j)
runner.run(test_suite)
- mresult.info.append(json.loads(resultInfo(MresultDetail.resultInfo, t_id=gm[j]["id"], t_name=gm[j]["name"], t_url=gm[0]["host"] + gm[0]["url"],
- t_param=gm[j]["params"], t_actual=go.REALLY_RESULT, t_hope=gm[j]["hope"], t_result=go.RESULT,
+ mresult.info.append(json.loads(resultInfo(MresultDetail.resultInfo, t_id=gm[j]["id"], t_name=gm[j]["name"], t_url=gm[0]["host"] +"/"+gm[0]["url"],
+ t_param=str(go.PARAMS), t_actual=go.REALLY_RESULT, t_hope=gm[j]["hope"], t_result=go.RESULT,
t_method=gm[j]["method"]).to_primitive()))
# 运行测试套件
@@ -140,8 +138,6 @@ def run_case(runner):
worksheet2 = workbook.add_worksheet("测试详情")
data = json.loads(json.dumps(result(mresult, test_date=str(sum_time) + "毫秒", test_sum=go.CASE_TOTAL, test_failed=go.ERROR_NUM, test_version="v2.2", test_pl="python3",
test_net="本地连接", test_name=gm[0]["title"], test_success=go.SUCCESS_SUM, info=mresult.info)))
- print("shikun")
- print(data)
excel_report(workbook, data, worksheet, worksheet2)
# 发送email
diff --git a/test4.xml b/test4.xml
new file mode 100644
index 0000000..dffdae5
--- /dev/null
+++ b/test4.xml
@@ -0,0 +1,47 @@
+
+
+ 导购码接口测试
+ dgm.boweixin.com
+ 80
+ []
+
+
+ account
+ 18576759587
+ 1
+
+
+ password
+ 222222
+ 1
+
+
+ type
+ 0
+ 1
+
+ 0
+ 1001
+ 登陆
+ POST
+ Login
+ {"appStatus":{"errorCode":0,"message":"操作成功"},"content":[{"user_sex":0,"fk_user_city":440300,"user_id":30,"nickname":"18576759587","user_phone":"18576759587","head_picture":"http:\/\/dgm.boweixin.com\/","has_finance":1,"user_state":1}]}
+ user_id
+ 0
+
+
+
+ lookerId
+ 2
+ 1
+
+ 1002
+ 个人主页
+ GET
+ GetPersonalHomePage
+ {"appStatus":{"errorCode":0,"message":"操作成功"},"content":[{"business_name":"坤达点子","notice_img":"\/product\/20160718184134_321.jpg","user_type":1,"user_id":2,"goods":[{"good_price":45211.0,"good_id":12,"good_name":"艾欧","banner_picture1":"\/product\/20160719165135_8977.png"},{"good_price":199.0,"good_id":14,"good_name":"麒麟瓜1","banner_picture1":"\/product\/20160720102028_5352.jpg"},{"good_price":452.0,"good_id":6,"good_name":"实力产品","banner_picture1":"\/product\/20160718165448_2602.png"},{"good_price":99898.0,"good_id":11,"good_name":"越南芒果","banner_picture1":"\/product\/20160720100057_5877.jpg"}],"shop_img":"\/product\/20160718120144_3196.jpg","head_picture":"http:\/\/dgm.boweixin.com\/\/product\/20160718134528_4744.jpg","notice_id":1}]}
+ 1
+ 1
+
+
+
\ No newline at end of file