Python Interface Automation test (ii)

Source: Internet
Author: User
Tags wsdl

Code implementation

1.xlsengine.py

#-*-coding:utf-8-*-__author__='Yanghaitao'ImportxlrdImportXLWTclassxlsengine_rd ():"""The Xlsengine is a demo class for Excel openration Just for some basic test or the using or the 3rd class in P Ython"""    def __init__(self,file):#Define class variableSelf.xls_name =file Self.xlrd_object=None Self.xlwt_object=None self.isopenfailed=TruedefXlrd_open (self):Try:            #xlrd. book.encoding= "Utf-8"Self.xlrd_object =Xlrd.open_workbook (self.xls_name) self.isopenfailed=FalsePass        exceptexception,e:self.isopenfailed=True Self.xlrd_object=NonePrint(e)Pass        finally:            " " do nothing" "            Pass        return[Self.isopenfailed,self.xlrd_object]defDump_sheet (self):ifself.isopenfailed = =False:" "Dump the sheet usging for getting the sheet table = data.sheets () [0] Table = Data.sheet_by_index (0) Table = data.sheet_by_name (U ' Sheet1 ')" "             forNameinchself.xlrd_object.sheet_names (): Table=self.xlrd_object.sheet_by_name (name)Print("sheet%s rownums=%d colnums=%d"%(name,table.nrows,table.ncols))Else:            Print("file%s is not open \ n"%self.xls_name)defDump_cell (self,sheet_index,cell_row,cell_col):" "sheet_index Cell_row Cell_col" "        Try: Table=self.xlrd_object.sheet_by_index (0) value=Table.cell (cell_row,cell_col). ValuereturnvaluePass        except:            Print('Dump_cell,error')     classxlsengine_wt ():def __init__(self,file): Self.xls_name=file Self.xlwt_object=None Self.xlwt_sheet=None self.isopenfailed=TruedefOpen (self):Try: Self.xlwt_object=XLWT. Workbook () self.isopenfailed=Falseexceptexception,e:PrintedefAdd_sheet (self,sheet_name):" "Create A sheet to the XLS" "        Try: Self.xlwt_object=XLWT. Workbook () Self.xlwt_sheet= Self.xlwt_object.add_sheet (sheet_name,cell_overwrite_ok=True) self.xlwt_sheet.write (0,0,'WSDL') self.xlwt_sheet.write (0,1,u'Method') self.xlwt_sheet.write (0,2,'DATA') self.xlwt_sheet.write (0,3,u'Expected results') self.xlwt_sheet.write (0,6,7'Execution Results')        exceptexception,e:Print(e)defGet_sheet (self,sheet_index):Try: Self.xlwt_object=XLWT. Workbook () Self.xlwt_sheet=Self.xlwt_object.get_sheet (Sheet_index)exceptexception,e:Print(e)defWrite (self,row,col,value):" "Write value to (Row,col)" "        Try: Self.xlwt_sheet.write (row,col,value)exceptexception,e:Print(e)defSave_xls (self):" "Save the change to Xlsfile" "        Try: Self.xlwt_object.save (self.xls_name)exceptexception,e:Print(e)defSet_fontcolour (self,colour_index): Fnt=XLWT. Font () Fnt.colour_index=Colour_index Fnt.bold=True Style=XLWT. Xfstyle () Style.font=fntreturnstyledefWrite_result (self,row,list,index_list,as_value=True):" "Row rows, list result lists, Index_list fill in the index of values in the data list, display the calling interface address in the WSDL results, as_value the expected result" "Self.write (Row,0,str (list[index_list][0])) self.write (row,1,str (list[index_list][1]) self.write (row,2,str (list[index_list][2]) self.write (row,3,bool (list[index_list][3]))        if(bool (list[index_list][3]) ==as_value):#whether the expected result is trueSelf.xlwt_sheet.write (Row,4,str (as_value) +'_success', Self.set_fontcolour (3))#colour_index=3, Green, through        Else: Self.xlwt_sheet.write (Row,4,str (As_value) +'_fail', Self.set_fontcolour (2))#colour_index=2, red, failed    defwrite_resultred (SELF,ROW,LIST,INDEX_LIST,WSDL): Self.write (Row,0,str (list[index_list][0]))#WSDL AddressSelf.write (Row,1,str (list[index_list][1]))#Method NameSelf.write (Row,2,str (list[index_list][2]))#Incoming parameters (use cases)Self.write (Row,3,bool (list[index_list][3]))#Expected resultsSelf.xlwt_sheet.write (row,4,'Unkonw_fail', Self.set_fontcolour (2))#colour_index=2, Red, failed (execution result)
View Code

2.vipsoap.py

# !/usr/bin/python # Coding:utf-8  from Import Client class Service:     def __init__ (self,wsdl):        self.client=Client (WSDL)    def  Method (self,dict):        result=Self.client.service.Method (dict)        return result
View Code

3.dataengine.py

__author__='Yanghaitao' fromXlsengineImportXlsengine_rdImportloggingcount_rows=1defdata2list (file,sheet_index): Data=xlsengine_rd (file) data.xlrd_open () sheet=Data.xlrd_object.sheet_by_index (sheet_index) rows=sheet.nrows result_list=[]     forIinchrange (rows):if(I! =0): Result_list.append (Sheet.row_values (i))returnresult_listdefResultcheck (test_rep,xlw,list,xls_row):Globalcount_rowsif(Test_rep. Success = =True): Xlw.write_result (count_rows,list,xls_row,true) count_rows=count_rows+1elif(Test_rep. Success = =False): Logging.writelog (str (list[xls_row][1]), Test_rep) Xlw.write_result (count_rows,list,xls_row,false) count_rows=count_rows+1Else: Logging.writelog (str (list[xls_row][1]), Test_rep) xlw.write_resultred (count_rows,list,xls_row) count_rows=count_rows+1
View Code

4.logging.py

#!/usr/bin/python#Coding:utf-8ImportLogging,timeImportsysreload (SYS) sys.setdefaultencoding ("Utf-8") Logging.basicconfig ( level=logging.info, Format='% (asctime) s% (filename) s[line:% (Lineno) d] "% (levelname) S"% (message) s', Datefmt='%a,%d%b%Y%h:%m:%s', filename=r". \log\service"+time.strftime (R'%y-%m-%d', Time.localtime (Time.time ())) +". Log", FileMode='a') Console=logging. Streamhandler () Logging.getlogger ('suds.client'). AddHandler (console)defWritelog (methodname,result):" "Write Log" "content= methodname +"\ n"         forIteminchresult:content=content+'\t|'+str (item)ifResult. success==False:logging.error (content)defwriteexception (msg):" "Write Log" "Logging.error (""Catch Exception""+STR (msg))
View Code

Python Interface Automation test (ii)

Related Article

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.