Äú¿ÉÒÔ¾èÖú£¬Ö§³ÖÎÒÃǵĹ«ÒæÊÂÒµ¡£

1Ôª 10Ôª 50Ôª





ÈÏÖ¤Â룺  ÑéÖ¤Âë,¿´²»Çå³þ?Çëµã»÷Ë¢ÐÂÑéÖ¤Âë ±ØÌî



  ÇóÖª ÎÄÕ ÎÄ¿â Lib ÊÓÆµ iPerson ¿Î³Ì ÈÏÖ¤ ×Éѯ ¹¤¾ß ½²×ù Model Center   Code  
»áÔ±   
   
 
     
   
 ¶©ÔÄ
  ¾èÖú
python½Ó¿Ú×Ô¶¯»¯ÊµÕ½£¨¿ò¼Ü£©
 
  8324  次浏览      28
 2019-3-15 
 
±à¼­ÍƼö:
±¾ÎÄÀ´×Ôcnblogs£¬ÎÄׯÖ÷Òª½²½âÁË¿ò¼ÜµÄ˼·£¬ÌáÈ¡²âÊÔÓÃÀý£¬²âÊÔ±¨¸æ£¬ÅäÖÃÎļþ£¬ÓÃÀýÉè¼Æ£¬ÓÃÀý±àдµÈÄÚÈÝ¡£

python½Ó¿Ú²âÊÔµÄÔ­Àí£¬¾Í²»½âÊÍÁË£¬°Ù¶ÈÒ»´ó¶Ñ¡£

ÏÈ¿´Ä¿Â¼£¬¿ÉÄÜÕâ¸ö¿ò¼Ü±È½Ï¼òµ¥£¬µ«ÊÇÂéȸËäСÎåÔà¾ãÈ«¡£

¸÷¸öÎļþ¼ÐϵÄÎļþÈçÏ£º

Ò».ÀíÇå˼·

ÎÒÕâ¸ö×Ô¶¯»¯¿ò¼ÜҪʵÏÖʲô

1.´ÓexcelÀïÃæÌáÈ¡²âÊÔÓÃÀý

2.²âÊÔ±¨¸æµÄÊä³ö£¬²¢ÇÒ²âÊÔ±¨¸æµÃ°üÀ¨Ö´ÐеIJâÊÔÓÃÀýµÄÊýÁ¿¡¢³É¹¦µÄÊýÁ¿¡¢Ê§°ÜµÄÊýÁ¿ÒÔ¼°ÄÄÌõ³É¹¦ÁË£¬Ê§°ÜµÄÊÇÄÄÒ»¸ö£¬Ê§°ÜµÄÔ­ÒòÊÇʲô£»²âÊÔ½á¹ûµÄ×ÜÌåÇé¿öͨ¹ýͼ±íÀ´±íʾ¡£

3.²âÊÔ±¨¸æÓÃʲôÐÎʽÊä³ö£¬excel£¬»¹ÊÇhtml£¬»¹ÊÇÆäËûµÄ£¬ÕâÀïÎÒÑ¡ÔñÁËexcel

4.ÅäÖÃÎļþÐèÒªÅäÖÃʲô¶«Î÷

5.ÄÄЩ¶«Î÷¿ÉÒÔ·ÅÈ빫¹²º¯ÊýÖ±½Óµ÷Óá£

ºÃµÄÕâЩ˼·ÀíÇå³þÖ®ºó¾Í¿ÉÒÔ¶¯ÊÖÁË¡£

¶þ.Ê×ÏÈÊÇÅäÖÃÎļþºÍexcel²âÊÔÓÃÀýµÄÉè¼Æ

Êý¾ÝÓë´úÂë·ÖÀ룬Ҳ¾ÍÊÇÊý¾ÝÐÔµÄÐèÒª×÷ΪÅäÖÃÎļþ¿ÉÒÔËæÊ±Ð޸ġ£È磺½Ó¿Úurl£¬ÍøÕ¾µÇ¼ȨÏÞÑéÖ¤ÐÅÏ¢£¬Êý¾Ý¿âÐÅÏ¢¡£È«²¿´æÈëconfigÎļþ¼ÐÏÂ

