Python edit basic and HTTP Interface Test _9.3 Chapter

Source: Internet
Author: User

HTTP status Code Classification Query method + unit test

1 #statuscodetype.py2 classStatuscodetype ():3     defGetstatustype (self,status):4         ifisinstance (STATUS,STR):5             ifstatus.isdigit ():6                 ifstatus[0]=='1':7                     return 'Request request information received'8                 elifstatus[0]=='2':9                     return 'Success'Ten                 elifstatus[0]=='3': One                     return ' redirect' A                 elifstatus[0]=='4': -                     return 'Client Error' -                 elifstatus[0]=='5': the                     return 'Service-side error' -                 Else: -                     return 'non-existent status code' -             Else: +                 return 'non-existent status code' -         elifisinstance (status,int): +             ifstatus>=100 andstatus<200: A                 return  'Request request information received' at             elifStatus >=200 andStatus <300: -                 return 'Success' -             elifStatus >= 300 andStatus < 400: -                 return ' redirect' -             elifStatus >= 400 andStatus < 500: -                 return 'Client Error' in             elifStatus >= 500 andStatus < 600: -                 return 'Service-side error' to             Else: +                 return 'non-existent status code' -         Else: the             return 'non-existent status code'
1 ImportStatuscodetype2s=Statuscodetype.statuscodetype ()3 classTest_statuscode (unittest. TestCase):4     defsetUp (self):5         Pass6     defTearDown (self):7         Pass8     deftest_01 (self):9X=s.getstatustype (100)TenSelf.assertequal (x,'Request request information received') One     deftest_02 (self): AX=s.getstatustype (199) -Self.assertequal (x,'Request request information received') -     deftest_03 (self): theX=s.getstatustype (200) -Self.assertequal (x,'Success') -     #@unittest. Skip (' Do not execute the use case ') -     deftest_04 (self): +X=s.getstatustype (299) -Self.assertequal (x,'Success') +     #@unittest. SkipIf (1, ' skip it ') A     deftest_05 (self): atX=s.getstatustype (300) -Self.assertequal (x,' redirect') -     #@unittest. skipIf (0, ' execute it ') -     deftest_06 (self): -X=s.getstatustype (399) -Self.assertequal (x,' redirect') in     deftest_07 (self): -X=s.getstatustype (400) toSelf.assertequal (x,'Client Error') +     deftest_08 (self): -X=s.getstatustype (499) theSelf.assertequal (x,'Client Error') *     deftest_09 (self): $X=s.getstatustype (500)Panax NotoginsengSelf.assertequal (x,'Service-side error') -     deftest_10 (self): theX=s.getstatustype (599) +Self.assertequal (x,'Service-side error') A     defTest_11 (self): theX=s.getstatustype (100.5) +Self.assertequal (x,'non-existent status code') -     defTest_12 (self): $X=s.getstatustype (-5) $Self.assertequal (x,'non-existent status code') -     deftest_13 (self): -X=s.getstatustype ('ABC') theSelf.assertequal (x,'non-existent status code') -     deftest_14 (self):WuyiX=s.getstatustype (99) theSelf.assertequal (x,'non-existent status code') -     deftest_15 (self): WuX=s.getstatustype (600) -Self.assertequal (x,'non-existent status code') About     deftest_16 (self): $X=s.getstatustype ('302') -Self.assertequal (x,' redirect') -     deftest_17 (self): -X=s.getstatustype ('302.5') ASelf.assertequal (x,'non-existent status code') + if __name__=='__main__': theUnittest.main ()

1 #attached: Select Use cases are executed in the specified order2 ImportUnitTest3  fromTest_9_3_1ImportTest_statuscode4 if __name__=='__main__':5suit=UnitTest. TestSuite ()6Case=[test_statuscode ('test_17'), Test_statuscode ('test_16'), Test_statuscode ('test_01')]7Runner=unittest. Texttestrunner (verbosity=2)#This parameter shows the details of the execution8 suit.addtests (case)9 Runner.run (SUIT)Ten     Print('execution Complete')

Python edit basic and HTTP Interface Test _9.3 Chapter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.