예제 #1
0
 def __init__(self, redis_db=None):
     if redis_db == None:
         redis_db = 0
     conf_path = Project_path.conf_path + "db.ini"
     host = Conf(conf_path).get_value("Redis", "host")
     port = Conf(conf_path).get_value("Redis", "port")
     password = Conf(conf_path).get_value("Redis", "password")
     self.r = redis.Redis(host=host,
                          port=port,
                          db=redis_db,
                          password=password,
                          decode_responses=True)
예제 #2
0
def send_api_response_time(prefix, start_time, end_time, url_rule, request_method, request_url):
    try:
        statsd_conf = Conf.get("statsd")
        if not statsd_conf["enabled"]:
            logging.info("Statsd disabled, not sending stats")
            return

        if not url_rule:
            logging.info("URL rule not found for url: [%s %s]" % (request_method, request_url))
            return

        components = []
        for c in url_rule.rule.split("/"):
            if not c: continue
            if c.startswith("<int:") and c.endswith(">"):
                components.append(c[5:-1])
            elif c.startswith("<path:") and c.endswith(">"):
                components.append(c[6:-1])
            elif c.startswith("<") and c.endswith(">"):
                components.append(c[1:-1])
            else:
                components.append(c)
        if not components or len(components) <= 0: components = ["home"]

        key = prefix + "." + ".".join(components) + "." + request_method
        delta = int((end_time - start_time).total_seconds() * 1000)

        logging.debug(
                "Sending stats to %s:%s [%s: %s]" % (statsd_conf["host"], statsd_conf["port"], key, delta))

        statsd_client = StatsdClient(statsd_conf["host"], statsd_conf["port"])
        statsd_client.timing(key, delta)
    except Exception as e:
        logging.error("Error in sending stats: %s" % e)
예제 #3
0
def host(request):
    '''获取命令行参数'''
    # 获取命令行参数给到环境变量
    env = request.config.getoption("--env").upper()
    test_host = Conf(env_conf_path).get_value(env, "test_host")
    print(f"当前用例运行测试环境:{test_host}")
    os.environ["host"] = test_host
    updata_allure_env(env, test_host)
예제 #4
0
 def get_engine(self):
     db_conf = Conf.get("event_database")
     db_baseurl = "mysql://%s/%s?charset=%s&user=%s&passwd=%s" % (
         db_conf["host"], db_conf["name"], db_conf["charset"], db_conf["user"], db_conf["password"])
     logging.info("DB Baseurl: %s, Init pool size: %s, Max pool size: %s, Pool recycle delay: %s" % (
         db_baseurl, db_conf["init_pool_size"], db_conf["max_pool_size"], db_conf["pool_recycle_delay"]))
     return create_engine(db_baseurl, echo=db_conf["sql_logging"], poolclass=QueuePool,
                          pool_size=db_conf["init_pool_size"],
                          max_overflow=int(db_conf["max_pool_size"]) - int(db_conf["init_pool_size"]),
                          pool_recycle=db_conf["pool_recycle_delay"])
예제 #5
0
def Default_data(product_model, ismeiju=None):
    deviceinfo = json.loads(
        Conf(device_conf).get_value("DeviceInfo", product_model))
    queryinfo = json.loads(
        Conf(device_conf).get_value("QueryInfo", product_model))
    data = {
        "version": "1.0",
        "text": "空调设置制冷模式",
        "uid": "auto_test0001",
        "homeId": "00001",
        "device_info": "device_info",
        "query_reply": "query_reply"
    }
    data["query_reply"] = queryinfo
    # data["device_info"] = deviceinfo  #如果传入全部设备,需要考虑多个同型号的情况
    data["device_info"] = [deviceinfo]
    if ismeiju == None:
        v_box_info = json.loads(
            Conf(device_conf).get_value("DeviceInfo", 'v_box'))
        data['device'] = v_box_info
    return data