ÏÂÃæÊǾßÌåµÄÅäÖÃÎļþÐÅÏ¢£º

API_url.txt


inserthouse=http://IP:port/scp-mdmapp/house/insertHouse
deletehouse=http://IP:port/scp-mdmapp/house/deleteHouse
batchdeletehouse=http://IP:port/scp-mdmapp/house/batchdeleteHouse
gethouse=http://IP:port/scp-mdmapp/house/getHouse
updatehouse=http://IP:port/scp-mdmapp/house/updateHouse

 

Authorization.txt

joxNTIxMTg3MTA3fQ.JyeCMMsM0tOr7exORUNpkZ -FtprjpNBhMtFjUAdnYDnhRfaR6qi3fq Vkybyb245zONiTxLOw8jBR60oNUVEbKx9 _cut6uDIZMUFYOx6hyyBkY9IXJlutYdo4sSMAKF _MjKsZY7bZNXLHzN0juiezn6iN0hbnbhS -Kv2LYLLZLTs

ÎҵIJâÊÔÓÃÀýµÄÉè¼ÆÈçÏ£º

notesÊDzâÊÔÓÃÀýÕªÒª¡£

Èý.¹«¹²º¯Êý´æÔÚcommonÎļþ¼ÐÏÂ

get_authorization.py


#´ÓÅäÖÃÎļþ»ñÈ¡·ÃÎÊȨÏÞÐÅÏ¢
def get_Authorization():
fp = ope n('D:\person\learn\py\HDapi \config\Authorization.txt')
info = fp.read()
fp.close()
return info

 

public.py

import os,xlrd,xlwt,time

#ͨ¹ýÅäÖÃÎļþÀïµÄ½Ó¿ÚÃû³ÆÀ´»ñÈ¡½Ó¿ÚurlµÄº¯Êý
def get_url(api_name):
fp = open('D:\person\learn\py\HDapi\config\API_url.txt')
#°´ÐжÁÈ¡½Ó¿ÚurlÅäÖÃÎļþ
api_infos = fp.readlines()
fp.close()
#ͨ¹ýforÑ­»·À´±éÀúÅäÖÃÎļþÀïµÄÿһ¸öurl£¬²¢ÇÒ·µ»Ø´«ÈëµÄ½Ó¿ÚÃû³ÆÏàÓ¦µÄurl
for api in api_infos:
#È¥³ýÒòΪ¶ÁÈ¡²úÉúµÄ»»ÐпոñµÈ
api_f = api.strip(' \r\n\t')
api_c = api_f.split('=')
if api_name == api_c[0]:
return api_c[1]

#ͨ¹ý´«ÈëÓÃÀýÃû³ÆµÄÎļþºÍexcelÒ³ÃæÀ´¶ÁÈ¡²âÊÔÓÃÀý
def get_case(filename,sheetnum):
case_dir='D:\\person\\learn\\py\\HDapi\\testcase_excel' + '\\' + filename + '.xlsx'

datas = xlrd.open_workbook(case_dir)
table = datas.sheets()[sheetnum]
nor = table.nrows
nol = table.ncols
return nor,table

#ͨ¹ýxlwt¿âÀ´Éè¼Æ²âÊÔ±¨¸æ²¢Ð´ÈëexcelÀïÃæ
def write_report():
workbook = xlwt.Workbook(encoding='utf-8')
#ÔÚexcel²âÊÔ±¨¸æ±í¸ñÖд´½¨Ãû½ÐhousemanageµÄÒ³Ãæ
worksheet = workbook.add_sheet('housemanage')
#ÉèÖÃ×ÖÌå¸ñʽΪ¾ÓÖÐ¶ÔÆë
alignment = xlwt.Alignment()
alignment.horz = alignment.HORZ_CENTER
alignment.vert = alignment.VERT_CENTER
style = xlwt.XFStyle()
style.alignment = alignment

