Esempio n. 1
0
 def setUpClass(cls) -> None:
     '''获取新增厂商ID'''
     cls.header = OperationHeader().get_header()
     url_firm = globalvar.Base_Url + "/firm/add"
     data_firm = {
         "name": "测试厂商700",
         "code": 700,
         "icon": " 测试厂商11",
         "address": "金绣国际测试地址"
     }
     cls.firmid = requests.post(url=url_firm,
                                data=json.dumps(data_firm),
                                headers=cls.header).json()['result']
     '''获取新增产品ID'''
     cls.header = OperationHeader().get_header()
     url_product = globalvar.Base_Url + "/product/add"
     data_product = {
         "firmId": cls.firmid,
         "name": "test product",
         "code": 800,
         "ability": 512
     }
     cls.productid = requests.post(url=url_product,
                                   data=json.dumps(data_product),
                                   headers=cls.header).json()['result']
     '''读测试用例sheet'''
     cls.data = GetData(fileName='/Users/stina/Desktop/apitest.xls',
                        sheetName='product_edit')
     cls.run_method = RunMethod()
     cls.com_util = CommonUtil()
Esempio n. 2
0
 def go_on_run(self):
     logger.info("*************** 开始执行用例 ***************")
     res = None
     pass_count = []
     fail_count = []
     request_data = {}
     rows_count = self.data.get_case_lines()
     try:
         for i in range(1, rows_count):
             is_run = self.data.get_is_run(i)
             if is_run:
                 url = self.data.get_url(i)
                 method = self.data.get_request_method(i)
                 data = json.dumps(self.data.get_data_for_json(i))
                 expect = self.data.get_expect_data(i)
                 header = self.data.is_cookie(i)
                 depend_case = self.data.is_depend(i)
                 if depend_case != None:
                     self.depend_data = DependDentData(depend_case)
                     # 相应数据
                     depend_response_data = self.depend_data.get_data_for_key(
                         i)
                     # 获取依赖的key
                     depend_key = self.data.get_depend_field(i)
                     request_data[depend_key] = depend_response_data
                 if header == 'write':
                     res = self.run_method.run_main(method, url, data)
                     opera_header = OperationHeader()
                     opera_header.write_cookie()
                 if header != 'write':
                     cookie = self.opera_json.get_data('JSESSIONID')
                     cookies = {"JSESSIONID": cookie}
                     cookies = json.dumps(cookies)
                     res = self.run_method.run_main(method=method,
                                                    url=url,
                                                    data=data,
                                                    cookies=cookies)
                 if self.common.is_contain(expect, res):
                     self.data.write_result(i, 'pass')
                     pass_count.append(i)
                 else:
                     self.data.write_result(i, 'fail')
                     fail_count.append(i)
         self.mail.send_main(pass_count, fail_count)
     except requests.exceptions.ConnectionError:
         print('连接错误')
     logger.info("*************** 结束执行用例 ***************")
     return res
Esempio n. 3
0
    def test_login(self):
        res = None
        rows_count = self.data.get_case_lines()
        for i in range(1, rows_count):
            cid = self.data.get_case_id(i)
            url = globalvar.Base_Url + self.data.get_request_url(i)
            method = self.data.get_request_method(i)
            request_data = self.data.get_request_data(i)
            expect = self.data.get_expcet_data(i)
            header = self.data.is_header(i)
            if header == None:
                header = OperationHeader().get_header()
            else:
                header = json.loads(header)

            # 表格里填入返回值
            res = str(
                self.run_method.run_main(method, url, request_data,
                                         header).json())
            self.data.write_response(i, res)

            #与预期值做比较
            res_message = 'message: ' + self.run_method.run_main(
                method, url, request_data, header).json().get("message")
            if self.com_util.is_equal_str(expect, res_message) == 1:
                self.data.write_result(i, 'pass')
                logging.info("**********login test success***********")
                globalvar.pass_count.append(i)
            else:
                self.data.write_result(i, 'fail')
                logging.info("**********login test fail***********")
                globalvar.fail_count.append(i)
Esempio n. 4
0
    def test_run_scene_del_error(self):
        res = None
        rows_count = self.data.get_case_lines()
        for i in range(2, rows_count):
            url = globalvar.Base_Url + self.data.get_request_url(i)
            method = self.data.get_request_method(i)
            request_data = "{" + self.data.get_request_data(
                i) + self.add_scene_id + " }"
            expect = str(int(self.data.get_expcet_data(i)))
            header = self.data.is_header(i)
            if header == None:
                header = OperationHeader().get_header()
            else:
                header = json.loads(header)

            # 表格里填入返回值
            write_json = str(
                self.run_method.run_main(method, url,
                                         request_data.encode('utf-8'),
                                         header).json())
            self.data.write_response(i, write_json)

            # 与预期值做比较
            res = str(
                self.run_method.run_main(method, url,
                                         request_data.encode('utf-8'),
                                         header).status_code)
            if self.com_util.is_equal_str(expect, res) == 1:
                self.data.write_result(i, 'pass')
                logging.info("**********scene_del test success***********")
                globalvar.pass_count.append(i)
            else:
                self.data.write_result(i, 'fail')
                logging.info("**********scene_del test fail***********")
                globalvar.fail_count.append(i)
Esempio n. 5
0
 def setUpClass(cls) -> None:
     '''读测试用例sheet'''
     cls.data = GetData(fileName='/Users/stina/Desktop/apitest.xls',
                        sheetName='firm_add')
     cls.run_method = RunMethod()
     cls.com_util = CommonUtil()
     '''获取token'''
     cls.header = OperationHeader().get_header()
