diff options
author | Will Woods <wwoods@redhat.com> | 2008-09-04 14:04:44 -0400 |
---|---|---|
committer | Will Woods <wwoods@redhat.com> | 2008-09-04 14:04:44 -0400 |
commit | bcb002af27ee4a224be7578ded886471231e598e (patch) | |
tree | da21e70d6243862417b99a7efff1786340ae64e9 /selftest.py | |
parent | 041a27dbc66b007f2e4c7132c229f14af5163982 (diff) | |
parent | ce753c44a0445b796cd19851cba8dff2e5d455d0 (diff) | |
download | python-bugzilla-bcb002af27ee4a224be7578ded886471231e598e.tar.gz python-bugzilla-bcb002af27ee4a224be7578ded886471231e598e.tar.xz python-bugzilla-bcb002af27ee4a224be7578ded886471231e598e.zip |
Merge from abstractify branch
Diffstat (limited to 'selftest.py')
-rwxr-xr-x | selftest.py | 125 |
1 files changed, 73 insertions, 52 deletions
diff --git a/selftest.py b/selftest.py index 30f212d..e378b21 100755 --- a/selftest.py +++ b/selftest.py @@ -14,81 +14,102 @@ 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':427301, + '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':4433, + 'private_bug':6620, # FIXME - does this instance have groups? + '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() + prodlist = [p['name'] for p in prod] + print "Products found: %s, %s, %s...(%i more)" % \ + (prodlist[0],prodlist[1],prodlist[2],len(prodlist)-3) - print "Reading public bug (#%i)" % public_bug - print bz.getbugsimple(public_bug) + p = data['query']['product'] + assert p in prodlist + print "Getting component list for %s" % p + comp = bz.getcomponents(p) + print "%i components found" % len(comp) + + + 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." + sys.exit(1) + print "Awesome. We're done." |