#¾ßÌåµÄºÏ²¢ÄÄЩµ¥Ôª¸ñ²¢ÇÒдÈëÏàÓ¦µÄÐÅÏ¢
worksheet.write_merge(0,0,0,7,'²âÊÔ±¨¸æ(housemanage)',style)
worksheet.write_merge(1,10,0,0,'house_manage',style)
worksheet.write_merge(1,2,1,1,'insethouse',style)
worksheet.write_merge(3,4,1,1,'updatehouse',style)
worksheet.write_merge(5,6,1,1,'deletehouse',style)
worksheet.write_merge(7,8,1,1,'gethouse',style)
worksheet.write_merge(9,10,1,1,'updatehouse',style)
worksheet.write_merge(1,2,11,11,'total_result',style)
worksheet.write(1,2,'notes')
worksheet.write(2,2,'detail')
worksheet.write(3,2,'notes')
worksheet.write(4,2,'detail')
worksheet.write(5,2,'notes')
worksheet.write(6,2,'detail')
worksheet.write(7,2,'notes')
worksheet.write(8,2,'detail')
worksheet.write(9,2,'notes')
worksheet.write(10,2,'detail')
worksheet.write(1,12,'pass')
worksheet.write(1,13,'faild')
#×îºó·µ»Øworksheet,workbookÁ½¸ö²ÎÊý£¬ÒòΪÔÚ²âÊÔ²âÊÔÓÃÀýºÍÔËÐÐÎļþÖÐÐèÒªÓõ½µÄÁ½¸ö²ÎÊý
return worksheet,workbook---------------------

ËÄ.²âÊÔÓÃÀýµÄ±àд

test_inserthouse.py

import requests,unittest,os,time,json
from common import public,get_authorization


#·¿ÎÝÌí¼ÓÓÃÀý£¬Í¨¹ý´«ÈëpublicÀïwirte_sheetº¯Êý·µ»ØµÄ²ÎÊýwooksheet£¬½«ÓÃÀýµÄÖ´Ðнá¹ûдÈëµ½²âÊÔ±¨¸æÖÐ
def test_inserthouses(worksheet,workbook):
url = public.get_url('inserthouse')
nor,table = public.get_case('house',0)
Authorization = get_authorization.get_Authorization()
a = 2
xu = 0
yu = 0
#ÓÃforÑ­»·À´ÊµÏÖ±éÀúÒ»¸öexcelÒ³ÃæµÄËùÓвâÊÔÓÃÀý
for i in range(1,nor):
#»ñÈ¡excel±í¸ñÀïÃæÐèÒª¸ø½Ó¿Ú´«ÈëµÄ²ÎÊý
houseNum = table.cell_value(i,0)
orgUuid = table.cell_value(i,1)
floor = table.cell_value(i,2)
houseUseFor = table.cell_value(i,3)
residentNum = table.cell_value(i,4)
emergencyPhone = table.cell_value(i,5)
expect_code = table.cell_value(i,6)
expect_message = table.cell_value(i,7)
notes = table.cell_value(i,8)
payment = table.cell_value(i,11)
#½Ó¿ÚbodyÐèÒª´«ÈëµÄ²ÎÊý
data = {
'houseNum':houseNum,
'houseUseFor':houseUseFor,
'orgUuid':orgUuid,
'residentNum':residentNum,
'floor':floor,
'emergencyPhone':emergencyPhone,
'payment':payment
}

#ÇëÇóÍ·£¬ÍøÕ¾¼ÓÁ˵ǽÑéÖ¤Ö®ºóÐèÒªÔÚÇëÇóÍ·´«ÈëAuthorization²ÎÊý
headers={
'Accept':'application/json',
'Content-Type':'application/json',
'Authorization':Authorization
}
a+=1
worksheet.write(1,a,notes)

data = json.dumps(data)

r = requests.post(url,data=data,headers=headers)
#½«×Ö·û´®¸ñʽת»»Îª×Öµä
b = eval(r.text)
m = b.get('code')
n = b.get('message')
k = b.get('data')
#ÅжϽӿڲâÊÔͨ¹ýÓë·ñ
if m==expect_code and n==expect_message:
worksheet.write(2,a,'pass')
xu += 1
else:
worksheet.write(2,a,'faild:%s'%k)
yu += 1
#²âÊÔÓÃÀýÖ´ÐÐÍêºó£¬·µ»ØÓÃÀý³É¹¦Óëʧ°ÜµÄÊýÁ¿
return xu,yu
# now = time.strftime('%Y-%m-%d %H_%M_%S')
# report_dir = 'D:\\person\\learn\\py\\HDapi\\report\\'
# filename =report_dir + now + 'apiresult.xlsx'
# workbook.save(filename)