예제 #6
0
파일: demo6.py 프로젝트: fengyu0712/myclone
from common.read_xls_news import Read_xls
from common.http_request_new import Request
from common.conf import Conf
from collections import Counter
import json, Project_path
http_conf_path = Project_path.conf_path + "http.ini"
host = Conf(http_conf_path).get_value("HTTP", "sit")
path = "E:\AITEST\\testdata\yb101远程控制-自动化案例_new3.xls"
conf_path = "E:\AITEST\conf\defaultQueryReply.ini"
r = Read_xls(path)
w = r.copy_book()
url = "%s/v1/auto_test/control/virtual" % host
result_path = "E:\AITEST\\testdata\yb101远程控制-自动化案例_new4.xls"
data_yb101_0 = json.loads(Conf(conf_path).get_value("AC", "yb101"))
data_ac = r.read_data('yb101', start_line=2)
for i in range(0, len(data_ac)):
    text = data_ac[i][4]
    if "空调" not in text:
        text = "空调" + text
        r.write_onlydata(w, i + 1, 4, text, sheetname='yb101')
r.save_write(w, result_path)
예제 #7
0
path = os.path.split(Path)[0]
from common.read_xls_news import Read_xls
from common.http_request_new import Request
from common.conf import Conf
from collections import Counter
import Project_path

import jsonpath  #嵌套字典取值s = jsonpath.jsonpath(dic,'$..name')

test_path = Project_path.TestData_path + "电饭煲自动化案例.xlsx"
conf_path = Project_path.conf_path + "ReplyInfo.ini"
result_path = Project_path.TestResult_path + "电饭煲远程控制-自动化案例_Result.xls"
http_conf_path = Project_path.conf_path + "http.ini"
sn_path = Project_path.conf_path + "sn.ini"

host = Conf(http_conf_path).get_value("HTTP", "sit")
testmode = Conf(http_conf_path).get_value("AITEST", "mode")
#sn_yb101=Conf(sn_path).get_value("AC","yb101")
#sn_HB=Conf(sn_path).get_value("AC","HB")
sn_ricecooker = Conf(sn_path).get_value("rice_cooker", "rice_cooker_4001XM")