Esempio n. 6
0
 def setUp(self) -> None:
     '获取新增场景ID'
     url = globalvar.Base_Url + "/scene/add"
     data = {"name": "002 test home1"}
     header = OperationHeader().get_header()
     self.add_scene_id = requests.post(url=url,
                                       data=json.dumps(data),
                                       headers=header).json()['result']
Esempio n. 7
0
 def setUpClass(cls) -> None:
     '''获取新增厂商ID'''
     cls.header = OperationHeader().get_header()
     url = globalvar.Base_Url + "/firm/add"
     data = {"name": "测试厂商700", "code":700, "icon":" 测试厂商11", "address":"金绣国际测试地址"}
     cls.firmid = requests.post(url=url, data=json.dumps(data), headers=cls.header).json()['result']
     '''读测试用例sheet'''
     cls.data = GetData(fileName='/Users/stina/Desktop/apitest.xls', sheetName='firm_del')
     cls.run_method = RunMethod()
     cls.com_util = CommonUtil()
Esempio n. 8
0
 def setUpClass(cls) -> None:
     '''获取新增家庭ID'''
     cls.header = OperationHeader().get_header()
     url = globalvar.Base_Url + "/scene/add"
     data = {"name": "002 testhome"}
     cls.sceneid = requests.post(url=url, data=json.dumps(data), headers=cls.header).json()['result']
     '''读测试用例sheet'''
     cls.data = GetData(fileName='/Users/stina/Desktop/apitest.xls', sheetName='room_add')
     cls.run_method = RunMethod()
     cls.com_util = CommonUtil()
Esempio n. 9
0
 def tearDownClass(cls) -> None:
     sql = "SELECT id FROM scene WHERE owner_id=1693143315735314432 AND name!='默认家庭' AND flag=0"
     sql_data = OperationMysql().search_all(sql)
     if sql_data != None:
         sql_count = sql_data[0]
         for i in range(sql_count):
             sid = sql_data[1][i]['id']
             data = json.dumps({"sceneId": sid})
             url = globalvar.Base_Url + '/scene/del'
             header = OperationHeader().get_header()
             response = requests.post(url=url, data=data, headers=header)
     else:
         pass
Esempio n. 10
0
    def go_on_run(self):
        res = None
        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_lines()

        for i in range(1, rows_count):
            # is_run = self.data.get_is_run(i)
            # if is_run:
            cid = self.data.get_case_id(i)
            url = self.data.get_request_url(i)
            method = self.data.get_request_method(i)
            request_data = self.data.get_request_data(i)
            # request_data = self.data.get_data_for_json(i)
            expect = self.data.get_expcet_data(i)
            header = self.data.is_header(i)
            # depend_case = self.data.is_depend(i)
            # if depend_case != None:
            #     self.depend_data = DependdentData(depend_case)
                #获取的依赖响应数据
                # depend_response_data = self.depend_data.get_data_for_key(i)
                #获取依赖的key
                # depend_key = self.data.get_depend_field(i)
                # request_data[depend_key] = depend_response_data

                # res = self.run_method.run_main(method, url, request_data)
                # op_header = OperationHeader(res)
                # op_header.write_cookie()
            if header == None:
                header = OperationHeader().get_header()
            # elif header == 'yes':
            #     op_json = OperetionJson('../dataconfig/cookie.json')
            #     cookie = op_json.get_data('apsid')
            #     cookies = {
            #         'apsid':cookie
            #     }
            #     res = self.run_method.run_main(method, url, request_data,cookies)


            res = str(self.run_method.run_main(method, url, request_data, header).status_code)

            if self.com_util.is_equal_str(expect, res) == 1:
                # print(f'第{i+1}行' + '测试通过')
                # print(expect)
                # print(res)
                self.data.write_result(i, 'pass')
                # pass_count.append(i)
            else:
                self.data.write_result(i, 'fail' + res)
                # fail_count.append(i)
                print(cid + '测试不通过')
Esempio n. 11
0
 def setUpClass(cls) -> None:
     "登录"
     url = globalvar.Base_Url + "/account/login"
     data = {
         "username": "******",
         "password": "******",
         "appId": "1469503131678220288"
     }
     header = {"Content-Type": "application/json"}
     requests.post(url=url, data=json.dumps(data), headers=header)
     cls.run_method = RunMethod()
     cls.data = GetData(fileName='/Users/stina/Desktop/apitest.xls',
                        sheetName='scene_getAll')
     cls.com_util = CommonUtil()
     cls.header = OperationHeader().get_header()
Esempio n. 12
0
 def setUpClass(cls) -> None:
     # "登录"
     # url = globalvar.Base_Url + "/account/login"
     # data = {"username": "******", "password": "******", "appId": "1469503131678220288"}
     # header = {"Content-Type": "application/json"}
     # requests.post(url=url, data=json.dumps(data), headers=header)
     cls.run_method = RunMethod()
     cls.data = GetData(fileName='/Users/stina/Desktop/apitest.xls',
                        sheetName='scene_edit')
     cls.com_util = CommonUtil()
     cls.header = OperationHeader().get_header()
     '获取新增场景ID'
     url = globalvar.Base_Url + "/scene/add"
     data = {"name": "002 test home"}
     cls.sceneid = requests.post(url=url,
                                 data=json.dumps(data),
                                 headers=cls.header).json()['result']