Bloggers usually learn python when, mostly copy online others ready to make changes to achieve their own test requirements
All Python basic syntax is actually poorly mastered.
Would like to optimize the implementation of the interface script, the discovery of the basic loop control statements do not know how to write
So get ready to clean up.
1 #!/usr/bin/env python2 #-*-coding:utf_8-*-3 4 ImportRequests5 ImportUnitTest6 ImportRe7 8 classTestswcw_back (unittest. TestCase):9 defsetUp (self):Ten Print "interface Test started" One A defTearDown (self): - Print "end of interface test" - the defTestlogin_1 (self):#Login Test Cases -URL ='http://localhost:8081/swcw/back/sysLogin.action' -Postparams = {'username':'Admin','Password':'123456'} -Results =requests.post (url,postparams) +Pattern = Re.compile (r'Tomain') -Match =Pattern.search (Results.url) + ifResults.status_code = = 200: A ifMatch! =None: at Print 'use case test result: Test pass' - Else: - Print 'use case test Result: Test Failed' - Else: - Print 'use case test Result: request failed' - in defTestlogin_2 (self):#Login Test Cases -URL ='http://localhost:8081/swcw/back/sysLogin.action' toPostparams = {'username':'Admin','Password':'123457'}#Password Error +Results =requests.post (url,postparams) -Pattern = Re.compile (r'Tomain') theMatch =Pattern.search (Results.url) * ifResults.status_code = = 200: $ ifMatch! =None:Panax Notoginseng Print 'use case test result: Test pass' - Else: the Print 'use case test Result: Test Failed' + Else: A Print 'use case test Result: request failed' the + defTestlogin_3 (self):#Login Test Cases -URL ='http://localhost:8081/swcw/back/sysLogin.action' $Postparams = {'username':'admin1','Password':'123456'}#Logon name Error $Results =requests.post (url,postparams) -Pattern = Re.compile (r'Tomain') -Match =Pattern.search (Results.url) the ifResults.status_code = = 200: - ifMatch! =None:Wuyi Print 'use case test result: Test pass' the Else: - Print 'use case test Result: Test Failed' Wu Else: - Print 'use case test Result: request failed' About $ if __name__=="__main__": -Unittest.main ()
Added a control statement based on the original script
Make the output clearer
If statement nested with another if statement
If condition:
Results
Else
Results
Python Learning Notes (Control statements)