Skip to content

Commit

Permalink
Merge pull request #31 from tsbxmw/dev-2.1.0
Browse files Browse the repository at this point in the history
Dev 2.1.0 fix @ support @test @Skip
  • Loading branch information
tsbxmw authored Dec 4, 2018
2 parents be23029 + d35427c commit 04ea89d
Show file tree
Hide file tree
Showing 14 changed files with 419 additions and 47 deletions.
4 changes: 2 additions & 2 deletions haf/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# encoding = 'utf-8'

from haf.main import main
from haf.main import main_args


main()
main_args()

12 changes: 10 additions & 2 deletions haf/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ def constructor(self, inputs:dict={}):
self.url = f"{self.protocol}://{self.host_port}{self.url_part}"

def deserialize(self):
try:
data = json.dumps(self.data, indent=4)
except:
data = str(self.data)
return {
"header": self.header,
"data": self.data,
"data": data,
"url": self.url,
"method": self.method,
"protocol": self.protocol,
Expand All @@ -54,9 +58,13 @@ def constructor(self, inputs:dict={}):
self.code = inputs.get("code", {})

def deserialize(self):
try:
body = json.dumps(self.body, indent=4)
except:
body = str(self.body)
return {
"header": str(self.header),
"body": str(self.body),
"body": body,
"code": self.code
}

Expand Down
2 changes: 0 additions & 2 deletions haf/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ def start_manager_server(self):
# runner queue to web server
publish_runner = Queue(maxsize=1)


# register the functions to InfoManager

InfoManager.register("get_case", callable=lambda: case)
InfoManager.register("get_param", callable=lambda: param)
InfoManager.register("get_result", callable=lambda: result)
Expand Down
65 changes: 64 additions & 1 deletion haf/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class BaseCase(object):
BaseCase the base of cases
'''
def __init__(self):
self.mark = CASE_MARK_BASE
self.name = None
self.id = None
self.subid = None
Expand All @@ -20,11 +21,72 @@ def __init__(self):
self.bench_name = ""
self.error_msg = ""
self.AttrNoneList = ["result", "error", "AttrNoneList", ]
self.func = None


class PyCase(BaseCase):
def __init__(self, module_name, module_path):
super().__init__()
self.mark = CASE_MARK_API
self.type = CASE_TYPE_PY
self.message_type = MESSAGE_TYPE_CASE
self.log_key = ""
self.module_name = module_name
self.module_path = module_path
self.suite = ""
self.func = ""
self._init_all()

def _init_all(self):
self.ids = Ids()
self.run = CASE_RUN
self.dependent = []
self.bench_name = ""
self.request = Request()
self.expect = Expect()
self.response = Response()
self.sqlinfo = SqlInfo()
self.log_key = ""
self.error = None

def constructor(self, *args, **kwargs):
'''
:param args:
:param kwargs:
:return:
'''
args_init = {}
if len(args) > 0 and isinstance(args[0], dict):
args_init = args[0]
else:
args_init = kwargs
#logger.info(args_init)
self.ids.constructor(args_init)
self.run = CASE_RUN if args_init.get("run") is True else CASE_SKIP
self.func = args_init.get("func")
self.suite = args_init.get("suite")

def bind_bench(self, bench_name):
self.bench_name = bench_name
self.generate_log_key()

def generate_log_key(self):
self.log_key = self.key = f"{self.bench_name}$%{self.ids.id}.{self.ids.subid}.{self.ids.name}$%"

def deserialize(self):
return {
"ids": self.ids.deserialize(),
"run": self.run,
"bench_name": self.bench_name,
"func": str(self.func),
"type": self.type
}


class HttpApiCase(BaseCase):
def __init__(self):
super().__init__()
self.mark = CASE_MARK_API
self.type = CASE_TYPE_HTTPAPI
self.message_type = MESSAGE_TYPE_CASE
self.log_key = ""
Expand Down Expand Up @@ -78,5 +140,6 @@ def deserialize(self):
"request": self.request.deserialize(),
"response": self.response.deserialize(),
"expect": self.expect.deserialize(),
"sqlinfo": self.sqlinfo.deserialize()
"sqlinfo": self.sqlinfo.deserialize(),
"type": self.type
}
6 changes: 5 additions & 1 deletion haf/common/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ def __init__(self):
pass



class FailBusException(BaseException):
def __init__(self):
pass


class FailLoadCaseFromPyException(BaseException):
def __init__(self):
pass
4 changes: 4 additions & 0 deletions haf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
CASE_TYPE_BASE = 0
CASE_TYPE_WEBUI = 1
CASE_TYPE_HTTPAPI = 2
CASE_TYPE_PY = 3

MESSAGE_TYPE_CASE = 10
MESSAGE_TYPE_RESULT = 11
Expand Down Expand Up @@ -49,6 +50,9 @@
"53": "ERROR"
}

CASE_MARK_BASE = 60
CASE_MARK_API = 61

LOG_PATH_DEFAULT = "D:\workspace\mine\python\haf\data"

MAIN_VERSION = 2
Expand Down
30 changes: 25 additions & 5 deletions haf/ext/resource/report/base_online.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@
{% endfor %}
</td>
<td>{{results.begin_time}}</td>
{% if results.end_time %}
<td>{{results.end_time}}</td>
{% else %}
<td>running...</td>
{% endif %}
<td>{{results.duration}}</td>
<td>{{results.passed}}</td>
<td>{{results.failed}}</td>
Expand Down Expand Up @@ -162,26 +166,42 @@
<li>url : {{case.case.request.url}}</li>
<li onclick="showElement('{{case.case.request}}')" ><a>all</a></li>
<ul id="{{case.case.request}}" style="display:none">
<li>header : {{case.case.request.header}}</li>
<li>data : {{case.case.request.data}}</li>
<li>header :
<pre>{{case.case.request.header}}</pre>
</li>
<li>data :
<pre>{{case.case.request.data}}</pre>
</li>
</ul>
</td>
<td>
{% set response=case.case.response.deserialize() %}
<li >code : {{response.get("code")}}</li>
<li onclick="showElement('{{case.case.response}}')" ><a>all</a></li>
<ul id="{{case.case.response}}" style="display:none">
<li style="hidden:none">header : {{response.get("header")}}</li>
<li style="hidden:none">body : {{response.get("body")}}</li>
<li style="hidden:none">
header :
<pre>{{response.get("header")}}</pre>
</li>
<li style="hidden:none">
body :
<pre>{{response.get("body")}}</pre>
</li>
</ul>
</td>
<td>
{% set check=case.result_check_response %}
<li onclick="showElement('{{'{}.{}.{}.{}.response_check'.format(case.case.bench_name, case.case.ids.id, case.case.ids.subid, case.case.ids.name)}}')"><a>response check</a></li>
<ul id="{{'{}.{}.{}.{}.response_check'.format(case.case.bench_name, case.case.ids.id, case.case.ids.subid, case.case.ids.name)}}" style="display:none">
<li>code check: {{case.result_check_response[0]}}</li>
<li>code check:
<pre>{{case.result_check_response[0]}}</pre>
</li>
<li><a href="file:///{{case.log_dir}}">body check: {{case.result_check_response[1]}}</a></li>
</ul>
<li onclick="showElement('{{'{}.{}.{}.{}.run_error'.format(case.case.bench_name, case.case.ids.id, case.case.ids.subid, case.case.ids.name)}}')"><a>run error</a></li>
<div id="{{'{}.{}.{}.{}.run_error'.format(case.case.bench_name, case.case.ids.id, case.case.ids.subid, case.case.ids.name)}}" style="display:none">
<pre> {{case.run_error}} </pre>
</div>
</td>
<td>
<ul>
Expand Down
1 change: 1 addition & 0 deletions haf/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#encoding='utf-8'
44 changes: 27 additions & 17 deletions haf/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from haf.bench import HttpApiBench
from haf.busclient import BusClient
from haf.case import HttpApiCase
from haf.case import HttpApiCase, PyCase
from haf.common.exception import FailLoaderException
from haf.common.log import Log
from haf.config import *
Expand Down Expand Up @@ -53,26 +53,28 @@ def run(self):
file_name = temp.get("file_name")
inputs = LoadFromConfig.load_from_file(file_name)

suite = HttpApiSuite()

bench_name = ""

input = inputs.get("config")[0]
bench_name = input.get("name")
module_name = input.get("module_name")
module_path = input.get("module_path")

bench = HttpApiBench()

for input in inputs.get("dbconfig"):
db = SQLConfig()
db.constructor(input)
bench.add_db(db)
if "dbconfig" in inputs.keys():
for input in inputs.get("dbconfig"):
db = SQLConfig()
db.constructor(input)
bench.add_db(db)

for input in inputs.get("testcases"):

if input.get("id") is None or input.get("subid") is None:
continue
if input.get("host_port") is None:
input["host_port"] = inputs.get("config").get("host_port")
case = HttpApiCase()
input["host_port"] = inputs.get("config")[0].get("host_port")
if "api_name" in input.keys():
case = HttpApiCase()
else:
case = PyCase(module_name, module_path)
try:
case.constructor(input)
case.bind_bench(bench_name)
Expand Down Expand Up @@ -116,7 +118,7 @@ def put_web_message(self, key:str):

@locker
def put_case(self, key:str, case):
logger.info(f"{self.key} -- put case {case.ids.id}.{case.ids.subid}.{case.ids.name}")
logger.info(f"{self.key} -- put case {case.bench_name} - {case.ids.id}.{case.ids.subid}.{case.ids.name}")
case_queue = self.bus_client.get_case()
case_queue.put(case)

Expand All @@ -127,19 +129,21 @@ def end_handler(self):
case_queue.put(SIGNAL_CASE_END)
except Exception as e:
logger.error(e)
pass


class LoadFromConfig(object):

@staticmethod
def load_from_file(file_name):
if file_name.endswith(".xlsx"):
return LoadFromConfig.load_from_xlsx(file_name)
output = LoadFromConfig.load_from_xlsx(file_name)
elif file_name.endswith(".json"):
return LoadFromConfig.load_from_json(file_name)
output = LoadFromConfig.load_from_json(file_name)
elif file_name.endswith(".yml"):
return LoadFromConfig.load_from_yml(file_name)
output = LoadFromConfig.load_from_yml(file_name)
elif file_name.endswith(".py"):
output = LoadFromConfig.load_from_py(file_name)
return output

@staticmethod
def load_from_xlsx(file_name):
Expand All @@ -157,4 +161,10 @@ def load_from_json(file_name):
def load_from_yml(file_name):
if isinstance(file_name, str):
inputs = Utils.load_from_yml(file_name)
return inputs

@staticmethod
def load_from_py(file_name):
if isinstance(file_name, str):
inputs = Utils.load_from_py(file_name)
return inputs
5 changes: 4 additions & 1 deletion haf/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

from haf.program import Program
from haf.config import BANNER_STRS
from coupling.dict import AttrDict
import argparse


def init():
print(BANNER_STRS)


def main():
def main_args():

init()

Expand All @@ -36,6 +38,7 @@ def main():
sub_run_arg_program.add_argument("--only-runner", "-or", type=bool, default=False, dest="only_runner", help="""if true, only start runner""")
sub_run_arg_program.add_argument("--only-recorder", "-ore", type=bool, default=False, dest="only_recorder", help="""if true, only start recorder""")
sub_run_arg_program.add_argument("--config", "-c", type=str, dest="config", help="""customer config""")
sub_run_arg_program.add_argument("--api", "-api", dest="api", default=True, type=bool, help="api case or not, default is true")

args = arg_program.parse_args()
main_program = Program()
Expand Down
Loading

0 comments on commit 04ea89d

Please sign in to comment.