QA/Testopia/XmlRpcReporting

From FedoraProject

< QA
Jump to: navigation, search
#!/usr/bin/python

import random
import os
import time

# We'll be working with nested dictionaries etc, so we'll want pretty-printing
# support to keep us sane:
from pprint import pprint

from testopia import Testopia

import xmlrpclib
from cookielib import MozillaCookieJar
from bugzilla import *

url = "https://publictest2.fedoraproject.org/bugzilla/xmlrpc.cgi"
cookies = "cookies.txt"

cookieServerProxy = xmlrpclib.ServerProxy('https://publictest2.fedoraproject.org/bugzilla/tr_xmlrpc.cgi',
                                          transport=SafeCookieTransport(),
                                          verbose = False) # or True
# Point it at your browser cookies.
# It can corrupt the file, so point it at a copy:
cookieServerProxy._ServerProxy__transport.cookiejar = MozillaCookieJar('cookies.txt')
cookieServerProxy._ServerProxy__transport.cookiejar.load() # needed for some reason

# a cookie-based implementation
t = Testopia('foo', 'bar')
t.server = cookieServerProxy

build       = '2.6.25.6-58.fc9.i686'
product     = 'Rawhide'
test_plan   = 'Kernel Tier1'
environment = 'x86_64'

# OK, should be able to use the interface to xmlrpc:
print "Lookup userid.."
my_id = 6
print "Lookup testplan id.."
testplan_id = t.testplan_list(name=test_plan)[0]['plan_id']
print "Lookup product id.."
product_id  = t.product_check_by_name(product)['id']
print "Lookup build id.."
try:
   build_id = t.build_check_by_name(build,product_id)['build_id']
except:
   build_id = t.build_create(build,product_id)['build_id']
print "Lookup environment id.."
try:
   environment_id = t.environment_check_by_name(environment,product_id)['environment_id']
except:
   environment_id = t.environment_create(product_id, True, environment)['environment_id']

print "Product[%s] ID:%s, TestPlan[%s] ID:%s, Build[%s] ID:%s Environment[%s] ID:%s" % (product,product_id,test_plan,testplan_id,build,build_id, environment, environment_id)

# Create the Test run..
testrun = t.testrun_create(build_id, environment_id, testplan_id, 'Summary',my_id)
# Update the Test run to "Running" status
t.testrun_update(testrun['run_id'],1,build_id,environment_id,my_id)
for testcase in t.testplan_get_test_cases(testplan_id):
   print "Create test case %s" % testcase['summary']
   testcaserun = t.testcaserun_create(my_id, build_id, testcase['case_id'],
                                      environment_id, testrun['run_id'])
   print "running..."
   t.testcaserun_update(testrun['run_id'], testcase['case_id'], build_id,
                        environment_id, case_run_status_id=4)
   time.sleep(10)
   status = random.randrange(2,4)
   print "Filing status %s" % status
   t.testcaserun_update(testrun['run_id'], testcase['case_id'], build_id,
                        environment_id, case_run_status_id=status)
   
# Update the Test run to "Stopped" status
t.testrun_update(testrun['run_id'],0,build_id,environment_id,my_id)