r = Read_xls(test_path)
w = r.copy_book()
url = "%s/v1/auto_test/control/virtual" % host
data = {
    "version":
    "1.0",
    "text":
    "电饭煲开始煮饭 ",
    "uid":
    "6b07adb88106411fba94fe38c6754baa",
예제 #8
0
import websocket, time, json
from websocket import ABNF
from common.log import Logger
from common.conf import Conf
import Project_path
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
conf_path = Project_path.conf_path
data0 = Conf(conf_path + "/ws.ini").get_value("WS", "content")


class WsSingle:
    def __init__(self, url):
        self.ws = websocket.create_connection(url)  # 创建连接
        Logger().info("WebSocket链接建立成功")

    # @pytest.mark.flaky(reruns=2, reruns_delay=redis_case)  # 重试机制
    def runsingle(self, wavfile, content=None, step=None):
        if content == None:
            content = eval(data0)
        if step == None:  # 如果audioType是wav,此处需要修改为3200
            step = 3200
        self.ws.send(json.dumps(content))

        try:
            with open(wavfile, 'rb') as f:
                while True:
                    data = f.read(step)
                    if data:
                        # print(data)
                        self.ws.send(data, ABNF.OPCODE_BINARY)
예제 #9
0
def sample_get(id):
    # Sample reding from config
    app_host = Conf.get("app_host")
    return json_response({"id": id, "app_host": app_host})
예제 #10
0
path = os.path.split(Path)[0]
from demo.demo7 import Default_data
from common.read_xls_news import Read_xls
from common.http_request_new import Request
from common.conf import Conf
import Project_path

import jsonpath  #嵌套字典取值s = jsonpath.jsonpath(dic,'$..name')

test_path = Project_path.TestData_path + "空调远程控制-自动化案例.xls"
conf_path = Project_path.conf_path + "ReplyInfo.ini"
result_path = Project_path.TestResult_path + "空调远程控制-自动化案例_Result.xls"
http_conf_path = Project_path.conf_path + "http.ini"
sn_path = Project_path.conf_path + "sn.ini"

host = Conf(http_conf_path).get_value("HTTP", "sit")
testmode = Conf(http_conf_path).get_value("AITEST", "mode")
sn_yb101 = Conf(sn_path).get_value("AC", "yb101")
sn_HB = Conf(sn_path).get_value("AC", "HB")

r = Read_xls(test_path)
w = r.copy_book()
url = "%s/v1/auto_test/control/virtual" % host


def Label_Case(sheet_name=None):
    datalist = r.read_data(sheet_name, start_line=2)
    data = []
    if testmode == '0':
        for each in datalist:
            data.append(each)
예제 #11
0
    #         "params": {
    #             "sessionId": self.sessionId,
    #             "text": "",
    #             "nlpIsp": "dui"
    #         }
    #     }
    #     self.ws.send(json.dumps(data), ABNF.OPCODE_TEXT)
    #     return self.ws.recv()

    def close(self):
        self.ws.close()
        Logger().info("WebSocket断开")


if __name__ == "__main__":
    url = Conf(conf_path + "/ws.ini").get_value("SIT", "url")
    print(url)
    wavfail = Project_path.TestData_path + "test_audio\\201M24_01_41_0001.wav"
    wavfail2 = Project_path.TestData_path + "test_audio\\237M32_08_41_0160.wav"
    wavfail3 = Project_path.TestData_path + "test_audio\\佛山的天气如何.wav"
    ws = SimDevices(url)
    a = ws.on_line()
    print(a)

    # time.sleep(2)
    # b = ws.speech(wavfail)
    # print(b)
    print("=====>====")
    # d = ws.speech(wavfail2)
    # print(d)
    # print("=====>====")
예제 #12
0
 def get_api_timeout(timeout=None):
     if timeout:
         return int(timeout)
     else:
         int(Conf.get("api_timeout"))
예제 #13
0
파일: mysql.py 프로젝트: fengyu0712/myclone
create_data_sql= "create table test_data("\
                  "id int not null PRIMARY key auto_increment," \
                  "url varchar(50) ," \
                  "mobilephone varchar(15)," \
                  "amount int(12)," \
                  "type varchar(12)," \
                  "test_result varchar(100) ," \
                  "create_date datetime," \
                  "update_date datetime" \
                  ")DEFAULT CHARSET=utf8"

getdata_sql = "select url from test.test_data where id=redis_case"

# insert_sql='insert into test_data (created_day,name,count) values(%s,%s,%s)'

if __name__ == '__main__':
    insert_sql = 'INSERT INTO `test`.`test_data`(`id`, `url`, `mobilephone`, `amount`, `type`, `test_result`, `create_date`, `update_date`) VALUES (%s, NULL, NULL, NULL, NULL, NULL, NULL, NULL)'
    conf_path = Project_path.conf_path + "db.ini"
    config = Conf(conf_path).get_value("Mysql", "config")
    a = MySql(config)
    a.creat_table(create_data_sql)
    a.insert_manydata(insert_sql, data=[2, 3])
    b = a.read_data(getdata_sql)
    print(b)
    # pd.DataFrame(result)
    # print(eval(b[0][0]))
    # print(type(eval(b))
    # a.close()
    # print(b)
    # print(type(b[redis_case][3]))
예제 #14
0
def get_expectData(product_model, path, result_path, run_num=None):
    if run_num == None:
        run_num = 1
    host = Conf(http_conf_path).get_value("HTTP", "sit")
    url = "%s/v1/auto_test/control/virtual" % host
    data = Default_data(product_model)
    queryinfo = data['query_reply']
    r = Read_xls(path)
    data_list = r.read_data(product_model, start_line=2)
    w = r.copy_book()
    for i in range(len(data_list)):
        testid = data_list[i][0]
        tdata = data_list[i][3]
        try:
            tts_list = eval(data_list[i][7])
        except:
            tts_list = []
        try:
            testdata = json.loads(tdata)
        except:
            testdata = '{' + tdata.replace('&', ',') + '}'
            try:
                testdata = json.loads(testdata)
            except Exception as e:
                print(e)
            else:
                testdata = dict(queryinfo, **testdata)
        finally:
            print(testid)
            data['text'] = data_list[i][4]
            data["query_reply"] = testdata
            n = run_num
            while n > 0:
                Response = Request().requests(url, data, "POST").json()
                tts = str(Response['data']['tts']['data'][0]['text'])
                print(tts)
                tts_list.append(tts)
                nlu = Response['data']['nlu']
                try:
                    lua = jsonpath.jsonpath(Response, "$..luaData")[0]
                except Exception as e:
                    lua = ''
                print(lua)
                if n == 1:
                    tts_list.append(tts)
                    tts_lists = list(set(tts_list))
                    print(tts_lists)
                    r.write_onlydata(w,
                                     i + 1,
                                     5,
                                     str(nlu),
                                     sheetname=product_model)
                    r.write_onlydata(w,
                                     i + 1,
                                     6,
                                     str(lua),
                                     sheetname=product_model)
                    r.write_onlydata(w,
                                     i + 1,
                                     7,
                                     str(tts_lists),
                                     sheetname=product_model)
                else:
                    tts_list.append(tts)
                n -= 1
        i += 1
    r.save_write(w, result_path)
예제 #15
0
from common.read_xls_news import Read_xls
from common.T_websocket import WsSingle
from common.conf import Conf
from common.log import Logger
import Project_path
import time, pytest,allure,xlsxwriter,redis
from multiprocessing import Lock

from demo.redis import RedisLock1

conf_path= Project_path.conf_path
url=Conf(conf_path+"/ws.ini").get_value("WS","url")
audio_path=Conf(conf_path+"/ws.ini").get_value("WS","audio_path")
test_data_path= Project_path.TestData_path + "/case.xlsx"

r=Read_xls(test_data_path)
w=r.copy_book()
# redis_conn= redis.Redis(host='111.231.233.115', port=6379, password="******", db=redis_case)
now = time.strftime('%Y-%m-%d-%H-%M-%S')
result_path = Project_path.TestResult_path + now +__name__ + ".xls"

testdatas=[]
sheet_names=r.get_sheet_names()
for sheetname in sheet_names:
    sheet_data=r.read_data(sheetname,start_line=3)
    for each in sheet_data:
        each.append(sheetname)
    testdatas+=sheet_data
# writedata = WriteExcel()
# testdatas = r.read_data("002M30_36", start_line=3)
pass_num=0
예제 #16
0
 def get_api_timeout(timeout=None):
     if timeout:
         return int(timeout)
     else:
         int(Conf.get("api_timeout"))
예제 #17
0
import os

from flask import Flask

from common.conf import Conf

from common.database import Db, EventDb
from common.decorator import Controller, Permissions, Security

from flask_cors import CORS

flask = Flask(__name__, template_folder="templates", static_folder="../static")
CORS(flask)

Conf.get_instance().init(os.path.dirname(os.path.realpath(__file__)))
Db.get_instance().init()

controller = Controller.get_instance()
# permissions = Permissions.get_instance()
security = Security.get_instance()


예제 #18
0
from common.read_xls_news import Read_xls
from common.http_request_new import Request
from common.myredis import myRedis
from common.conf import Conf
from demo.demo7 import Default_data
from collections import Counter
import Project_path
import jsonpath  # 嵌套字典取值s = jsonpath.jsonpath(dic,'$..name')
import lockfile

test_path = Project_path.TestData_path + "净化器自动化案例.xls"
conf_path = Project_path.conf_path + "ReplyInfo.ini"
result_path = Project_path.TestResult_path + "净化器自动化案例_Result.xls"
http_conf_path = Project_path.conf_path + "http.ini"

host = Conf(http_conf_path).get_value("HTTP", "sit")
testmode = Conf(http_conf_path).get_value("AITEST", "mode")

url = "%s/v1/auto_test/control/virtual" % host

r = Read_xls(test_path)


def Label_Case(sheet_name=None):
    datalist = r.read_data(sheet_name, start_line=2)
    data = []
    if testmode == '0':
        for each in datalist:
            data.append(each)
    else:
        for each in datalist:
예제 #19
0
import time, sys, os, platform

# 获取绝对路径,以便shell脚本跑
curPath = os.path.abspath(os.path.dirname(__file__))
print(curPath)
rootPath = os.path.split(curPath)[0]
print(rootPath)
sys.path.append(rootPath)
import Project_path, pytest
from common.myredis import myRedis
from common.write_xls import WriteExcel
from common.conf import Conf

db_path = Project_path.conf_path + "db.ini"
device_list = eval(Conf(db_path).get_value("Redis", "redis_db"))

# test_path = rootPath+"\\testcase\\WS_Test\\"
# test_path="E:\AITEST\\testcase\TestAiYun"
test_path = "E:\AITEST\\testcase\TestAiYun\\redis_case"

# test_path="E:\AITEST\\testcase\TestAiYun\\redis_case\\test_StrideAcRredis02.py"
now = time.strftime("%Y-%m-%d %H_%M_%S", time.localtime())
result_file = Project_path.TestResult_path + "allure_result\\"
report_file = Project_path.TestReport_path + "allure_report\\"


def run():
    # pytest.main()
    pytest.main(["-s", '-n=1', test_path, '--alluredir', result_file])
    # pytest.main(["-s",  test_path, '--alluredir', result_file])
    # '-s' 展示日志
예제 #20
0
from common.conf import Conf
from demo.demo7 import Default_data
from common.Appointment import *
import Project_path
import jsonpath  # 嵌套字典取值s = jsonpath.jsonpath(dic,'$..name')

product = "电压力锅"
product_model = ['POWER601']

test_path = Project_path.TestData_path + "%s自动化案例.xls" % product
conf_path = Project_path.conf_path + "ReplyInfo.ini"
result_path = Project_path.TestResult_path + "%s自动化案例_Result.xls" % product
http_conf_path = Project_path.conf_path + "http.ini"
db_path = Project_path.conf_path + "db.ini"

host = Conf(http_conf_path).get_value("HTTP", "sit")
testmode = Conf(http_conf_path).get_value("AITEST", "mode")
device_list = eval(Conf(db_path).get_value("Redis", "redis_db"))

url = "%s/v1/auto_test/control/virtual" % host

r = Read_xls(test_path)


def Label_Case(sheet_name=None):
    datalist = r.read_data(sheet_name, start_line=2)
    data = []
    if testmode == '0':
        for each in datalist:
            data.append(each)
    else:
예제 #21
0
path = os.path.split(Path)[0]
from common.read_xls_news import Read_xls
from common.http_request_new import Request
from common.conf import Conf
from collections import Counter
import Project_path

import jsonpath  # 嵌套字典取值s = jsonpath.jsonpath(dic,'$..name')

test_path = Project_path.TestData_path + "电压力锅自动化案例.xlsx"
conf_path = Project_path.conf_path + "ReplyInfo.ini"
result_path = Project_path.TestResult_path + "电压力锅远程控制-自动化案例_Result.xls"
http_conf_path = Project_path.conf_path + "http.ini"
sn_path = Project_path.conf_path + "sn.ini"

host = Conf(http_conf_path).get_value("HTTP", "sit")
testmode = Conf(http_conf_path).get_value("AITEST", "mode")
# sn_yb101=Conf(sn_path).get_value("AC","yb101")
# sn_HB=Conf(sn_path).get_value("AC","HB")
sn_cooker = Conf(sn_path).get_value("pressure_cooker", "e_pressure_cooker")

r = Read_xls(test_path)
w = r.copy_book()
url = "%s/v1/auto_test/control/virtual" % host
data = {
    "version": "1.0",
    "text": "电压力锅开始煮饭 ",
    "uid": "6b07adb88106411fba94fe38c6754baa",
    "homeId": "162681",
    "device": {
        "sn": "0000EC1110002001A18C011A00620000",