Page 1 of 1
is there a way to attach file using xmlrpc?
Posted: Fri Feb 05, 2010 5:50 pm
by josri
Hi,
I am using Python client. I am able to successfully update the automated testcase results. But is there any way I can upload a file using xmlrpc to testlink if the test fails?
Thank you
Jo
Posted: Mon Feb 08, 2010 9:54 am
by partymungo
Hi,
currently there is noa API call to add an attachement (as i know). Because of that, i use mysql statements to add files to the test case result. Not very fine but it works. If you are interested in, i can provide you with a python script.
Posted: Mon Feb 08, 2010 5:29 pm
by josri
Thank you for the response. Didn't think of that

Sure, can you share the script?
Jo
Posted: Tue Feb 09, 2010 3:05 pm
by partymungo
Hi,
maybe not very fine ..... but it works (for my purpose)
Code: Select all
#! /usr/bin/env python
# Testlevel: Systemtest
# Testclassification: Function
# Testsuite: Remotemanagement
# Main focus:
# Target: Attach testdata to testresult
import MySQLdb
import time
import os
import string
import getopt
import sys
(options, arguments) = getopt.getopt(sys.argv[1:], 't:u:e:')
tcid = options[0][1] #testcase id
uuid = options[1][1] #test uuid
ext = options[2][1] #extension
#some variables
id_ = 0
fk_id = 0
fk_table = 'NULL'
title = 'NULL'
description = 'NULL'
file_name = 'NULL'
file_path = 'NULL'
file_size = 0
file_type = 'NULL'
date_added = 0
content = 0
compression_type = 0
#create ".tgz" which contains ".log", ".xml" and ".txt" files from
# testexecution
os.chdir("/home/tester/BFRM001/result/")
dir_ = os.listdir(os.curdir)
os.popen("tar -cvzf " + uuid + "." + ext + " " + uuid)
# Connect to database and establish cursor
connection = MySQLdb.connect("localhost","admin","","testlink")
cursor = connection.cursor()
#calculate "id", consecutive number
cursor.execute("SELECT id FROM attachments")
rows = cursor.fetchall()
tmp = max(rows)
id_ = tmp[0]+1
#get "fk_id" from table "executions", based on testcase id (tcid)
cursor.execute("SELECT id FROM executions WHERE tcversion_id="+tcid)
rows = cursor.fetchall()
tmp = max(rows)
fk_id = tmp[0]
# set "fk_table"
fk_table = 'executions'
#set "title" to filename
title = uuid
#set "description" to something
description ='Testdata for testrun: '+ uuid
#set "file_name" to filename
file_name = uuid + "." + ext
#set "file_path" to table+fk_id+uuid.extension
file_path = "executions" + "/" + str(fk_id) + "/" + uuid + "." + ext
#set "file_size"
file_size = os.path.getsize(uuid + "." + ext)
#set "file_type" to static value "application/x-compressed-tar"
file_type = 'application/x-compressed-tar'
#set "date_added"
#will be done by "NOW()" statement at insertion time
#set "content", actually to 0 (don't know how to set field of type longblob)
content = 0
#set "compression_type" to static value 1
compression_type = 1
#now we have to copy the file to destination folder .../testlink/upload_area
#/executions/...
path = ".../testlink/upload_area/executions/"+str(fk_id)
os.mkdir(path)
os.popen("cp " + uuid + "." + ext + " " + path)
# finally, add dbentry to database
data = (id_,fk_id,fk_table,title,description,file_name,file_path,file_size,file_type,content, compression_type)
cursor.execute("INSERT INTO attachments VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,NOW(),%s,%s)", data)
I use this script in 1.8.4, you have to check db layout for other version.
regards
Posted: Tue Feb 09, 2010 4:58 pm
by josri
Thank you very much. Will try that.