|
| 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