test_updatehouse.py

import requests,unittest,os,time,json
from common import public,get_authorization

#·¿Îݱ༭²âÊÔÓÃÀý
def test_updatehouses(worksheet,workbook):
nor,table = public.get_case('house',4)
Authorization = get_authorization.get_Authorization()
url = public.get_url('updatehouse')
a = 2
x = 0
y = 0
for i in range(1,nor):
houseNum = table.cell_value(i,0)
orgUuid = table.cell_value(i,1)
uuid = table.cell_value(i,2)
houseUseFor = table.cell_value(i,3)
residentNum = table.cell_value(i,4)
emergencyPhone = table.cell_value(i,5)
expect_code = table.cell_value(i,6)
expect_message = table.cell_value(i,7)
notes = table.cell_value(i,8)
floor = table.cell_value(i,9)
payment = table.cell_value(i,11)

data = {
'houseNum':houseNum,
'houseUseFor':houseUseFor,
'orgUuid':orgUuid,
'floor':floor,
'residentNum':residentNum,
'uuid':uuid,
'emergencyPhone':emergencyPhone,
'payment':payment
}

headers={
'Accept':'application/json',
'Content-Type':'application/json',
'Authorization':Authorization
}

a+=1
worksheet.write(3,a,notes)

data = json.dumps(data)

r = requests.post(url,data=data,headers=headers)
b = eval(r.text)
m = b.get('code')
n = b.get('message')
k = b.get('data')
if m==expect_code and n==expect_message:
worksheet.write(4,a,'pass')
x += 1
else:
worksheet.write(4,a,'faild:%s'%k)
y += 1
return x,y---------------------

Îå.ͨ¹ý¶Ô¹«¹²º¯Êý¡¢²âÊÔÓÃÀýµÄÉè¼ÆÁªºÏµÄ˼¿¼Ó¦¸ÃÔÚÖ´ÐÐÎļþÀïÃæ×öʲô£¬ÊµÏÖʲô¡£

±¾À´ÎÒÏ뽫ִÐÐÎļþµ¥¶À·ÅÖÃÓÚHDapi-auto-testµÄ¸ùÎļþÏµģ¬¿ÉÊǽ«²âÊÔͨ¹ýÓ벻ͨ¹ýµÄÊýÁ¿Ð´Èëµ½²âÊÔ±¨¸æÀïÃæ£¬¾Í±ØÐëÒªµ÷Óù«¹²º¯ÊýµÄ·½·¨£¬ÓÉÓÚ·ÅÖÃÔÚ¸ùÎļþ¼ÐÏÂÓ빫¹²º¯Êý¸ôÁËÒ»¸öÎļþ¼ÐÎÞ·¨µ÷Ó㨠±¾Äñ²»»áµ÷Óã©£¬ËùÒÔ²»µÃ²»½«Ö´ÐÐÎļþ·ÅÖÃÓÚ²âÊÔÓÃÀýÎļþ¼ÐÏÂÁË£¬ºÃÔÚÎļþÃû»¹ÊDZȽϺÃÇø·ÖÒ²±È½ÏºÃѰÕÒ£¬ÁíÍâÎÒ»¹Ïë¼ÓÉÏ×Ô¶¯·¢ËÍÓʼþµÄ¹¦ÄÜ£¬ÕâÀﲻдÁË£¬Æäʵ·¢ËÍÓʼþºÜ¼òµ¥Ëæ±ãÕÒ¼¸¸öÀý×Ó¾ÍOKÁË£¬ps:´úÂë±È½Ïlow£¬¶¼Ã»Óзâ×°£¬Ö±½Ó±©Á¦¼òµ¥Ö´ÐС£´úÂëÈçÏ£º


