Commit 07e35650 authored by huangqiang's avatar huangqiang

Interface_Atuo_test

parent 8460e68a
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="projectConfiguration" value="pytest" />
<option name="PROJECT_TEST_RUNNER" value="pytest" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (venv) (2)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Interface_Atuo_test.iml" filepath="$PROJECT_DIR$/.idea/Interface_Atuo_test.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="14" />
<option name="y" value="75" />
<option name="width" value="1750" />
<option name="height" value="980" />
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
</component>
</project>
\ No newline at end of file
# coding=utf-8
import time
import configparser
# IP地址校验
def validate_ip(ip_str) -> bool:
sep = ip_str.split('.')
if len(sep) != 4:
return False
for i, x in enumerate(sep):
try:
int_x = int(x)
if int_x < 0 or int_x > 255:
return False
except ValueError:
return False
return True
# 更新配置文件的数据
def update_address(address: str):
if address == "geek.jkwljy.com":
update_conf("host", "host", address)
elif address:
if validate_ip(address.split(":")[0]):
update_conf("host", "host", address)
else:
print("IP地址错误:", address)
else:
print("未输入IP地址,使用默认IP地址:192.168.32.41:3000")
# 获取时间格式名称
def get_time_name() -> list:
names = []
dname = time.strftime("%Y_%m_%d", time.localtime())
names.append(dname)
sname = time.strftime("%Y_%m_%d-%H_%M_%S", time.localtime())
names.append(sname)
return names
# 读取配置文件
def readconf(section, option):
value = ""
cf = configparser.ConfigParser()
cf.read("config.conf", encoding="utf-8")
if cf.has_option(section, option):
value = cf.get(section, option)
else:
print("section, option值错误:", section+" "+option )
return value
# 更新配置文件
def update_conf(section, option, value):
cf = configparser.ConfigParser()
cf.read("config.conf", encoding="utf-8")
if cf.has_option(section, option):
cf.set(section, option, value)
cf.write(open("config.conf", "w"))
else:
print("section, option,value值错误:", section+" "+option+" "+value)
def set_host() -> str:
base_url = ""
host = readconf("host", "host")
if host == "geek.jkwljy.com":
base_url = "https://" + host
else:
base_url = "http://" + host
return base_url
\ No newline at end of file
[host]
host = 132.232.15.12
[path]
logpath = log/
reportpath = report/
[url]
web_hook = https://oapi.dingtalk.com/robot/send?access_token=94b76afb5b538437e9986e95bd9e4c882cfcf3c75e8c1b3a6f209cac403b8e00
[token]
token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiIyNTc0ODgiLCJ0ZXJtaW5hbCI6InBjIiwidXVpZCI6IjZhMTgxYmFmMDllNjRkZjQ5MDdhNDg3M2M5NDQ0NWNlIiwidGltZXN0YW1wIjoxNTc0MzE5NDEzNDE1fQ.FnymeuiIkTflj1UcCgfq3DxrDBeJ-TwcJz4pc_xIxdw
[password]
wan_neng_password = A0S7f14f94e7-dcc
[user]
phone = 15300000000
password = Abc123!
[test]
login = login/testsuites/
teach_manage = teach_manage/testsuites/
# coding=utf-8
from dingtalkchatbot import chatbot
import common
import string
def send_dingding_message(web_hook,msg,message_type="text",is_at_all=False,at_mobiles=None):
result = None
dingRobot=chatbot.DingtalkChatbot(web_hook)
if message_type == "text":
if isinstance(msg,str):
result = dingRobot.send_text(msg=msg, is_at_all=is_at_all,at_mobiles=at_mobiles)
elif message_type == "link":
# msg={title="测试标题",text="this is 内容",message_url="http://132.232.15.12/jky/#/personnel/employeeinfo"}
if isinstance(msg,dict):
result = dingRobot.send_link(**msg)
else:
print("msg数据类型错误")
elif message_type == "markdown":
# msg={title="测试标题",text="this is 内容"}
if isinstance(msg,dict):
title=msg['title']
text=msg['text']
result = dingRobot.send_markdown(title=title, text=text,is_at_all=is_at_all,at_mobiles=at_mobiles)
else:
print("msg数据类型错误")
elif message_type == "send_feed_card":
if isinstance(msg,list):
links = []
# title = "测试feedcard",message_url = "http://132.232.15.12/jky/#/personnel/employeeinfo",\
# pic_url="http://pic18.nipic.com/20120103/8993051_170340691334_2.jpg"
for m in msg:
if isinstance(m,dict):
link = chatbot.FeedLink(**m)
links.append(link)
else:
print("msg中有类型错误")
if links:
result = dingRobot.send_feed_card(links=links)
else:
print("msg数据类型错误")
elif message_type == "ActionCard":
if isinstance(msg, dict):
actionCard = chatbot.ActionCard(msg)
result = dingRobot.send_action_card(actionCard)
else:
print("msg数据类型错误")
else:
print("msg_type错误")
return result
def get_markdown_template()-> str:
markdown_template = """"
接口测试概要(${host})\n
整体结果: ${result}\n
测试开始时间:${start_datetime}
持续时间:${duration_time}\n
测试用例总数:${testcases_total},成功:${testcases_success},失败:${testcases_fail}\n
测试调用接口总数:${teststep_total},成功:${teststep_success},失败:${teststep_failures},跳过:${teststep_skipped},错误:${teststep_errors}
"""
return markdown_template
def send_result_message(summary: str):
stat = summary["stat"]
testcases = stat["testcases"]
teststeps = stat["teststeps"]
time = summary["time"]
host = common.readconf("host", "host")
messagedata = {
"host": host,
"result": summary["success"],
"testcases_total": testcases["total"],
"testcases_success": testcases["success"],
"testcases_fail": testcases["fail"],
"teststep_total": teststeps["total"],
"teststep_success": teststeps["successes"],
"teststep_failures": teststeps["failures"],
"teststep_errors": teststeps["errors"],
"teststep_skipped": teststeps["skipped"],
"start_datetime": time["start_datetime"],
"duration_time": time["duration"][:8]
}
markdown_template = string.Template(get_markdown_template())
markdown = markdown_template.safe_substitute(**messagedata)
web_hook = common.readconf("url", "web_hook")
msg = {
"title": "接口测试概况",
"text": markdown
}
send_dingding_message(web_hook, msg=msg, message_type="markdown")
# web_hook = "https://oapi.dingtalk.com/robot/send?access_token=94b76afb5b538437e9986e95bd9e4c882cfcf3c75e8c1b3a6f209cac403b8e00"
# send_dingding_message(web_hook,msg="测试")
# msg = {
# "title": "接口测试概况",
# "text": get_markdown_template()
# }
# send_dingding_message(web_hook,msg=msg,message_type="markdown")
# coding = utf-8
import requests
import common
class GetData:
def __init__(self):
self.header = {
"Content-Type": "application/json;charset=UTF-8"
}
def set_token(self, phone, psd):
uri = "/service-user/auth/employee"
url = common.set_host() + uri
data = {"type": "employee", "identityType": 1, "ip": "0.0.0.0", "account": phone, "password": psd}
response = requests.post(url=url, json=data)
rJ = response.json()
token = rJ["data"]["token"]
self.header["token"] = "Bearer "+token
if token:
common.update_conf("token", "token", token)
else:
print("获取token失败")
return token
def set_wan_neng_password(self, phone, password):
self.set_token(phone, password)
uri = "/service-user/masterKey/getKey"
url = common.set_host() + uri
data = {"platform": "GuardianAPP"}
response = requests.get(url=url, params=data, headers=self.header)
rJ = response.json()
wan_neng_password = rJ["data"]
if wan_neng_password:
common.update_conf("password", "wan_neng_password", wan_neng_password)
else:
print("获取wan_neng_password失败")
return wan_neng_password
INFO  HttpRunner version: 2.3.1
INFO  Loading environment variables from E:\jenkinsAndpython\jichengtest\teach_manage\.env
INFO  Start to run testcase: 登录相关接口测试
INFO  POST http://192.168.32.41:3000/service-user/auth/employee
INFO  status_code: 200, response_time(ms): 176.54 ms, response_length: 258 bytes

