summaryrefslogtreecommitdiffstats
path: root/selftest.py
blob: a7fbe57363033a68e50cdd1acc0ed09d1eb018d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python
# Simple self-test of the bugzilla module

from bugzilla import Bugzilla
import os, glob

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]

def selftest():
    url = 'https://bugzilla.redhat.com/xmlrpc.cgi'
    cookies = find_firefox_cookiefile()
    public_bug = 1
    private_bug = 250666
    print "Woo, welcome to the bugzilla.py self-test."
    print "Using bugzilla at " + url
    print "Reading cookies from " + cookies
    b = Bugzilla(url=url,cookies=cookies)
    print "Reading product list"
    print b.products()
    print "Reading public bug (#%i)" % public_bug
    print b.getbugsimple(public_bug)
    print "Reading private bug (#%i)" % private_bug
    try:
        print b.getbugsimple(private_bug)
    except xmlrpclib.Fault, e:
        if 'NotPermitted' in e.faultString:
            print "Failed: Not authorized."
        else:
            print "Failed: Unknown XMLRPC error: %s"  % e
    print "Awesome. We're done."

if __name__ == '__main__':
    selftest()