From 35f9cb409068820018480408376e2c4332d1f315 Mon Sep 17 00:00:00 2001 From: Will Woods Date: Tue, 10 Jun 2008 11:06:57 -0400 Subject: Fix up selftest a bit --- selftest.py | 117 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 65 insertions(+), 52 deletions(-) diff --git a/selftest.py b/selftest.py index 30f212d..b2622f7 100755 --- a/selftest.py +++ b/selftest.py @@ -14,81 +14,94 @@ from bugzilla import Bugzilla import os, glob, sys import xmlrpclib -def find_firefox_cookiefile(): - cookieglob = os.path.expanduser('~/.mozilla/firefox/*default*/cookies.txt') - cookiefiles = glob.glob(cookieglob) - if cookiefiles: - # TODO return whichever is newest - return cookiefiles[0] +bugzillas = { + 'Red Hat':{ + 'url':'https://bugzilla.redhat.com/xmlrpc.cgi', + 'public_bug':1, + 'private_bug':250666, + 'bugidlist':(1,2,3,1337), + 'query':{'product':'Fedora', + 'component':'kernel', + 'version':'rawhide'} + }, + 'Bugzilla 3.0':{ + 'url':'https://landfill.bugzilla.org/bugzilla-3.0-branch/xmlrpc.cgi', + 'public_bug':1, + 'private_bug':31337, # FIXME + 'bugidlist':(1,2,3,4433), + 'query':{'product':'WorldControl', + 'component':'WeatherControl', + 'version':'1.0'} + }, + } + +# TODO: add data for these instances +# 'https://landfill.bugzilla.org/bugzilla-3.2-branch/xmlrpc.cgi' - BZ3.2 +# 'https://partner-bugzilla.redhat.com/xmlrpc.cgi' - BZ3.2/RH hybrid -def selftest(user='',password=''): - url = 'https://partner-bugzilla.redhat.com/xmlrpc.cgi' - public_bug = 1 - private_bug = 250666 - bugidlist = (1,2,3,1337,123456) - query = {'product':'Fedora', - 'component':'kernel', - 'version':'devel', - 'long_desc':'wireless'} - - print "Woo, welcome to the bugzilla.py self-test." - print "Using bugzilla at " + url - if user and password: - print 'Using username "%s", password "%s"' % (user,password) - bz = Bugzilla(url=url,user=user,password=password) +def selftest(data,user='',password=''): + print "Using bugzilla at " + data['url'] + bz = Bugzilla(url=data['url']) + print "Bugzilla class: %s" % bz.__class__ + if not bz.logged_in: + if user and password: + bz.login(user,password) + if bz.logged_in: + print "Logged in to bugzilla OK." else: - cookies = find_firefox_cookiefile() - if not cookies: - print "Could not find any cookies for that URL!" - print "Log in with firefox or give me a username/password." - sys.exit(1) - print "Reading cookies from " + cookies - bz = Bugzilla(url=url,cookies=cookies) + print "Not logged in - create a .bugzillarc or provide user/password" + # FIXME: only run some tests if .logged_in + print "Reading product list" - print bz.getproducts() - print + prod = bz.getproducts() + k = sorted(prod.keys()) + print "Products found: %s, %s, %s...(%i more)" % (k[0],k[1],k[2],len(k)-3) - print "Reading public bug (#%i)" % public_bug - print bz.getbugsimple(public_bug) + print "Reading public bug (#%i)" % data['public_bug'] + print bz.getbugsimple(data['public_bug']) print - print "Reading private bug (#%i)" % private_bug + print "Reading private bug (#%i)" % data['private_bug'] try: - print bz.getbugsimple(private_bug) + print bz.getbugsimple(data['private_bug']) except xmlrpclib.Fault, e: if 'NotPermitted' in e.faultString: print "Failed: Not authorized." else: print "Failed: Unknown XMLRPC error: %s" % e - q_msg = "%s %s %s %s" % (query['product'],query['component'], - query['version'],query['long_desc']) print - print "Reading multiple bugs, one-at-a-time: %s" % str(bugidlist) - for b in bugidlist: - print bz.getbugsimple(b) + print "Reading multiple bugs, one-at-a-time: %s" % str(data['bugidlist']) + for b in data['bugidlist']: + print bz.getbug(b) print - print "Reading multiple bugs, all-at-once: %s" % str(bugidlist) - for b in bz.getbugssimple(bugidlist): + print "Reading multiple bugs, all-at-once: %s" % str(data['bugidlist']) + for b in bz.getbugs(data['bugidlist']): print b print - print "Querying %s bugs" % q_msg - bugs = bz.query(query) - print "%s bugs found." % len(bugs) - for bug in bugs: - print "Bug %s" % bug + print "Querying: %s" % str(data['query']) + try: + bugs = bz.query(data['query']) + print "%s bugs found." % len(bugs) + for bug in bugs: + print "Bug %s" % bug + except NotImplementedError: + print "This bugzilla class doesn't support query()." print - print "Awesome. We're done." - if __name__ == '__main__': user = '' password = '' if len(sys.argv) > 2: (user,password) = sys.argv[1:3] - try: - selftest(user,password) - except KeyboardInterrupt: - print "Exiting on keyboard interrupt." + + print "Woo, welcome to the bugzilla.py self-test." + for name,data in bugzillas.items(): + try: + selftest(data,user,password) + except KeyboardInterrupt: + print "Exiting on keyboard interrupt." + break + print "Awesome. We're done." -- cgit