is there a way to attach file using xmlrpc?

1.8 related questions and discussions.
Please upgrade to LATEST 1.9.x.
No more fixes for 1.8.

Moderators: Amaradana, TurboPT, TL Developers

Locked
josri
Advanced user
Posts: 30
Joined: Fri Jun 12, 2009 9:39 pm

is there a way to attach file using xmlrpc?

Post 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
partymungo
Advanced user
Posts: 20
Joined: Thu Aug 21, 2008 12:45 pm

Post 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.
josri
Advanced user
Posts: 30
Joined: Fri Jun 12, 2009 9:39 pm

Post by josri »

Thank you for the response. Didn't think of that :) Sure, can you share the script?

Jo
partymungo
Advanced user
Posts: 20
Joined: Thu Aug 21, 2008 12:45 pm

Post by partymungo »

Hi,
maybe not very fine ..... but it works (for my purpose) :lol:

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
josri
Advanced user
Posts: 30
Joined: Fri Jun 12, 2009 9:39 pm

Post by josri »

Thank you very much. Will try that.
Locked