# utf-8
from common import public
import test_inserthouse,test_updatehouse
import time
from pychartdir import *
#´Ó¹«¹²º¯Êýµ÷ÓÃexcelµÄдÈë·½·¨
worksheet,workbook = public.write_report()

#²âÊÔÓÃÀýµÄÖ´ÐУ¬²¢ÇÒ·µ»Øx:³É¹¦µÄÊýÁ¿£¬y£ºÊ§°ÜµÄÊýÁ¿
xu,yu = test_inserthouse.test_inserthouses(worksheet,workbook)
x,y = test_updatehouse.test_updatehouses(worksheet,workbook)
#µÃµ½³É¹¦Óëʧ°ÜµÄ×ÜÊýÁ¿
xr = x+xu
yr = y+yu
#½«³É¹¦Óëʧ°ÜµÄÊýÁ¿Ð´ÈëµÄexcelµÄ¹Ì¶¨±í¸ñÖÐ
worksheet.write(2,12,xr)
worksheet.write(2,13,yr)
#»ñÈ¡µ±Ç°µÄʱ¼ä²¢ÒÔÖÆ¶¨µÄ¸ñʽ·µ»Ø
now = time.strftime('%Y-%m-%d %H_%M_%S')
#²âÊÔ±¨¸æÊä³öµÄµØÖ·
report_dir = 'D:\\person\\learn\\py\\HDapi\\report\\'
#Æ´½Ó³ö²âÊÔ±¨¸æÃû
filename =report_dir + now + 'apiresult.xlsx'
workbook.save(filename)

#ͨ¹ýpychart¿âʵÏÖͼÐδ¦Àí£¬Éú³É²âÊÔ±¨¸æ×ÜÀÀͼ----¾ßÌåµÄ²ÎÊýÉè¼Æ¿ÉÒԲο¼pychart¿âµÄÎĵµ
data = [yr, xr]
labels = ["faild", "pass"]
c = PieChart(280, 240)
c.setPieSize(140, 130, 80)
c.addTitle("api_result")
c.set3D()
c.setData(data, labels)
c.setExplode(0)---------------------

Áù.·îÉϲâÊÔ±¨¸æÊä³ö

±¾À´Ï뽫Éú³ÉµÄͼƬ·Å½øexcel²âÊÔ±¨¸æÀïÃæµÄ£¬ÄκÎÄÜÁ¦ÓÐÏÞ£¬Ã»°ì·¨½«Í¼Æ¬·Å½øÈ¥£¬ÖÇÄܵ¥¶À´æÎªÒ»¸öpngÎļþÁË

ͼ±í×ÜÀÀ£º

excel²âÊÔ±¨¸æÇé¿ö£º

   
8324 ´Îä¯ÀÀ       28
Ïà¹ØÎÄÕÂ

΢·þÎñ²âÊÔÖ®µ¥Ôª²âÊÔ
һƪͼÎÄ´øÄãÁ˽â°×ºÐ²âÊÔÓÃÀýÉè¼Æ·½·¨
È«ÃæµÄÖÊÁ¿±£ÕÏÌåϵ֮»Ø¹é²âÊÔ²ßÂÔ
È˹¤ÖÇÄÜ×Ô¶¯»¯²âÊÔ̽Ë÷
Ïà¹ØÎĵµ

×Ô¶¯»¯½Ó¿Ú²âÊÔʵ¼ù֮·
jenkins³ÖÐø¼¯³É²âÊÔ
ÐÔÄܲâÊÔÕï¶Ï·ÖÎöÓëÓÅ»¯
ÐÔÄܲâÊÔʵÀý
Ïà¹Ø¿Î³Ì

³ÖÐø¼¯³É²âÊÔ×î¼Ñʵ¼ù
×Ô¶¯»¯²âÊÔÌåϵ½¨ÉèÓë×î¼Ñʵ¼ù
²âÊԼܹ¹µÄ¹¹½¨ÓëÓ¦ÓÃʵ¼ù
DevOpsʱ´úµÄ²âÊÔ¼¼ÊõÓë×î¼Ñʵ¼ù