Exemplo n.º 1
0
 def setUp(self):
     print('测试开始')
     rootpath = handle_ini.get_value('rootpath')
     self.url = rootpath + "/Util/Excle_case/case_01.xlsx"
     self.register_url = "/user/register"
     self.login = "******"
     self.addFamily = "/family/addFamily"
Exemplo n.º 2
0
    def run_main(self, method, url, **kwargs):
        base_url = handle_ini.get_value('host')
        if 'http' not in url:
            url = base_url + url
            print(url)
        if method == 'get':
            res = self.send_get(url, **kwargs)

        else:
            res = self.send_post(url, **kwargs)
        return res
Exemplo n.º 3
0
 def run_case(self):
     #获取mock全部数据
     rootpath = handle_ini.get_value('rootpath')
     url = rootpath + "/Util/Excle_case/case_01.xlsx"
     rows = handle.get_rows(url)
     for i in range(rows):
         data = handle.get_rows_value(url, i + 2)
         is_run = data[2]
         if is_run == 'yes':
             method = data[6]
             log_url = data[5]
             json1 = eval(data[7])
             headers = eval(data[9])
             res = request.run_main(method, log_url, headers, json1)
             json_res = res
             json.dumps(json_res, indent=2, ensure_ascii=False)
     return json_res
Exemplo n.º 4
0
# coding=utf-8

import unittest
import HTMLTestRunner_PY3
import time

from UnittestCace.Project.Test_Api import ZNcase_01
from UnittestCace.public.handle_init import handle_ini
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(ZNcase_01.Znjj))
now = time.strftime("%Y-%m-%M-%H_%M_%S", time.localtime(time.time()))
rootpath = handle_ini.get_value('rootpath')
file_path = rootpath + "/Report/"

wwwa = file_path + now + "report.html"
with open(wwwa, 'wb') as f:
    runner = HTMLTestRunner_PY3.HTMLTestRunner(f,
                                               verbosity=2,
                                               title='智能家居测试报告',
                                               description='执行人:袁军令')
    runner.run(suite)
f.close()
Exemplo n.º 5
0
class Demo:
    url = "https://www.biduo.cc/biquge/53_53723/"
    file_path = handle_ini.get_value('file_path')
    cur = 0

    def fiction(self):
        ''' 建立Session:'''
        session = HTMLSession()

        # 打开Url检查返回码
        r = session.get(Demo.url)
        if r.status_code == 404:
            print("url open failed: {}".format(r.url))
        return r

    def analysis(self, htmls):
        anchors = []
        news = htmls.html.find('div#list dd a')
        #查找内容并检查返回内容
        if news == None:
            print("article empty")
        for value in news:
            '''获取Element内容中的信息(文本/链接)'''
            anchor = {'text': value.text, 'links': value.absolute_links}
            anchors.append(anchor)
        return anchors

    def __refine(self, anchors):
        '''数据精炼'''
        l = lambda anchor: {
            'title': anchor['text'].strip(),  #strip()去掉字符串多余空格
            'links': anchor['links']
        }
        return map(l, anchors)

    def __sort(self, anchors):
        '''数据排序'''
        anchors = sorted(anchors, key=self.__sort_seed, reverse=True)
        return anchors

    def __sort_seed(self, anchor):
        for rank in range(0, len(anchor)):
            str(rank + 1)
        return str(rank + 1)

    def __show(self, anchors):
        '''数据显示'''
        for rank in range(0, len(anchors)):
            print('rank' + str(rank + 1) + ":  " + anchors[rank]['title'] +
                  '      ' + str(anchors[rank]['links']))
        set = anchors[rank]['links']
        lists = list(set)[0]
        session = HTMLSession()
        r = session.get(lists)
        newss = r.html.find("div.bookname h1")
        news = r.html.find("div#content")
        for texts in news:
            for self.title in newss:
                print('\n')
                print('-------------------' + self.title.text +
                      '-------------------------')
            print(texts.text)
        return texts.text

    def __open(self, texts):
        wwwa = Demo.file_path + "/{0}.txt".format(self.title.text)
        if wwwa == None:
            print("标题为空")
        with open(wwwa, 'w') as f:
            f.write('-------------------------' + self.title.text +
                    '-------------------------' + '\n' + texts)
            f.close()

    def go(self):
        htmls = self.fiction()
        anchors = self.analysis(htmls)
        anchors = list(self.__refine(anchors))
        anchors = self.__sort(anchors)
        anchors = self.__show(anchors)
        self.__open(anchors)
        print(
            str(datetime.datetime.now()) +
            "-----------------------------------------------------------------"
        )
Exemplo n.º 6
0
class UpDownStuff():
    base_url = handle_ini.get_value('updownstuff_host')
    List_url = base_url + '/list'
    selectCamera_url = base_url + '/selectCamera'
    closeStream_url = base_url + '/closeStream'
    setIpConfig_url = base_url + '/setIpConfig'
    startToGrab_url = base_url + '/startToGrab'
    detail_url = base_url + '/detail'

    def getCameraList(self):
        res = request.run_main('get', self.List_url)
        res = res['data'][0]['uuid']
        print('uuid:' + res)
        return res

    def closeStream(self, uuid):
        json = {"uuid": uuid}
        res = request.run_main('post', self.closeStream_url, json=json)
        print(res)

    def SelectCamera(self, uuid):
        json = {"uuid": uuid, "control-mode": "exclusive"}
        res = request.run_main('post', self.selectCamera_url, json=json)
        print(res)
        status = res['status']
        if status == False:
            time.sleep(2)
            self.closeStream(uuid)
            res1 = request.run_main('post', self.selectCamera_url, json=json)
            if res1['status'] == True:
                print('selectCamera操作成功1')
            else:
                print(res1)
        else:
            print('selectCamera操作成功2')

    # def setIpConfig(self,uuid):
    #     json = {
    #         "uuid": uuid,
    #         "config": "static"
    #     }
    #     res = request.run_main('post', self.setIpConfig_url, json=json)
    #     print('setIpConfig: ',str(res))
    def startToGrab(self, uuid):
        json = {"uuid": uuid, "rgb": False}
        res = request.run_main('post', self.startToGrab_url, json=json)
        if res['status'] == True:
            print('startToGrab操作成功')
        else:
            print(res)

    def detail(self, uuid):
        json1 = {"uuid": uuid}
        res = request.run_main('post', self.detail_url, json=json1)
        if res['status'] == True:
            print('detail操作成功')
        else:
            print(res)
        print(json.dumps(res, indent=2, ensure_ascii=False))

    def Go(self):
        uuid = self.getCameraList()
        self.SelectCamera(uuid)
        # self.setIpConfig(uuid)
        self.startToGrab(uuid)
        self.detail(uuid)