コード例 #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()
コード例 #2
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()
        self.send_mai = SendEmail()


    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 + '测试不通过')
コード例 #3
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()
コード例 #4
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.common = CommonUtil()
        self.mail = SendEmail()
        self.opera_json = OperationJson('../json_config/cookie.json')

    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
コード例 #5
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()
コード例 #6
0
ファイル: test_room_add.py プロジェクト: stinazhang/domiapi
 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()
コード例 #7
0
ファイル: test_scene_add.py プロジェクト: stinazhang/domiapi
 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_add')
     cls.com_util = CommonUtil()
     cls.send_email = SendEmail()
コード例 #8
0
ファイル: test_scene_edit.py プロジェクト: stinazhang/domiapi
 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']
コード例 #9
0
ファイル: test_login.py プロジェクト: stinazhang/domiapi
class run_login(unittest.TestCase):
    def setUp(self) -> None:
        self.run_method = RunMethod()
        self.data = GetData(fileName='/Users/stina/Desktop/apitest.xls',
                            sheetName='login')
        self.com_util = CommonUtil()

    def tearDown(self) -> None:
        pass

    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)
コード例 #10
0
ファイル: test_login.py プロジェクト: stinazhang/domiapi
 def setUp(self) -> None:
     self.run_method = RunMethod()
     self.data = GetData(fileName='/Users/stina/Desktop/apitest.xls',
                         sheetName='login')
     self.com_util = CommonUtil()
コード例 #11
0
ファイル: test_scene_del.py プロジェクト: stinazhang/domiapi
 def setUpClass(cls) -> None:
     cls.run_method = RunMethod()
     cls.data = GetData(fileName='/Users/stina/Desktop/apitest.xls',
                        sheetName='scene_del')
     cls.com_util = CommonUtil()
コード例 #12
0
 def __init__(self):
     self.run_method = RunMethod()
     self.data = GetData()
     self.com_util = CommonUtil()
     self.send_mai = SendEmail()
コード例 #13
0
 def __init__(self):
     self.run_method = RunMethod()
     self.data = GetData()
     self.common = CommonUtil()
     self.mail = SendEmail()
     self.opera_json = OperationJson('../json_config/cookie.json')