使用Python读取TestTrack记录- Part1

来源:互联网 发布:centos配置ip地址 编辑:程序博客网 时间:2024/05/30 07:11

background:

注:以下代码均是下班回家之后,凭记忆随手写的工作记录,留作日后查询之用,对准确性概不负责。

开发一个系统,能够实时对TestTrack Server中所有人员的工作量化展现和工作量对比,采用scrum思想开发,本着高内聚低耦合的思想,将系统分为三部分:TTExport + Calc +Website三个模块。

1. TTExport模块,负责导出指定project的某一范围的TT记录,即Defect

- 使用python编写export 脚本,之所以选择python而不是C#,是因为TT里面wsdl中日期类型为date而不是.net中datetime类型,要使用C#只能在TT Server上修改WSDL文件,这样会导致其他语言无法以默认的语法访问TT server,放弃C#,采用python,同时也是逼迫自己学写python

2. Calc模块,使用Linq to xml,计算指定条件下的筛选数值

- 使用Linq to xml

- int GetNumInPeriod(XElement element, string creater, string assigned, string status)

3. Website模块

- 采用MSChart显示图

- 提示用户是否同步最新TT记录,否则读取上次同步时保存在本地的xml,降低对TT server的访问量

issue:

使用python编写脚本读取TestTrack,生成xml并导出(类似于手动选择某个project下的某些TT记录,通过File->Export功能导出,但貌似TT没有提供API接口,只好自己编写)


solution:

使用server.service.DatabaseLogon(dbname, user, password)登陆TT serever,使用GetRecordListForTable获取所有的record(Defect),通过获取的record[0]获取到defect number,调用server.service.getDefect来获取指定defect


Code

# create a connection to TT serverserver = suds.client.Client("http://10.7.88.11/ttsoapcgi.wsdl")# fetch all the projects you have access to.database_name = "TLBB"username = 'administrator'password = ""#logincookie = server.service.DatabaseLogon(database_name, username, password)try:    #fetch all the defect    rows = server.service.getRecordListForTable(cookie, "Defect")    for record in rows.Records:        # fectch specific defect using given defect number        defect = server.service.getDefect(cookie, record[0].value, bDownloadAttachments=False)        if defect.__dict__.hasKey("recordid"):            recordid = defect.__dict__["recordid"]        if defect.__dict__.hasKey("summary"):            summary = defect.__dict__["summary"]        # todo: get all the property of target defect instance        except:finally:    response = server.service.DatabaseLogoff(cookie)