INFO  
==================== Output ====================
Variable : Value
---------------- : -----------------------------
Token : eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiI2NDQ2MSIsInRlcm1pbmFsIjoicGMiLCJ1dWlkIjoiYTljMzc5OWMyNDU3NDdlMDhhOTlhMGUxMmRiYzE2ZjMiLCJ0aW1lc3RhbXAiOjE1NzQwNzI4ODczMjV9.n779h0Emcu2nx1G3acMtUsGQkmgVT1M2wY2Ate90A_k
------------------------------------------------

INFO  GET http://192.168.32.41:3000/service-user/employees/info
INFO  status_code: 200, response_time(ms): 540.08 ms, response_length: 999 bytes

INFO  GET http://192.168.32.41:3000/service-user/employees/8223/access/modules
INFO  status_code: 200, response_time(ms): 89.81 ms, response_length: 4564 bytes

INFO  GET http://192.168.32.41:3000/service-user/token/valid
INFO  status_code: 200, response_time(ms): 75.09 ms, response_length: 35 bytes

INFO  Start to run testcase: 登录相关接口测试
INFO  POST http://192.168.32.41:3000/service-user/auth/employee
INFO  status_code: 200, response_time(ms): 78.69 ms, response_length: 260 bytes

INFO  
==================== Output ====================
Variable : Value
---------------- : -----------------------------
Token : eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiIyNTc0ODkiLCJ0ZXJtaW5hbCI6InBjIiwidXVpZCI6IjNlZDIzMjYzYjg2NTRhMzlhYzYwNjk0YjI1OWMzNDc5IiwidGltZXN0YW1wIjoxNTc0MDcyODg4MTIyfQ.6a5Ef9E2sOmAMUX1BALm5vrIJwzPzx8mCt7d65EN9n4
------------------------------------------------

