接口測(cè)試階段課件_第1頁(yè)
接口測(cè)試階段課件_第2頁(yè)
接口測(cè)試階段課件_第3頁(yè)
接口測(cè)試階段課件_第4頁(yè)
接口測(cè)試階段課件_第5頁(yè)
已閱讀5頁(yè),還剩21頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

能夠?qū)HRM系統(tǒng)中的登錄接口實(shí)現(xiàn)測(cè)試的編寫(接口對(duì)象調(diào)用、斷言##import#classLoginAPI:#初始化definitself.url="#deflogin(self,returnrequests.post(url=self.url,##importapp#classEmployeeAPI:#初始化definitself.url_add_employee=app.BASE_URL+"/api/sys/user"self.url_get_employee=app.BASE_URL+"/api/sys/user/{}"defadd_employee(self,returnrequests.post(url=self.url_add_employee,json=add_employee_data,defupdate_employee(self,employee_id,update_data):url=self.url_update_employee.format(employee_id)returnrequests.put(url=url,json=update_data,defget_employee(self,url=self.url_update_employee.format(employee_id)returnrequests.get(url=url,headers=app.headers_data)defdelete_employee(self,url=self.url_update_employee.format(employee_id)returnrequests.delete(url=url,headers=app.headers_data)##importfromapi.loginimportclassTestLogin(unittest.TestCase):#前置處理defsetUp(self):self.login_api=LoginAPI()#def case001deftest01_case001(self):#調(diào)用登錄接口進(jìn)行登錄response=self.login_api.login({"":",self.assertEqual(200,response.status_code)self.assertEqual(True,response.json().get("success"))self.assertEqual(10000,response.json().get("code")),##importfromapi.loginimport#classTestLogin(unittest.TestCase):#前置處理defsetUp(self):self.login_api=LoginAPI()#def ##case001deftest01_case001(self):#調(diào)用登錄接口進(jìn)行登錄response=self.login_api.login({"":",#self.assertEqual(200,response.status_code)self.assertEqual(True,response.json().get("success"))self.assertEqual(10000,response.json().get("code")),#case002不輸 deftest02_case002(self):#調(diào)用登錄接口進(jìn)行登錄response=self.login_api.login({" ":"","password":"123456"})#self.assertEqual(200,response.status_code)self.assertEqual(False,response.json().get("success"))self.assertEqual(20001,response.json().get("code")) 錯(cuò)誤",response.json().get("message"))

#case003deftest03_case003(self):#調(diào)用登錄接口進(jìn)行登錄response= ": ",#斷言self.assertEqual(200,response.status_code)self.assertEqual(False,response.json().get("success"))self.assertEqual(20001,response.json().get("code")) 錯(cuò)誤", 長(zhǎng)度小于11deftest04_case004(self):#調(diào)用登錄接口進(jìn)行登錄response=self.login_api.login({" ":" ","password":#self.assertEqual(200,response.status_code)self.assertEqual(False,response.json().get("success"))self.assertEqual(20001,response.json().get("code")) 錯(cuò)誤", 場(chǎng)地大于11deftest05_case005(self):#調(diào)用登錄接口進(jìn)行登錄response=self.login_api.login({" ":"138000000023","password":#self.assertEqual(200,response.status_code)self.assertEqual(False,response.json().get("success"))self.assertEqual(20001,response.json().get("code")) 錯(cuò)誤",response.json().get("message")) deftest06_case006(self):#調(diào)用登錄接口進(jìn)行登錄#self.assertEqual(200,response.status_code)self.assertEqual(False,response.json().get("success"))self.assertEqual(20001,response.json().get("code")) 錯(cuò)誤",response.json().get("message"))#case007輸入 deftest07_case007(self):#調(diào)用登錄接口進(jìn)行登錄response=self.login_api.login({" ":" ","password":#self.assertEqual(200,response.status_code)self.assertEqual(False,response.json().get("success"))self.assertEqual(20001,response.json().get("code")) 錯(cuò)誤",response.json().get("message"))#case008deftest08_case008(self):#調(diào)用登錄接口進(jìn)行登錄response=self.login_api.login({" ":" ","password":"123456","haha":"xixi"})#self.assertEqual(200,response.status_code)self.assertEqual(True,response.json().get("success"))self.assertEqual(10000,response.json().get("code"))",#case009少參-缺 deftest09_case009(self):#調(diào)用登錄接口進(jìn)行登錄response=self.login_api.login({"password":"123456"})#self.assertEqual(200,response.status_code)self.assertEqual(False,response.json().get("success"))self.assertEqual(20001,response.json().get("code")) 錯(cuò)誤",response.json().get("message"))#case010少參-deftest10_case010(self):#調(diào)用登錄接口進(jìn)行登錄response=self.login_api.login({" ":" #self.assertEqual(200,response.status_code)self.assertEqual(False,response.json().get("success"))self.assertEqual(20001,response.json().get("code"))self.assertIn("用戶名或錯(cuò)誤",response.json().get("message"))#case011無(wú)參defdeftest11_case011(self):#調(diào)用登錄接口進(jìn)行登錄response=self.login_api.login(None)self.assertEqual(200,response.status_code)self.assertEqual(False,response.json().get("success"))self.assertEqual(99999,response.json().get("code")),#case012錯(cuò)誤參數(shù) deftest12_case012(self):#調(diào)用登錄接口進(jìn)行登錄response=self.login_api.login({"mobiel":" ","password":self.assertEqual(200,response.status_code)self.assertEqual(False,response.json().get("success"))self.assertEqual(20001,response.json().get("code")) 錯(cuò)誤",response.json().get("message"))#case013錯(cuò)誤參數(shù)deftest13_case013(self):#調(diào)用登錄接口進(jìn)行登錄":",self.assertEqual(200,response.status_code)self.assertEqual(False,response.json().get("success"))self.assertEqual(20001,response.json().get("code")) 錯(cuò)誤",response.json().get("message"))##importtimefromscripts.test01_loginimportTestLogin#suite=unittest.TestSuite()#report="./report/report-{}.html".format(time.strftime("%Y%m%d-#withopen(report,"wb")asf:#創(chuàng)建HTMLTestRunnerrunnerrunner=HTMLTestRunner(f,title="API# 試套[{"desc":"case001登錄成功","login_data":{"": "password":"status_code":200,"success":true,"code":10000,"message":"操作成功{"desc":"case002不輸入號(hào)","login_data":{"":"password":"status_code":200,"success":false,"code":20001,"message":"用戶名或錯(cuò)誤{"desc":"case003不輸入","login_data":{"": "password":"status_code":200,"success":false,"code":20001,"message":"用戶名或錯(cuò)誤{"desc":"case004長(zhǎng)度小于11位","login_data":{"": "password":"status_code":200,"success":false,"code":20001,"message":"用戶名或錯(cuò)誤{"desc":"case005場(chǎng)地大于11位"login_data": ":"password":"status_code":200,"success":false,"code":20001,"message":"用戶名 {"desc":"case006 "login_data":{ ":"error","password":"123456""status_code":200,"success":false,"code":20001,"message":"用戶名 {"desc":"case007輸入未 "login_data":{ ": "password":"status_code":200,"success":false,"code":20001,"message":"用戶名 {"desc":"case008多參","login_data":{ ": "password":"123456","haha":"xixi""status_code":200,"success":true,"code":10000,"message":"操作成功{"desc":"case009少參-缺少 "login_data":{"password":"status_code":200,"success":false,"code":20001,"message":"用戶名 {"desc":"case010少參-缺 "login_data":{"":" "status_code""status_code":200,"success":false,"code":20001,"message":"用戶名 {"desc":"case011無(wú)參","status_code":200,"success":false,"code":99999,"message":"抱歉,系統(tǒng)繁忙"{"desc":"case012錯(cuò)誤參數(shù)- "login_data":{"mobiel":" "password":"123456""status_code":200,"success":false,"code":20001,"message":"用戶名 {"desc":"case013錯(cuò)誤參數(shù)- "login_data":{ ": "passwd":"status_code":200,"success":false,"code":20001,"message":"用戶名 }]##importjsonimportunittestfromapi.loginimportfromparameterizedimport#defbuild_data():#指定文件路徑j(luò)son_file=#打開jsontest_data=withopen(json_file,encoding="utf-8")asf:json_data=json.load(f)forcase_datainlogin_data=case_data.get("login_data")status_code=case_data.get("status_code")success=case_data.get("success")code=messagemessage=test_data.append((login_data,status_code,success,code,message))print("test_data={}".format((login_data,status_code,code,message)))returntest_dataclassTestLogin(unittest.TestCase):#前置處理defsetUp(self):self.login_api=LoginAPI()#定義測(cè)試用例deftest01_login(self,login_data,status_code,success,code,message):#調(diào)用登錄接口進(jìn)行登錄response=self.login_api.login(login_data)self.assertEqual(status_code,response.status_code)self.assertEqual(success,response.json().get("success"))self.assertEqual(code,response.json().get("code"))self.assertIn(message,response.json().get("message"))##importapp#classEmployeeAPI:#初始化defdefinitself.url_add_employee=app.BASE_URL+"/api/sys/user"self.url_get_employee=app.BASE_URL+"/api/sys/user/{}"defadd_employee(self,returnrequests.post(url=self.url_add_employee,json=add_employee_data,##importfromapi.employeeimport#classTestEmployee(unittest.TestCase):employee_id=None#employee_id defself.employee_api=#deftest01_add_employee(self):add_employee_data={"username": " "timeOfEntry":"2020-07-"formOfEmployment":"workNumber":"072804","departmentName":"銷售","departmentId":#員工ID唯性"correctionTime":"2020-07-}#response=#self.assertEqual(200,response.status_code)self.assertEqual(True,response.json().get("success"))self.assertEqual(10000,response.json().get("code")),#提取員工TestEmployee.employee_id=response.json().get("data").get("id")##importappimportrequests#classEmployeeAPI:#初始化definitself.url_add_employee=app.BASE_URL+"/api/sys/user"self.url_get_employee=app.BASE_URL+"/api/sys/user/{}"defadd_employee(self,returnrequests.post(url=self.url_add_employee,json=add_employee_data,defupdate_employee(self,employee_id,update_data):url=self.url_update_employee.format(employee_id)returnrequests.put(url=url,json=update_data,##importfromapi.employeeimport#classTestEmployee(unittest.TestCase):employee_id=None#employee_id defself.employee_api=#deftest01_add_employee(self):add_employee_data={"username": " "timeOfEntry":"2020-07-"formOfEmployment":"workNumber""workNumber":"072804","departmentName":"銷售","departmentId":#員工ID唯性"correctionTime":"2020-07-}response=self.assertEqual(200,response.status_code)self.assertEqual(True,response.json().get("success"))self.assertEqual(10000,response.json().get("code"))self.assertIn("操作成功"response.json().get("message"))#提取員工TestEmployee.employee_id=response.json().get("data").get("id")#deftest02_update_employee(self):update_employee_data={"username":"rose0728"}#獲取響應(yīng)結(jié)果response=self.employee_api.update_employee(TestEmployee.employee_id,self.assertEqual(200,response.status_code)self.assertEqual(True,response.json().get("success"))self.assertEqual(10000,response.json().get("code")),##importappimportrequests#classEmployeeAPI:#初始化definitself.url_add_employee=app.BASE_URL+"/api/sys/user"self.url_get_employee=app.BASE_URL+"/api/sys/user/{}"defdefadd_employee(self,returnrequests.post(url=self.url_add_employee,json=add_employee_data,defupdate_employee(self,employee_id,update_data):url=self.url_update_employee.format(employee_id)returnrequests.put(url=url,json=update_data,defget_employee(self,url=self.url_update_employee.format(employee_id)returnrequests.get(url=url,headers=app.headers_data)##importfromapi.employeeimport#classTestEmployee(unittest.TestCase):employee_id=None#employee_id defself.employee_api=#deftest01_add_employee(self):add_employee_data={"username": "timeOfEntry":"2020-07-"formOfEmployment":"workNumber":"072804","departmentName":"銷售","departmentId":#員工ID唯性"correctionTime":"2020-07-}#response=#self.assertEqual(200,response.status_code)self.assertEqual(True,response.json().get("success"))self.assertEqual(10000,response.json().get("code"))self.assertIn("操作成功response.json().get("message"))#提取員工TestEmployee.employee_idTestEmployee.employee_id=response.json().get("data").get("id")#deftest02_update_employee(self):update_employee_data={"username":"rose0728"}#response=self.employee_api.update_employee(TestEmployee.employee_id,self.assertEqual(200,response.status_code)self.assertEqual(True,response.json().get("success"))self.assertEqual(10000,response.json().get("code"))self.assertIn("操作成功response.json().get("message"))#deftest03_get_employee(self):#獲取響應(yīng)結(jié)果response=self.employee_api.get_employee(TestEmployee.employee_id)self.assertEqual(200,response.status_code)self.assertEqual(True,response.json().get("success"))self.assertEqual(10000,response.json().get("code"))",##importapp#classEmployeeAPI:#初始化definitself.url_add_employee=app.BASE_URL+"/api/sys/user"self.url_get_employee=app.BASE_URL+"/api/sys/user/{}"defadd_employee(self,returnrequests.post(url=self.url_add_employee,json=add_employee_data,defupdate_employee(self,employee_id,urlurl=returnrequests.put(url=url,json=update_data,defget_employee(self,url=self.url_update_employee.format(employee_id)returnrequests.get(url=url,headers=app.headers_data)defdelete_employee(self,url=self.url_update_employee.format(employee_id)returnrequests.delete(url=url,headers=app.headers_data)##importfromapi.employeeimport#classTestEmployee(unittest.TestCase):employee_id=None#employee_id defself.employee_api=#deftest01_add_employee(self):add_employee_data={"username": " "timeOfEntry":"2020-07-"formOfEmployment":"workNumber":"072804","departmentName":"銷售","departmentId":#員工ID唯性"correctionTime":"2020-07-}#response=#self.assertEqual(200,response.status_code)self.assertEqual(True,response.json().get("success"))self.assertEqual(10000,response.json().get("code")),#提取員工TestEmployee.employee_id=#deftest02_update_employee(self):update_employee_data={"username":"rose0728"}#獲取響應(yīng)結(jié)果response=self.employee_api.update_employee(TestEmployee.employee_id,self.assertEqual(200,response.status_code)self.assertEqual(True,response.json().get("success"))self.assertEqual(10000,response.json().get("code")),#deftest03_get_employee(self):#獲取響應(yīng)結(jié)果response=self.employee_api.get_employee(TestEmployee.employee_id)self.assertEqual(200,response.status_code)self.assertEqual(True,response.json().get("success"))self.assertEqual(10000,response.json().get("code")),#deftest04_delete_employee(self):#獲取響應(yīng)結(jié)果response=self.employee_api.delete_employee(TestEmployee.employee_id)self.assertEqual(200,response.status_code)self.assertEqual(True,response.json().get("success"))self.assertEqual(10000,response.json().get("code")),##defcommon_assert(case,response,status_code=200,success=True,code=10000,case.assertEqual(status_code,response.status_code)case.assertEqual(success,response.json().get("success"))case.assertEqual(code,response.json().get("code"))case.assertIn

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論