Created
February 27, 2013 21:32
-
-
Save omaciel/5051929 to your computer and use it in GitHub Desktop.
Generates reports against TCMS Test Plans
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import optparse | |
import xmlrpclib | |
try: | |
from nitrate import * | |
except ImportError: | |
print "Please install python-nitrate and try again: https://github.com/psss/python-nitrate" | |
sys.exit(-1) | |
AUTOMATED = { | |
0: 'Automated', | |
1: 'Manual', | |
2: 'Both', | |
} | |
def _fetch_data(arguments): | |
username = arguments.username | |
password = arguments.password | |
url = arguments.tcms | |
# Construct the server url | |
if url.startswith('https://'): url = url[8:] | |
if url.endswith('/'): url = url[:-1] | |
server_url = "https://%s:%s@%s/" % (username, password, url) | |
try: | |
s = xmlrpclib.ServerProxy(server_url) | |
except Exception, e: | |
print str(e) | |
sys.exit(-1) | |
plan = s.TestPlan.get(arguments.plan) | |
if plan.get('args'): | |
print ''.join(plan.get('args')) | |
sys.exit(-1) | |
print "Test Plan: %s" % plan.get('name') | |
_print_plain(s, plan) | |
def _print_plain(server, plan): | |
testcases = plan.get('case') | |
# Loop through all test cases | |
print "ID\tSummary\tCompo\tUI\tUnk" | |
for test in testcases: | |
cli = ui = unknown = False | |
# Fetch the test object | |
t = server.TestCase.get(test) | |
# We only want tests that have been confirmed | |
if t.get('case_status') == 'CONFIRMED': | |
# Figure out if this is a CLI or UI test | |
c = server.TestCase.get_components(t.get('case_id')) | |
components = [component.get('name') for component in c] | |
# Github task? | |
task = t.get('text').get('breakdown', None) | |
# Get rid of html markup | |
git = task and task[task.rfind('https'):task.find('</a>')].replace('</p', '') or '' | |
print "[%s] - %s\t%s\t%s\t%s" % ( | |
t.get('case_id'), | |
t.get('summary'), | |
components, | |
AUTOMATED[t.get('is_automated')], | |
git, | |
) | |
if __name__ == "__main__": | |
description = "Generates reports against TCMS Test Plans" | |
usage = "Usage: %prog --username <username> --password <password> --tcms <tcms> --plan <plan>" | |
epilog = "Constructive comments and feedback can be sent to Og Maciel <omaciel at ogmaciel dot com>." | |
version = "%prog version 0.1" | |
p = optparse.OptionParser(usage=usage, description=description, epilog=epilog, version=version) | |
p.add_option('-u', '--username', type=str, dest='username', help='Valid username') | |
p.add_option('-p', '--password', type=str, dest='password', help='Valid password') | |
p.add_option('--tcms', type=str, dest='tcms', help='URL for a nitrate server. e.g. https://nitrate.server/xmlrpc/') | |
p.add_option('--plan', type=int, dest='plan', help='The test plan IDs. e.g. 7771') | |
options, arguments = p.parse_args() | |
# Make sure we're passing a test plan | |
if not options.username or not options.password or not options.tcms or not options.plan: | |
p.print_help() | |
sys.exit(-1) | |
_fetch_data(options) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment