Skip to content

Commit 8955a6d

Browse files
committed
tests: Add rw_functional tests
setup.py now has an option --rw-functional to enable these tests. Currently they only run against partner-bugzilla.redhat.com and require a cached RH login for that instance. Tests currently cover 'bugzilla new' functionality.
1 parent e9cbe7f commit 8955a6d

7 files changed

Lines changed: 164 additions & 16 deletions

File tree

bugzilla/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,8 +1271,8 @@ def __init__(self,bugzilla,**kwargs):
12711271
else:
12721272
raise TypeError, "Bug object needs a bug_id"
12731273

1274-
self.url = bugzilla.url.replace('xmlrpc.cgi',
1275-
'show_bug.cgi?id=%i' % self.bug_id)
1274+
self.weburl = bugzilla.url.replace('xmlrpc.cgi',
1275+
'show_bug.cgi?id=%i' % self.bug_id)
12761276

12771277
# TODO: set properties for missing bugfields
12781278
# The problem here is that the property doesn't know its own name,

setup.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@
1212

1313
class TestCommand(Command):
1414
user_options = [
15-
("readonly-functional", None,
15+
("ro-functional", None,
1616
"Run readonly functional tests against actual bugzilla instances. "
17-
"This will be very slow")
17+
"This will be very slow."),
18+
("rw-functional", None,
19+
"Run read/write functional tests against actual bugzilla instances. "
20+
"As of now this only runs against partner-bugzilla.redhat.com, "
21+
"which requires an RH bugzilla account with cached cookies. "
22+
"This will also be very slow.")
1823
]
1924

2025
def initialize_options(self):
21-
self.readonly_functional = False
26+
self.ro_functional = False
27+
self.rw_functional = False
2228

2329
def finalize_options(self):
2430
pass
@@ -45,8 +51,10 @@ def run(self):
4551
continue
4652

4753
base = os.path.basename(t)
48-
if (base == "readonly_functional.py" and not
49-
self.readonly_functional):
54+
if (base == "ro_functional.py" and not self.ro_functional):
55+
continue
56+
57+
if (base == "rw_functional.py" and not self.rw_functional):
5058
continue
5159

5260
testfiles.append('.'.join(['tests', os.path.splitext(base)[0]]))

tests/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def difffile(expect, filename):
2222
if ret:
2323
raise AssertionError("Output was different:\n%s" % ret)
2424

25-
def clicomm(argv, bzinstance, returncliout=False, printcliout=False):
25+
def clicomm(argv, bzinstance, returnmain=False, printcliout=False):
2626
"""
2727
Run bin/bugzilla.main() directly with passed argv
2828
"""
@@ -61,7 +61,9 @@ def clicomm(argv, bzinstance, returncliout=False, printcliout=False):
6161
if ret != 0:
6262
raise RuntimeError("Command failed with %d\ncmd=%s\nout=%s" %
6363
(ret, argv, outt))
64-
return returncliout and outt or mainout
64+
if returnmain:
65+
return mainout
66+
return outt
6567
finally:
6668
sys.stdout = oldstdout
6769
sys.stderr = oldstderr

tests/misc-cli.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,17 @@ class MiscCLI(unittest.TestCase):
2121
maxDiff = None
2222

2323
def testManPageGeneration(self):
24-
out = tests.clicomm("bugzilla --generate-man", None,
25-
returncliout=True)
24+
out = tests.clicomm("bugzilla --generate-man", None)
2625
self.assertTrue(len(out.splitlines()) > 100)
2726

2827
def testHelp(self):
29-
out = tests.clicomm("bugzilla --help", None, returncliout=True)
28+
out = tests.clicomm("bugzilla --help", None)
3029
self.assertTrue(len(out.splitlines()) > 20)
3130

3231
def testCmdHelp(self):
33-
out = tests.clicomm("bugzilla query --help", None, returncliout=True)
32+
out = tests.clicomm("bugzilla query --help", None)
3433
self.assertTrue(len(out.splitlines()) > 40)
3534

3635
def testVersion(self):
37-
out = tests.clicomm("bugzilla --version", None, returncliout=True)
36+
out = tests.clicomm("bugzilla --version", None)
3837
self.assertTrue(len(out.splitlines()) >= 2)

tests/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def clicomm(self, argstr, out):
3535
if out is None:
3636
self.assertRaises(RuntimeError, tests.clicomm, comm, self.bz)
3737
else:
38-
q = tests.clicomm(comm, self.bz)
38+
q = tests.clicomm(comm, self.bz, returnmain=True)
3939
self.assertDictEqual(out, q)
4040

4141
def testBasicQuery(self):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def clicomm(self, argstr, expectexc=False):
3030
if expectexc:
3131
self.assertRaises(RuntimeError, tests.clicomm, comm, bz)
3232
else:
33-
return tests.clicomm(comm, bz, returncliout=True)
33+
return tests.clicomm(comm, bz)
3434

3535
def _testBZClass(self):
3636
bz = Bugzilla(url=self.url, cookiefile=None)

tests/rw_functional.py

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#
2+
# Copyright Red Hat, Inc. 2012
3+
#
4+
# This work is licensed under the terms of the GNU GPL, version 2 or later.
5+
# See the COPYING file in the top-level directory.
6+
#
7+
8+
'''
9+
Unit tests that do permanent functional against a real bugzilla instances.
10+
'''
11+
12+
import datetime
13+
import os
14+
import re
15+
import unittest
16+
import urllib2
17+
18+
import bugzilla
19+
from bugzilla import Bugzilla
20+
21+
import tests
22+
23+
24+
def _split_int(s):
25+
return [int(i) for i in s.split(",")]
26+
27+
28+
class BaseTest(unittest.TestCase):
29+
url = None
30+
bzclass = None
31+
32+
def _getCookiefile(self):
33+
return os.path.expanduser("~/.bugzillacookies")
34+
35+
def _testBZClass(self):
36+
bz = Bugzilla(url=self.url, cookiefile=None)
37+
self.assertTrue(isinstance(bz, self.bzclass))
38+
39+
def _testCookie(self):
40+
cookiefile = self._getCookiefile()
41+
domain = urllib2.urlparse.urlparse(self.url).netloc
42+
if os.path.exists(cookiefile):
43+
out = file(cookiefile).read(1024)
44+
if domain in out:
45+
return
46+
47+
raise RuntimeError("%s must exist and contain domain '%s'" %
48+
(cookiefile, domain))
49+
50+
51+
class RHPartnerTest(BaseTest):
52+
# Despite its name, this instance is simply for bugzilla testing,
53+
# doesn't send out emails and is blown away occasionally. The front
54+
# page has some info.
55+
url = "https://partner-bugzilla.redhat.com/xmlrpc.cgi"
56+
bzclass = bugzilla.RHBugzilla
57+
58+
test1 = BaseTest._testCookie
59+
test2 = BaseTest._testBZClass
60+
61+
62+
def test3NewBugBasic(self):
63+
"""
64+
Create a bug with minimal amount of fields, then close it
65+
"""
66+
67+
component = "python-bugzilla"
68+
version = "16"
69+
summary = ("python-bugzilla test basic bug %s" %
70+
datetime.datetime.today())
71+
newout = tests.clicomm("bugzilla new "
72+
"--product Fedora --component %s --version %s "
73+
"--summary \"%s\" "
74+
"--comment \"Test bug from the python-bugzilla test suite\" "
75+
"--outputformat \"%%{bug_id}\"" %
76+
(component, version, summary), bz)
77+
78+
self.assertTrue(len(newout.splitlines()) == 3)
79+
80+
bugid = int(newout.splitlines()[2])
81+
bug = bz.getbug(bugid)
82+
print "\nCreated bugid: %s" % bugid
83+
84+
self.assertEquals(bug.component, [component])
85+
self.assertEquals(bug.version, [version])
86+
self.assertEquals(bug.summary, summary)
87+
88+
# Close the bug
89+
tests.clicomm("bugzilla modify --close NOTABUG %s" % bugid,
90+
bz)
91+
bug.refresh()
92+
self.assertEquals(bug.status, "CLOSED")
93+
self.assertEquals(bug.resolution, "NOTABUG")
94+
95+
96+
def test4NewBugAllFields(self):
97+
"""
98+
Create a bug using all 'new' fields, check some values, close it
99+
"""
100+
bz = self.bzclass(url=self.url, cookiefile=self._getCookiefile())
101+
102+
summary = ("python-bugzilla test manyfields bug %s" %
103+
datetime.datetime.today())
104+
url = "http://example.com"
105+
osval = "Windows"
106+
107+
blocked = "461686,461687"
108+
dependson = "427301"
109+
comment = "Test bug from python-bugzilla test suite"
110+
newout = tests.clicomm("bugzilla new "
111+
"--product Fedora --component python-bugzilla --version 16 "
112+
"--summary \"%s\" "
113+
"--comment \"%s\" "
114+
"--url %s --severity Urgent --priority Low --os %s "
115+
"--arch ppc --cc %s --blocked %s --dependson %s "
116+
"--outputformat \"%%{bug_id}\"" %
117+
(summary, comment, url, osval, cc, blocked, dependson), bz)
118+
119+
self.assertTrue(len(newout.splitlines()) == 3)
120+
121+
bugid = int(newout.splitlines()[2])
122+
bug = bz.getbug(bugid)
123+
print "\nCreated bugid: %s" % bugid
124+
125+
# XXX: check full output for comment?
126+
self.assertEquals(bug.summary, summary)
127+
self.assertEquals(bug.bug_file_loc, url)
128+
self.assertEquals(bug.op_sys, osval)
129+
self.assertEquals(bug.blocks, _split_int(blocked))
130+
self.assertEquals(bug.depends_on, _split_int(dependson))
131+
self.assertTrue(all([e in bug.cc for e in cc.split(",")]))
132+
self.assertEquals(bug.longdescs[0]["body"], comment)
133+
134+
# Close the bug
135+
tests.clicomm("bugzilla modify --close WONTFIX %s" % bugid,
136+
bz)
137+
bug.refresh()
138+
self.assertEquals(bug.status, "CLOSED")
139+
self.assertEquals(bug.resolution, "WONTFIX")

0 commit comments

Comments
 (0)