INFO  GET http://192.168.32.41:3000/service-user/employees/info
INFO  status_code: 200, response_time(ms): 104.74 ms, response_length: 582 bytes

INFO  GET http://192.168.32.41:3000/service-user/employees/8515/access/modules
INFO  status_code: 200, response_time(ms): 99.31 ms, response_length: 1988 bytes

INFO  GET http://192.168.32.41:3000/service-user/token/valid
INFO  status_code: 200, response_time(ms): 77.39 ms, response_length: 35 bytes

INFO  Start to render Html report ...
INFO  Generated Html report: report/2019_11_18-18_28_07_test.html
INFO  HttpRunner version: 2.3.1
INFO  Loading environment variables from E:\jenkinsAndpython\jichengtest\teach_manage\.env
INFO  Start to run testcase: 登录相关接口测试
INFO  POST http://192.168.32.41:3000/service-user/auth/employee
INFO  status_code: 200, response_time(ms): 147.1 ms, response_length: 258 bytes

INFO  
==================== Output ====================
Variable : Value
---------------- : -----------------------------
Token : eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiI2NDQ2MSIsInRlcm1pbmFsIjoicGMiLCJ1dWlkIjoiYTcxOTIwMTNkNzdhNDY4OTgzYzBhMjA0M2RhZjc4NmMiLCJ0aW1lc3RhbXAiOjE1NzQwNzM3OTgxNDh9.K4dRxD7nHUhb3Tgs3U8RM4Gb1YfELqB9weST_xVaxpk
------------------------------------------------

INFO  GET http://192.168.32.41:3000/service-user/employees/info
INFO  status_code: 200, response_time(ms): 549.94 ms, response_length: 999 bytes

INFO  GET http://192.168.32.41:3000/service-user/employees/8223/access/modules
INFO  status_code: 200, response_time(ms): 86.25 ms, response_length: 4564 bytes

INFO  GET http://192.168.32.41:3000/service-user/token/valid
INFO  status_code: 200, response_time(ms): 77.79 ms, response_length: 35 bytes

INFO  Start to render Html report ...
INFO  Generated Html report: report/2019_11_18-18_43_17_test.html
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment