def replace_name(self, title): before_code = re.match('^2.*款(\d+)$', config.get('api', 'oaname'), re.S).group(1) print(before_code) if title == '戶名唯一性校驗': name = config.get('api', 'oaname') else: name = config.get('api', 'oaname')[:18] + str(int(before_code) + 1) config.set('api', 'oaname', name) return name
def replace_name(self,prename): before_code = re.match('^.*?(\d+)$', config.get('api', 'oaname')).group(1) # print("提取出來的測試編號:{}".format(before_code)) keywords= re.search('(.*[\u4e00-\u9fa5]+)',config.get('api','oaname')).group(1) # print(提取出來的測試前綴:{}".format(keywords)) name = keywords + str(int(before_code) + 1) config.set('api', 'oaname', name) if prename is not None: config.set('api','prename',name) return name
def get_events(self, title, name, result, event): if event == "once": model = result['model'] if model != []: data = model[0] events = data["events"] else: return False else: events = result["data"] print(events) if events != []: for i in events: print(i) print("name:{}".format(name)) if i["title"] == name: if title == "獲取事件id": config.set("api", 'eventid', i["id"]) print("要編輯的事件id是:{}".format(config.get("api", 'eventid'))) return True else: return False else: return False
def gettype(title, data): if title == "獲取部門id": ids = getid(config.get('api', 'group'), data) try: config.set("api", "groupid", ids[0]) except Exception as e: print("列表爲空,ids[0]溢出!") raise e elif title == "獲取hr通知部門id": ids = getid(config.get('api', 'hrgroups'), data) config.set("api", "hrgroupsid", ids) elif title == "獲取教師id": ids = getid(config.get('api', 'teachers'), data) try: config.set("api", "teacherid", ids[0]) config.set("api", "teacher", eval(config.get('api', 'teachers'))[0]) except Exception as e: print("列表爲空,ids[0]溢出!") raise e
def getapprover(self): data1=config.get("edit_ap","groupoption") approvers=eval(data1)["approvalUserOptions"] data2=config.get("edit_ap","categoryoption") options=eval(data2)["approvalFlowOptions"] print(type(options[0])) n = 1 for i in options: m = 1 if i["approvalType"]=="AND": for j in approvers: name="approver"+str(m + 10*n) config.set("edit_ap",name,j["cnName"]) m += 1 print(j["cnName"]) else: for j in approvers: name = "approver" + str(m + 10*n) config.set("edit_ap", name, j["cnName"]) break n+=1
def replace(data): p = '#(.*?)#' while re.search(p, data): data_new = re.search(p, data).group(1) try: try: da = config.get('api', data_new) except Exception as e: da = config.get('edit_ap', data_new) except configparser.NoOptionError as e: try: da = config.get('setting', data_new) config.set('setting', 'status', re.search('([a-zA-Z]+)', data_new).group(1)) except Exception as e: if hasattr(Context, data_new): da = str(getattr(Context, data_new)) else: print("找不到参数信息!") raise e data = re.sub(p, da, data, count=1) #查找替換,count查找替換的次數 return data
def replace(data): p='#(.*?)#' while re.search(p,data): data_new = re.search(p,data).group(1) try: da = config.get('api', data_new) except configparser.NoOptionError as e: if hasattr(Context,data_new): da = str(getattr(Context,data_new)) else: print("找不到参数信息!") raise e data = re.sub(p,da,data,count=1) #查找替換,count查找替換的次數 return data
method=case.method, headers=case.headers) actual = resp.json()['success'] print("測試結果:{}".format(actual)) print("傳入的json:{}".format(case.json)) print("傳入的url:{}".format(case.url)) print("傳入的title:{}".format(case.title)) msg = resp.json()['errorMsg'] print("報錯信息:{}".format(msg)) self.do_excel.write_excel(case.id + 1, actual, 'FALSE', msg) try: self.unit.assertEqual(case.expect, actual) self.do_excel.write_excel(case.id + 1, actual, 'PASS') if "驗證賬戶" in case.title: print(type(config.get("setting", "status").upper())) print(getstatus(resp.json()['data'])) self.unit.assertEqual( config.get("setting", "status").upper(), getstatus(resp.json()['data'])) except AssertionError as e: print("粗錯了!") raise e #沒有寫這個只會顯示用例執行次數,寫之後控制台顯示有誤信息 if case.title == "獲取授權碼" and resp.json()['model']['accessToken']: config.set('api', 'token', resp.json()['model']['accessToken']) elif case.title == "獲取賬戶id": self.setting.get_accountid('api', 'oaname', resp.json()['data']) elif case.title == "獲取approveid": self.setting.get_approveid('api', 'oaname', 'edit_ap', 'approveid',
print("測試結果:{}".format(actual)) print("傳入的json:{}".format(case.json)) print("傳入的url:{}".format(case.url)) print("傳入的title:{}".format(case.title)) msg = resp.json()['errorMsg'] print("報錯信息:{}".format(msg)) self.do_excel.write_excel(case.id + 1, actual, 'FALSE', msg) try: self.unit.assertEqual(case.expect,actual) self.do_excel.write_excel(case.id+1,actual,'PASS') except AssertionError as e: print("粗錯了!") raise e #沒有寫這個只會顯示用例執行次數,寫之後控制台顯示有誤信息 if case.title == "獲取授權碼" and resp.json()['model']['accessToken']: config.set('api','token',resp.json()['model']['accessToken']) elif case.title == "獲取approveid": self.setting.get_approveid('api', 'oaname', 'edit_ap', 'approveid', resp.json()['data']) try: if case.title == "驗證審批": self.unit.assertEqual(resp.json()['data'][0]["name"],config.get('api','oaname')) except AssertionError as e: print("審批出問題了!") raise e @classmethod def tearDownClass(cls): cls.dohttp.close()
try: self.unit.assertEqual(case.expect, actual) self.do_excel.write_excel(case.id + 1, actual, 'PASS') except AssertionError as e: msg = resp.json()['errorMsg'] print("報錯信息:{}".format(msg)) self.do_excel.write_excel(case.id + 1, actual, 'FALSE') raise e if case.data is not None: config.set('api', 'token', resp.json()['model']['accessToken']) if case.check_exist is not None: if case.prename is not None: result = self.getevents.get_events( case.title, config.get("api", "prename"), resp.json(), case.event) else: result = self.getevents.get_events(case.title, config.get("api", "oaname"), resp.json(), case.event) try: self.assertEqual(True, result) self.do_excel.write_excel(case.id + 1, result, 'PASS') except Exception as e: self.do_excel.write_excel(case.id + 1, result, 'FALSE') print("無法獲取事件id/事件存在,检查prename参数是否正确!") raise e if case.check_noexist is not None: result = self.getevents.get_events(case.title,
def get_approveid(self, get_section, get_option, set_section, set_option, data): for i in data: if i['title'] == config.get(get_section, get_option): config.set(set_section, set_option, i['id'])
def get_accountid(self, get_section, get_option, data): for i in data: if i['name'] == config.get(get_section, get_option): setattr(Context, 'accountid', i['id'])
def __init__(self): now_time = time.strftime('%Y-%m-%d') name = now_time + '澳科大-日程测试1' if now_time not in config.get('api','oaname'): config.set('api','oaname',name)
print("傳入的url:{}".format(case.url)) print("傳入的title:{}".format(case.title)) print("打印token:{}".format(getattr(Context, 'token'))) try: self.unit.assertEqual(case.expect, actual) self.do_excel.write_excel(case.id + 1, actual, 'PASS') except AssertionError as e: msg = resp.json()['errorMsg'] print("報錯信息:{}".format(msg)) self.do_excel.write_excel(case.id + 1, actual, 'FALSE') raise e #沒有寫這個只會顯示用例執行次數,寫之後控制台顯示有誤信息 if case.title == "獲取授權碼" and resp.json()['model']['accessToken']: # setattr(Context,'token',resp.json()['model']['accessToken']) config.set('api', 'token', resp.json()['model']['accessToken']) print("打印token:{}".format(getattr(Context, 'token'))) elif case.title == "获取开户结算银行、帐户、户名信息": data = resp.json()['data'] config.set('api', 'bankAccountName', data[0]['bankAccountName']) config.set('api', 'bankAccount', data[0]['bankAccount']) config.set('api', 'bankName', data[0]['bankName']) else: id = gettype(case.title, resp.json()['data']) print(id) print("打印{0}:{1}".format(id[0], config.get('api', id[0]))) @classmethod def tearDownClass(cls): cls.dohttp.close()
print("傳入的title:{}".format(case.title)) try: self.unit.assertEqual(case.expect, actual) self.do_excel.write_excel(case.id + 1, actual, 'PASS') except AssertionError as e: msg = resp.json()['errorMsg'] print("報錯信息:{}".format(msg)) self.do_excel.write_excel(case.id + 1, actual, 'FALSE') raise e if case.title == "獲取授權碼" and resp.json()['model']['accessToken']: config.set('api', 'token', resp.json()['model']['accessToken']) elif case.title == "驗證審批組已修改": actual_approver = resp.json()['model']['approvalUsers'][0] expect_approver = eval(config.get( 'edit_ap', 'GroupOption'))["approvalUserOptions"][0] try: self.unit.assertEqual(expect_approver["userId"], actual_approver["userId"]) except AssertionError as e: print("修改審批組不成功!") raise e elif case.title == "驗證審批類型已修改": actual_groupId = resp.json()['model']['approvalFlows'][0] expect_approver = eval(config.get( 'edit_ap', 'CategoryOption'))["approvalFlowOptions"][0] try: self.unit.assertEqual(expect_approver["userId"], actual_groupId["groupId"]) except AssertionError as e: print("修改審批類別不成功!")