def test03NewBugBasic(self): """ Create a bug with minimal amount of fields, then close it """ bz = self.bzclass(url=self.url) component = "python-bugzilla" version = "rawhide" summary = ("python-bugzilla test basic bug %s" % datetime.datetime.today()) newout = tests.clicomm("bugzilla new " "--product Fedora --component %s --version %s " "--summary \"%s\" " "--comment \"Test bug from the python-bugzilla test suite\" " "--outputformat \"%%{bug_id}\"" % (component, version, summary), bz) assert len(newout.splitlines()) == 3 bugid = int(newout.splitlines()[2]) bug = bz.getbug(bugid) print("\nCreated bugid: %s" % bugid) # Verify hasattr works assert hasattr(bug, "id") assert hasattr(bug, "bug_id") assert bug.component == component assert bug.version == version assert bug.summary == summary # Close the bug tests.clicomm("bugzilla modify --close NOTABUG %s" % bugid, bz) bug.refresh() assert bug.status == "CLOSED" assert bug.resolution == "NOTABUG"
def test03NewBugBasic(self): """ Create a bug with minimal amount of fields, then close it """ bz = self.bzclass(url=self.url) component = "python-bugzilla" version = "rawhide" summary = ("python-bugzilla test basic bug %s" % datetime.datetime.today()) newout = tests.clicomm("bugzilla new " "--product Fedora --component %s --version %s " "--summary \"%s\" " "--comment \"Test bug from the python-bugzilla test suite\" " "--outputformat \"%%{bug_id}\"" % (component, version, summary), bz) self.assertTrue(len(newout.splitlines()) == 3) bugid = int(newout.splitlines()[2]) bug = bz.getbug(bugid) print("\nCreated bugid: %s" % bugid) # Verify hasattr works self.assertTrue(hasattr(bug, "id")) self.assertTrue(hasattr(bug, "bug_id")) self.assertEqual(bug.component, component) self.assertEqual(bug.version, version) self.assertEqual(bug.summary, summary) # Close the bug tests.clicomm("bugzilla modify --close NOTABUG %s" % bugid, bz) bug.refresh() self.assertEqual(bug.status, "CLOSED") self.assertEqual(bug.resolution, "NOTABUG")
def test4NewBugAllFields(self): """ Create a bug using all 'new' fields, check some values, close it """ bz = self.bzclass(url=self.url, cookiefile=cf, tokenfile=tf) summary = ("python-bugzilla test manyfields bug %s" % datetime.datetime.today()) url = "http://example.com" osval = "Windows" cc = "*****@*****.**" blocked = "461686,461687" dependson = "427301" comment = "Test bug from python-bugzilla test suite" sub_component = "Command-line tools (RHEL6)" alias = "pybz-%s" % datetime.datetime.today().strftime("%s") newout = tests.clicomm("bugzilla new " "--product 'Red Hat Enterprise Linux 6' --version 6.0 " "--component lvm2 --sub-component '%s' " "--summary \"%s\" " "--comment \"%s\" " "--url %s --severity Urgent --priority Low --os %s " "--arch ppc --cc %s --blocked %s --dependson %s " "--alias %s " "--outputformat \"%%{bug_id}\"" % (sub_component, summary, comment, url, osval, cc, blocked, dependson, alias), bz) self.assertTrue(len(newout.splitlines()) == 3) bugid = int(newout.splitlines()[2]) bug = bz.getbug(bugid) print("\nCreated bugid: %s" % bugid) self.assertEquals(bug.summary, summary) self.assertEquals(bug.bug_file_loc, url) self.assertEquals(bug.op_sys, osval) self.assertEquals(bug.blocks, _split_int(blocked)) self.assertEquals(bug.depends_on, _split_int(dependson)) self.assertTrue(all([e in bug.cc for e in cc.split(",")])) self.assertEquals(bug.longdescs[0]["text"], comment) self.assertEquals(bug.sub_components, {"lvm2": [sub_component]}) self.assertEquals(bug.alias, [alias]) # Close the bug # RHBZ makes it difficult to provide consistent semantics for # 'alias' update: # https://bugzilla.redhat.com/show_bug.cgi?id=1173114 # alias += "-closed" tests.clicomm("bugzilla modify " "--close WONTFIX %s " % bugid, bz) bug.refresh() self.assertEquals(bug.status, "CLOSED") self.assertEquals(bug.resolution, "WONTFIX") self.assertEquals(bug.alias, [alias])
def testPositionalArgs(self): # Make sure cli correctly rejects ambiguous positional args out = tests.clicomm("bugzilla login --xbadarg foo", None, expectfail=True) assert "unrecognized arguments: --xbadarg" in out out = tests.clicomm("bugzilla modify 123456 --foobar --status NEW", None, expectfail=True) assert "unrecognized arguments: --foobar" in out
def clicomm(self, argstr, expectexc=False, bz=None): comm = "bugzilla " + argstr if not bz: bz = Bugzilla(url=self.url, use_creds=False) if expectexc: with pytest.raises(Exception): tests.clicomm(comm, bz) else: return tests.clicomm(comm, bz)
def clicomm(self, argstr, out): comm = "bugzilla query --__test-return-result " + argstr if not out: with pytest.raises(RuntimeError): tests.clicomm(comm, self.bz) else: q = tests.clicomm(comm, self.bz, returnmain=True) assert out == q
def test10Login(self): """ Failed login test, gives us a bit more coverage """ # We overwrite getpass for testing import getpass def fakegetpass(prompt): sys.stdout.write(prompt) sys.stdout.flush() return sys.stdin.readline() oldgetpass = getpass.getpass getpass.getpass = fakegetpass try: # Implied login with --username and --password ret = tests.clicomm("bugzilla --bugzilla %s " "--user [email protected] " "--password foobar query -b 123456" % self.url, None, expectfail=True) self.assertTrue("Login failed: " in ret) # 'login' with explicit options ret = tests.clicomm("bugzilla --bugzilla %s " "--user [email protected] " "--password foobar login" % self.url, None, expectfail=True) self.assertTrue("Login failed: " in ret) # 'login' with positional options ret = tests.clicomm("bugzilla --bugzilla %s " "login [email protected] foobar" % self.url, None, expectfail=True) self.assertTrue("Login failed: " in ret) # bare 'login' stdinstr = "[email protected]\n\rfoobar\n\r" ret = tests.clicomm("bugzilla --bugzilla %s login" % self.url, None, expectfail=True, stdinstr=stdinstr) self.assertTrue("Bugzilla Username:"******"Bugzilla Password:"******"Login failed: " in ret) finally: getpass.getpass = oldgetpass
def test03NewBugBasic(self): """ Create a bug with minimal amount of fields, then close it """ bz = self.bzclass(url=self.url) bug = self._makebug(bz) # Verify hasattr works assert hasattr(bug, "id") assert hasattr(bug, "bug_id") # Close the bug tests.clicomm("bugzilla modify --close NOTABUG %s" % bug.id, bz) bug.refresh() assert bug.status == "CLOSED" assert bug.resolution == "NOTABUG"
def testUnknownKeys(self): """ Make sure unknown key detection works """ # Prevent unfinished crate support from interfering # pylint: disable=protected-access # Ignore 'Access to protected member' from scratchlivedb.scratchdb import _unknowns _unknowns.unknowns = {} # pylint: enable=protected-access out = tests.clicomm("scratchlivedb-tool dump %s" % unknowndb) assert "Unknown keys encountered: ['tzzz', 'uzzz', 'zzzz']" in out out = tests.clicomm("scratchlivedb-tool --debug dump %s" % unknowndb) assert "Unknown type for key 'zzzz'" in out
def clicomm(self, argstr, out, flagsout=None, wbout=None, tags_add=None, tags_rm=None): comm = "bugzilla modify --test-return-result 123456 224466 " + argstr # pylint: disable=unpacking-non-sequence if out is None: self.assertRaises(RuntimeError, tests.clicomm, comm, self.bz) else: (mdict, fdict, wdict, tagsa, tagsr) = tests.clicomm(comm, self.bz, returnmain=True) if wbout: self.assertDictEqual(wbout, wdict) if flagsout: self.assertEqual(flagsout, fdict) if out: self.assertDictEqual(out, mdict) if tags_add: self.assertEqual(tags_add, tagsa) if tags_rm: self.assertEqual(tags_rm, tagsr)
def testCertFail(self): # No public setup that I know of to test cert succeeds, so # let's give it a bogus file and ensure it fails badcert = os.path.join(os.path.dirname(__file__), "..", "README.md") out = tests.clicomm( "bugzilla --cert %s query --bug_id 123456" % badcert, None, expectfail=True) assert "PEM" in out
def testFaults(self): # Test special error wrappers in bugzilla/_cli.py bzinstance = Bugzilla(self.url, use_creds=False) out = tests.clicomm("bugzilla query --field=IDONTEXIST=FOO", bzinstance, expectfail=True) assert "Server error:" in out out = tests.clicomm("bugzilla " "--bugzilla https://example.com/xmlrpc.cgi " "query --field=IDONTEXIST=FOO", None, expectfail=True) assert "Connection lost/failed" in out out = tests.clicomm("bugzilla " "--bugzilla https://expired.badssl.com/ " "query --bug_id 1234", None, expectfail=True) assert "trust the remote server" in out assert "--nosslverify" in out
def test10Login(self): """ Failed login test, gives us a bit more coverage """ # We overwrite getpass for testing import getpass def fakegetpass(prompt): sys.stdout.write(prompt) sys.stdout.flush() return sys.stdin.readline() oldgetpass = getpass.getpass getpass.getpass = fakegetpass try: # Implied login with --username and --password ret = tests.clicomm( "bugzilla --bugzilla %s " "--user [email protected] " "--password foobar query -b 123456" % self.url, None, expectfail=True, ) self.assertTrue("Login failed: " in ret) # 'login' with explicit options ret = tests.clicomm( "bugzilla --bugzilla %s " "--user [email protected] " "--password foobar login" % self.url, None, expectfail=True, ) self.assertTrue("Login failed: " in ret) # 'login' with positional options ret = tests.clicomm( "bugzilla --bugzilla %s " "login [email protected] foobar" % self.url, None, expectfail=True ) self.assertTrue("Login failed: " in ret) # bare 'login' stdinstr = "[email protected]\n\rfoobar\n\r" ret = tests.clicomm("bugzilla --bugzilla %s login" % self.url, None, expectfail=True, stdinstr=stdinstr) self.assertTrue("Bugzilla Username:"******"Bugzilla Password:"******"Login failed: " in ret) finally: getpass.getpass = oldgetpass
def test06ModifyEmails(self): """ Modify cc, assignee, qa_contact for existing bug """ bz = self.bzclass(url=self.url) bugid = "663674" cmd = "bugzilla modify %s " % bugid bug = bz.getbug(bugid) origcc = bug.cc # Test CC list and reset it email1 = "*****@*****.**" email2 = "*****@*****.**" bug.deletecc(origcc) tests.clicomm(cmd + "--cc %s --cc %s" % (email1, email2), bz) bug.addcc(email1) bug.refresh() assert email1 in bug.cc assert email2 in bug.cc assert len(bug.cc) == 2 tests.clicomm(cmd + "--cc=-%s" % email1, bz) bug.refresh() assert email1 not in bug.cc # Test assigned target tests.clicomm(cmd + "--assignee %s" % email1, bz) bug.refresh() assert bug.assigned_to == email1 # Test QA target tests.clicomm(cmd + "--qa_contact %s" % email1, bz) bug.refresh() assert bug.qa_contact == email1 # Reset values bug.deletecc(bug.cc) tests.clicomm(cmd + "--reset-qa-contact --reset-assignee", bz) bug.refresh() assert bug.cc == [] assert bug.assigned_to == "*****@*****.**" assert bug.qa_contact == "*****@*****.**"
def clicomm(self, argstr, out): comm = "bugzilla query --test-return-result " + argstr if out is None: self.assertRaises(RuntimeError, tests.clicomm, comm, self.bz) else: q = tests.clicomm(comm, self.bz, returnmain=True) self.assertDictEqual(out, q)
def clicomm(self, argstr, out): comm = "bugzilla new --test-return-result " + argstr if out is None: self.assertRaises(RuntimeError, tests.clicomm, comm, self.bz) else: q = tests.clicomm(comm, self.bz, returnmain=True) self.assertDictEqual(out, q)
def clicomm(self, argstr, expectexc=False): comm = "bugzilla " + argstr bz = self.bzclass(url=self.url, cookiefile=None, tokenfile=None) if expectexc: self.assertRaises(Exception, tests.clicomm, comm, bz) else: return tests.clicomm(comm, bz)
def test06ModifyEmails(self): """ Modify cc, assignee, qa_contact for existing bug """ bz = self.bzclass(url=self.url) bugid = "663674" cmd = "bugzilla modify %s " % bugid bug = bz.getbug(bugid) origcc = bug.cc # Test CC list and reset it email1 = "*****@*****.**" email2 = "*****@*****.**" bug.deletecc(origcc) tests.clicomm(cmd + "--cc %s --cc %s" % (email1, email2), bz) bug.addcc(email1) bug.refresh() self.assertTrue(email1 in bug.cc) self.assertTrue(email2 in bug.cc) self.assertEquals(len(bug.cc), 2) tests.clicomm(cmd + "--cc=-%s" % email1, bz) bug.refresh() self.assertTrue(email1 not in bug.cc) # Test assigned target tests.clicomm(cmd + "--assignee %s" % email1, bz) bug.refresh() self.assertEquals(bug.assigned_to, email1) # Test QA target tests.clicomm(cmd + "--qa_contact %s" % email1, bz) bug.refresh() self.assertEquals(bug.qa_contact, email1) # Reset values bug.deletecc(bug.cc) tests.clicomm(cmd + "--reset-qa-contact --reset-assignee", bz) bug.refresh() self.assertEquals(bug.cc, []) self.assertEquals(bug.assigned_to, "*****@*****.**") self.assertEquals(bug.qa_contact, "*****@*****.**")
def clicomm(self, argstr, expectexc=False): comm = "bugzilla " + argstr bz = self.bzclass(url=self.url, cookiefile=None) if expectexc: self.assertRaises(Exception, tests.clicomm, comm, bz) else: return tests.clicomm(comm, bz)
def test6ModifyEmails(self): """ Modify cc, assignee, qa_contact for existing bug """ bz = self.bzclass(url=self.url, cookiefile=cf) bugid = "663674" cmd = "bugzilla modify %s " % bugid bug = bz.getbug(bugid) origcc = bug.cc # Test CC list and reset it email1 = "*****@*****.**" email2 = "*****@*****.**" bug.deletecc(origcc) tests.clicomm(cmd + "--cc %s --cc %s" % (email1, email2), bz) bug.refresh() self.assertTrue(email1 in bug.cc) self.assertTrue(email2 in bug.cc) self.assertEquals(len(bug.cc), 2) tests.clicomm(cmd + "--cc -%s" % email1, bz) bug.refresh() self.assertTrue(email1 not in bug.cc) # Test assigned target tests.clicomm(cmd + "--assignee %s" % email1, bz) bug.refresh() self.assertEquals(bug.assigned_to, email1) # Test QA target tests.clicomm(cmd + "--qa_contact %s" % email1, bz) bug.refresh() self.assertEquals(bug.qa_contact, email1) # Reset values bug.deletecc(bug.cc) tests.clicomm(cmd + "--reset-qa-contact --reset-assignee", bz) bug.refresh() self.assertEquals(bug.cc, []) self.assertEquals(bug.assigned_to, "*****@*****.**") self.assertEquals(bug.qa_contact, "*****@*****.**")
def test10Login(self): """ Failed login test, gives us a bit more coverage """ ret = tests.clicomm("bugzilla --bugzilla %s " "--user [email protected] " "--password foobar login" % self.url, None, expectfail=True) self.assertTrue("Login failed: " in ret)
def test4NewBugAllFields(self): """ Create a bug using all 'new' fields, check some values, close it """ bz = self.bzclass(url=self.url, cookiefile=cf) summary = ("python-bugzilla test manyfields bug %s" % datetime.datetime.today()) url = "http://example.com" osval = "Windows" cc = "*****@*****.**" blocked = "461686,461687" dependson = "427301" comment = "Test bug from python-bugzilla test suite" newout = tests.clicomm( "bugzilla new " "--product Fedora --component python-bugzilla --version rawhide " "--summary \"%s\" " "--comment \"%s\" " "--url %s --severity Urgent --priority Low --os %s " "--arch ppc --cc %s --blocked %s --dependson %s " "--outputformat \"%%{bug_id}\"" % (summary, comment, url, osval, cc, blocked, dependson), bz) self.assertTrue(len(newout.splitlines()) == 3) bugid = int(newout.splitlines()[2]) bug = bz.getbug(bugid) print "\nCreated bugid: %s" % bugid self.assertEquals(bug.summary, summary) self.assertEquals(bug.bug_file_loc, url) self.assertEquals(bug.op_sys, osval) self.assertEquals(bug.blocks, _split_int(blocked)) self.assertEquals(bug.depends_on, _split_int(dependson)) self.assertTrue(all([e in bug.cc for e in cc.split(",")])) self.assertEquals(bug.longdescs[0]["text"], comment) # Close the bug tests.clicomm("bugzilla modify --close WONTFIX %s" % bugid, bz) bug.refresh() self.assertEquals(bug.status, "CLOSED") self.assertEquals(bug.resolution, "WONTFIX")
def test4NewBugAllFields(self): """ Create a bug using all 'new' fields, check some values, close it """ bz = self.bzclass(url=self.url, cookiefile=cf) summary = ("python-bugzilla test manyfields bug %s" % datetime.datetime.today()) url = "http://example.com" osval = "Windows" cc = "*****@*****.**" blocked = "461686,461687" dependson = "427301" comment = "Test bug from python-bugzilla test suite" newout = tests.clicomm("bugzilla new " "--product Fedora --component python-bugzilla --version rawhide " "--summary \"%s\" " "--comment \"%s\" " "--url %s --severity Urgent --priority Low --os %s " "--arch ppc --cc %s --blocked %s --dependson %s " "--outputformat \"%%{bug_id}\"" % (summary, comment, url, osval, cc, blocked, dependson), bz) self.assertTrue(len(newout.splitlines()) == 3) bugid = int(newout.splitlines()[2]) bug = bz.getbug(bugid) print "\nCreated bugid: %s" % bugid self.assertEquals(bug.summary, summary) self.assertEquals(bug.bug_file_loc, url) self.assertEquals(bug.op_sys, osval) self.assertEquals(bug.blocks, _split_int(blocked)) self.assertEquals(bug.depends_on, _split_int(dependson)) self.assertTrue(all([e in bug.cc for e in cc.split(",")])) self.assertEquals(bug.longdescs[0]["text"], comment) # Close the bug tests.clicomm("bugzilla modify --close WONTFIX %s" % bugid, bz) bug.refresh() self.assertEquals(bug.status, "CLOSED") self.assertEquals(bug.resolution, "WONTFIX")
def test10Login(self): """ Failed login test, gives us a bit more coverage """ ret = tests.clicomm("bugzilla --bugzilla %s " "--user [email protected] " "--password foobar login" % self.url, None, expectfail=True) self.assertTrue("Logging in... failed." in ret)
def testSyncRhythmbox(self): """ Basic test for rhythmbox sync, make sure we see expected output """ tmpfile = rhythmbox_scratch_input + ".tmp" shutil.copy(rhythmbox_scratch_input, tmpfile) rmfiles.append(tmpfile) cmd = ("sync-rhythmbox-scratchlive --in-place %s %s" % (rhythmbox_xml, tmpfile)) out = tests.clicomm(cmd) assert "Changing timeadded: Armored_Core/Armored_" in out assert "Removing from DB: Orb/Orb_-_Adv" in out assert "Adding to DB: Orbital/Orbital_-_In_S" in out assert "Adding to DB: Daft_Punk/Daft_Punk_-_Tr" in out assert "Adding to DB: Advantage/Advantage_-_Th" in out # Make sure running twice doesn't make any changes out = tests.clicomm(cmd) assert "Parsing rhythmbox DB\n\nTotal removed:" in out
def test9Whiteboards(self): bz = self.bzclass(url=self.url, cookiefile=cf, tokenfile=tf) bug_id = "663674" cmd = "bugzilla modify %s " % bug_id bug = bz.getbug(bug_id) # Set all whiteboards initval = str(random.randint(1, 1024)) tests.clicomm(cmd + "--whiteboard =%sstatus " "--devel_whiteboard =%sdevel " "--internal_whiteboard '=%sinternal, security, foo security1' " "--qa_whiteboard =%sqa " % (initval, initval, initval, initval), bz) bug.refresh() self.assertEquals(bug.whiteboard, initval + "status") self.assertEquals(bug.qa_whiteboard, initval + "qa") self.assertEquals(bug.devel_whiteboard, initval + "devel") self.assertEquals(bug.internal_whiteboard, initval + "internal, security, foo security1") # Modify whiteboards tests.clicomm(cmd + "--whiteboard =foobar " "--qa_whiteboard _app ", bz) bug.prependwhiteboard("pre-", "devel") bug.refresh() self.assertEquals(bug.qa_whiteboard, initval + "qa" + " _app") self.assertEquals(bug.devel_whiteboard, "pre- " + initval + "devel") self.assertEquals(bug.status_whiteboard, "foobar") # Verify that tag manipulation is smart about separator tests.clicomm(cmd + "--qa_whiteboard -_app " "--internal_whiteboard -security", bz) bug.refresh() self.assertEquals(bug.qa_whiteboard, initval + "qa") self.assertEquals(bug.internal_whiteboard, initval + "internal, foo security1") bug.addtag("teststuff", "internal") bug.refresh() self.assertEquals(bug.internal_whiteboard, initval + "internal, foo security1, teststuff") # Clear whiteboards bug.setwhiteboard("", "status") bug.setwhiteboard("", "qa") bug.setwhiteboard("", "devel") bug.setwhiteboard("", "internal") bug.refresh() self.assertEquals(bug.whiteboard, "") self.assertEquals(bug.qa_whiteboard, "") self.assertEquals(bug.devel_whiteboard, "") self.assertEquals(bug.internal_whiteboard, "")
def test16ModifyTags(self): bugid = "461686" cmd = "bugzilla modify %s " % bugid bz = self.bzclass(url=self.url) bug = bz.getbug(bugid) if bug.tags: bz.update_tags(bug.id, tags_remove=bug.tags) bug.refresh() assert bug.tags == [] tests.clicomm(cmd + "--tags foo --tags +bar --tags baz", bz) bug.refresh() assert bug.tags, ["foo", "bar" == "baz"] tests.clicomm(cmd + "--tags=-bar", bz) bug.refresh() assert bug.tags, ["foo" == "baz"] bz.update_tags(bug.id, tags_remove=bug.tags) bug.refresh() assert bug.tags == []
def test16ModifyTags(self): bugid = "461686" cmd = "bugzilla modify %s " % bugid bz = self.bzclass(url=self.url) bug = bz.getbug(bugid) if bug.tags: bz.update_tags(bug.id, tags_remove=bug.tags) bug.refresh() self.assertEquals(bug.tags, []) tests.clicomm(cmd + "--tags foo --tags +bar --tags baz", bz) bug.refresh() self.assertEquals(bug.tags, ["foo", "bar", "baz"]) tests.clicomm(cmd + "--tags=-bar", bz) bug.refresh() self.assertEquals(bug.tags, ["foo", "baz"]) bz.update_tags(bug.id, tags_remove=bug.tags) bug.refresh() self.assertEquals(bug.tags, [])
def test9Whiteboards(self): bz = self.bzclass(url=self.url, cookiefile=cf) bug_id = "663674" cmd = "bugzilla modify %s " % bug_id bug = bz.getbug(bug_id) # Set all whiteboards initval = str(random.randint(1, 1024)) tests.clicomm( cmd + "--whiteboard =%sstatus " "--devel_whiteboard =%sdevel " "--internal_whiteboard '=%sinternal, security, foo security1' " "--qa_whiteboard =%sqa " % (initval, initval, initval, initval), bz) bug.refresh() self.assertEquals(bug.whiteboard, initval + "status") self.assertEquals(bug.qa_whiteboard, initval + "qa") self.assertEquals(bug.devel_whiteboard, initval + "devel") self.assertEquals(bug.internal_whiteboard, initval + "internal, security, foo security1") # Modify whiteboards tests.clicomm(cmd + "--whiteboard =foobar " "--qa_whiteboard _app ", bz) bug.prependwhiteboard("pre-", "devel") bug.refresh() self.assertEquals(bug.qa_whiteboard, initval + "qa" + " _app") self.assertEquals(bug.devel_whiteboard, "pre- " + initval + "devel") self.assertEquals(bug.status_whiteboard, "foobar") # Verify that tag manipulation is smart about separator tests.clicomm( cmd + "--qa_whiteboard -_app " "--internal_whiteboard -security", bz) bug.refresh() self.assertEquals(bug.qa_whiteboard, initval + "qa") self.assertEquals(bug.internal_whiteboard, initval + "internal, foo security1") bug.addtag("teststuff", "internal") bug.refresh() self.assertEquals(bug.internal_whiteboard, initval + "internal, foo security1, teststuff") # Clear whiteboards bug.setwhiteboard("", "status") bug.setwhiteboard("", "qa") bug.setwhiteboard("", "devel") bug.setwhiteboard("", "internal") bug.refresh() self.assertEquals(bug.whiteboard, "") self.assertEquals(bug.qa_whiteboard, "") self.assertEquals(bug.devel_whiteboard, "") self.assertEquals(bug.internal_whiteboard, "")
def clicomm(self, argstr, out, wbout=None, tags_add=None, tags_rm=None): comm = "bugzilla modify --__test-return-result 123456 224466 " + argstr (mdict, wdict, tagsa, tagsr) = tests.clicomm( comm, self.bz, returnmain=True) if wbout: assert wbout == wdict if out: assert out == mdict if tags_add: assert tags_add == tagsa if tags_rm: assert tags_rm == tagsr
def clicomm(self, argstr, out, flagsout=None, wbout=None): comm = "bugzilla modify --test-return-result 123456 224466 " + argstr if out is None: self.assertRaises(RuntimeError, tests.clicomm, comm, self.bz) else: (mdict, fdict, wdict) = tests.clicomm(comm, self.bz, returnmain=True) if wbout: self.assertDictEqual(wbout, wdict) if flagsout: self.assertEqual(flagsout, fdict) if out: self.assertDictEqual(out, mdict)
def clicomm(self, argstr, out, wbout=None, tags_add=None, tags_rm=None): comm = "bugzilla modify --__test-return-result 123456 224466 " + argstr (mdict, wdict, tagsa, tagsr) = tests.clicomm(comm, self.bz, returnmain=True) if wbout: assert wbout == wdict if out: assert out == mdict if tags_add: assert tags_add == tagsa if tags_rm: assert tags_rm == tagsr
def testManPageGeneration(self): try: # If logilab found, we get some useless import warning import warnings warnings.simplefilter("ignore") from logilab.common.optik_ext import ManHelpFormatter ignore = ManHelpFormatter except Exception: e = sys.exc_info()[1] print("Skipping man page test: %s" % e) return out = tests.clicomm("bugzilla --generate-man", None) self.assertTrue(len(out.splitlines()) > 100)
def test09Whiteboards(self): bz = self.bzclass(url=self.url) bug_id = "663674" cmd = "bugzilla modify %s " % bug_id bug = bz.getbug(bug_id) # Set all whiteboards initval = str(random.randint(1, 1024)) tests.clicomm( cmd + "--whiteboard =%sstatus " "--devel_whiteboard =%sdevel " "--internal_whiteboard '=%sinternal, security, foo security1' " "--qa_whiteboard =%sqa " % (initval, initval, initval, initval), bz) bug.refresh() self.assertEquals(bug.whiteboard, initval + "status") self.assertEquals(bug.qa_whiteboard, initval + "qa") self.assertEquals(bug.devel_whiteboard, initval + "devel") self.assertEquals(bug.internal_whiteboard, initval + "internal, security, foo security1") # Modify whiteboards tests.clicomm( cmd + "--whiteboard =foobar " "--qa_whiteboard _app " "--devel_whiteboard =pre-%s" % bug.devel_whiteboard, bz) bug.refresh() self.assertEquals(bug.qa_whiteboard, initval + "qa" + " _app") self.assertEquals(bug.devel_whiteboard, "pre-" + initval + "devel") self.assertEquals(bug.status_whiteboard, "foobar") # Verify that tag manipulation is smart about separator tests.clicomm( cmd + "--qa_whiteboard=-_app " "--internal_whiteboard=-security,", bz) bug.refresh() self.assertEquals(bug.qa_whiteboard, initval + "qa") self.assertEquals(bug.internal_whiteboard, initval + "internal, foo security1") # Clear whiteboards update = bz.build_update(whiteboard="", devel_whiteboard="", internal_whiteboard="", qa_whiteboard="") bz.update_bugs(bug.id, update) bug.refresh() self.assertEquals(bug.whiteboard, "") self.assertEquals(bug.qa_whiteboard, "") self.assertEquals(bug.devel_whiteboard, "") self.assertEquals(bug.internal_whiteboard, "")
def test09Whiteboards(self): bz = self.bzclass(url=self.url) bug_id = "663674" cmd = "bugzilla modify %s " % bug_id bug = bz.getbug(bug_id) # Set all whiteboards initval = str(random.randint(1, 1024)) tests.clicomm(cmd + "--whiteboard =%sstatus " "--devel_whiteboard =%sdevel " "--internal_whiteboard '=%sinternal, security, foo security1' " "--qa_whiteboard =%sqa " % (initval, initval, initval, initval), bz) bug.refresh() self.assertEquals(bug.whiteboard, initval + "status") self.assertEquals(bug.qa_whiteboard, initval + "qa") self.assertEquals(bug.devel_whiteboard, initval + "devel") self.assertEquals(bug.internal_whiteboard, initval + "internal, security, foo security1") # Modify whiteboards tests.clicomm(cmd + "--whiteboard =foobar " "--qa_whiteboard _app " "--devel_whiteboard =pre-%s" % bug.devel_whiteboard, bz) bug.refresh() self.assertEquals(bug.qa_whiteboard, initval + "qa" + " _app") self.assertEquals(bug.devel_whiteboard, "pre-" + initval + "devel") self.assertEquals(bug.status_whiteboard, "foobar") # Verify that tag manipulation is smart about separator tests.clicomm(cmd + "--qa_whiteboard=-_app " "--internal_whiteboard=-security,", bz) bug.refresh() self.assertEquals(bug.qa_whiteboard, initval + "qa") self.assertEquals(bug.internal_whiteboard, initval + "internal, foo security1") # Clear whiteboards update = bz.build_update( whiteboard="", devel_whiteboard="", internal_whiteboard="", qa_whiteboard="") bz.update_bugs(bug.id, update) bug.refresh() self.assertEquals(bug.whiteboard, "") self.assertEquals(bug.qa_whiteboard, "") self.assertEquals(bug.devel_whiteboard, "") self.assertEquals(bug.internal_whiteboard, "")
def clicomm(self, argstr, out, wbout=None, tags_add=None, tags_rm=None): comm = "bugzilla modify --test-return-result 123456 224466 " + argstr # pylint: disable=unpacking-non-sequence if out is None: self.assertRaises(RuntimeError, tests.clicomm, comm, self.bz) else: (mdict, wdict, tagsa, tagsr) = tests.clicomm( comm, self.bz, returnmain=True) if wbout: self.assertDictEqual(wbout, wdict) if out: self.assertDictEqual(out, mdict) if tags_add: self.assertEqual(tags_add, tagsa) if tags_rm: self.assertEqual(tags_rm, tagsr)
class MiscCLI(unittest.TestCase): """ Test miscellaneous CLI bits to get build out our code coverage """ maxDiff = None def testManPageGeneration(self): try: # If logilab found, we get some useless import warning import warnings warnings.simplefilter("ignore") from logilab.common.optik_ext import ManHelpFormatter ignore = ManHelpFormatter except Exception, e: print "Skipping man page test: %s" % e return out = tests.clicomm("bugzilla --generate-man", None) self.assertTrue(len(out.splitlines()) > 100)
def _makebug(self, bz): component = "python-bugzilla" version = "rawhide" summary = ("python-bugzilla test basic bug %s" % datetime.datetime.today()) newout = tests.clicomm("bugzilla new " "--product Fedora --component %s --version %s " "--summary \"%s\" " "--comment \"Test bug from the python-bugzilla test suite\" " "--outputformat \"%%{bug_id}\"" % (component, version, summary), bz) assert len(newout.splitlines()) == 3 bugid = int(newout.splitlines()[2]) bug = bz.getbug(bugid) print("\nCreated bugid: %s" % bug.id) assert bug.component == component assert bug.version == version assert bug.summary == summary return bug
def test07ModifyMultiFlags(self): """ Modify flags and fixed_in for 2 bugs """ bz = self.bzclass(url=self.url) bugid1 = "461686" bugid2 = "461687" cmd = "bugzilla modify %s %s " % (bugid1, bugid2) def flagstr(b): ret = [] for flag in b.flags: ret.append(flag["name"] + flag["status"]) return " ".join(sorted(ret)) def cleardict_old(b): """ Clear flag dictionary, for format meant for bug.updateflags """ clearflags = {} for flag in b.flags: clearflags[flag["name"]] = "X" return clearflags def cleardict_new(b): """ Clear flag dictionary, for format meant for update_bugs """ clearflags = [] for flag in b.flags: clearflags.append({"name": flag["name"], "status": "X"}) return clearflags bug1 = bz.getbug(bugid1) if cleardict_old(bug1): bug1.updateflags(cleardict_old(bug1)) bug2 = bz.getbug(bugid2) if cleardict_old(bug2): bug2.updateflags(cleardict_old(bug2)) # Set flags and confirm setflags = "needinfo? requires_doc_text-" tests.clicomm(cmd + " ".join([(" --flag " + f) for f in setflags.split()]), bz) bug1.refresh() bug2.refresh() assert flagstr(bug1) == setflags assert flagstr(bug2) == setflags assert bug1.get_flags("needinfo")[0]["status"] == "?" assert bug1.get_flag_status("requires_doc_text") == "-" # Clear flags if cleardict_new(bug1): bz.update_flags(bug1.id, cleardict_new(bug1)) bug1.refresh() if cleardict_new(bug2): bz.update_flags(bug2.id, cleardict_new(bug2)) bug2.refresh() assert cleardict_old(bug1) == {} assert cleardict_old(bug2) == {} # Set "Fixed In" field origfix1 = bug1.fixed_in origfix2 = bug2.fixed_in newfix = origfix1 and (origfix1 + "-new1") or "blippy1" if newfix == origfix2: newfix = origfix2 + "-2" tests.clicomm(cmd + "--fixed_in=%s" % newfix, bz) bug1.refresh() bug2.refresh() assert bug1.fixed_in == newfix assert bug2.fixed_in == newfix # Reset fixed_in tests.clicomm(cmd + "--fixed_in=\"-\"", bz) bug1.refresh() bug2.refresh() assert bug1.fixed_in == "-" assert bug2.fixed_in == "-"
def clicomm(self, argstr, out): comm = "bugzilla new --__test-return-result " + argstr q = tests.clicomm(comm, self.bz, returnmain=True) assert out == q
def testCmdHelp(self): out = tests.clicomm("bugzilla query --help", None) self.assertTrue(len(out.splitlines()) > 40)
def testVersion(self): out = tests.clicomm("bugzilla --version", None) self.assertTrue(len(out.splitlines()) >= 2)
def test07ModifyMisc(self): bugid = "461686" cmd = "bugzilla modify %s " % bugid bz = self.bzclass(url=self.url) bug = bz.getbug(bugid) # modify --dependson tests.clicomm(cmd + "--dependson 123456", bz) bug.refresh() assert 123456 in bug.depends_on tests.clicomm(cmd + "--dependson =111222", bz) bug.refresh() assert [111222] == bug.depends_on tests.clicomm(cmd + "--dependson=-111222", bz) bug.refresh() assert [] == bug.depends_on # modify --blocked tests.clicomm(cmd + "--blocked 123,456", bz) bug.refresh() assert [123, 456] == bug.blocks tests.clicomm(cmd + "--blocked =", bz) bug.refresh() assert [] == bug.blocks # modify --keywords tests.clicomm(cmd + "--keywords +Documentation --keywords EasyFix", bz) bug.refresh() assert ["Documentation", "EasyFix"] == bug.keywords tests.clicomm(cmd + "--keywords=-EasyFix --keywords=-Documentation", bz) bug.refresh() assert [] == bug.keywords # modify --target_release # modify --target_milestone targetbugid = 492463 targetbug = bz.getbug(targetbugid) targetcmd = "bugzilla modify %s " % targetbugid tests.clicomm(targetcmd + "--target_milestone beta --target_release 6.2", bz) targetbug.refresh() assert targetbug.target_milestone == "beta" assert targetbug.target_release == ["6.2"] tests.clicomm(targetcmd + "--target_milestone rc --target_release 6.10", bz) targetbug.refresh() assert targetbug.target_milestone == "rc" assert targetbug.target_release == ["6.10"] # modify --priority # modify --severity tests.clicomm(cmd + "--priority low --severity high", bz) bug.refresh() assert bug.priority == "low" assert bug.severity == "high" tests.clicomm(cmd + "--priority medium --severity medium", bz) bug.refresh() assert bug.priority == "medium" assert bug.severity == "medium" # modify --os # modify --platform # modify --version tests.clicomm(cmd + "--version rawhide --os Windows --arch ppc " "--url http://example.com", bz) bug.refresh() assert bug.version == "rawhide" assert bug.op_sys == "Windows" assert bug.platform == "ppc" assert bug.url == "http://example.com" tests.clicomm(cmd + "--version rawhide --os Linux --arch s390 " "--url http://example.com/fribby", bz) bug.refresh() assert bug.version == "rawhide" assert bug.op_sys == "Linux" assert bug.platform == "s390" assert bug.url == "http://example.com/fribby" # modify --field tests.clicomm(cmd + "--field cf_fixed_in=foo-bar-1.2.3 \ --field=cf_release_notes=baz", bz) bug.refresh() assert bug.fixed_in == "foo-bar-1.2.3" assert bug.cf_release_notes == "baz"
def testHelp(self): out = tests.clicomm("bugzilla --help", None) self.assertTrue(len(out.splitlines()) > 18)
def _test8Attachments(self): """ Get and set attachments for a bug """ bz = self.bzclass(url=self.url) cmd = "bugzilla attach " testfile = "../tests/data/bz-attach-get1.txt" # Add attachment as CLI option setbug = self._makebug(bz) setbug = bz.getbug(setbug.id, extra_fields=["attachments"]) orignumattach = len(setbug.attachments) # Add attachment from CLI with mime guessing desc1 = "python-bugzilla cli upload %s" % datetime.datetime.today() out1 = tests.clicomm(cmd + "%s --description \"%s\" --file %s" % (setbug.id, desc1, testfile), bz, stdin=open("/dev/tty", "rb")) desc2 = "python-bugzilla cli upload %s" % datetime.datetime.today() out2 = tests.clicomm(cmd + "%s --file test --summary \"%s\"" % (setbug.id, desc2), bz, stdin=open(testfile)) # Expected output format: # Created attachment <attachid> on bug <bugid> setbug.refresh() assert len(setbug.attachments) == (orignumattach + 2) att1 = setbug.attachments[-2] attachid = att1["id"] assert att1["summary"] == desc1 assert att1["id"] == int(out1.splitlines()[2].split()[2]) assert att1["content_type"] == "text/plain" att2 = setbug.attachments[-1] assert att2["summary"] == desc2 assert att2["id"] == int(out2.splitlines()[2].split()[2]) assert att2["content_type"] == "application/octet-stream" # Set attachment flags assert att1["flags"] == [] bz.updateattachmentflags(setbug.id, att2["id"], "review", status="+") setbug.refresh() assert len(setbug.attachments[-1]["flags"]) == 1 assert setbug.attachments[-1]["flags"][0]["name"] == "review" assert setbug.attachments[-1]["flags"][0]["status"] == "+" bz.updateattachmentflags(setbug.id, setbug.attachments[-1]["id"], "review", status="X") setbug.refresh() assert setbug.attachments[-1]["flags"] == [] # Get attachment, verify content out = tests.clicomm(cmd + "--get %s" % attachid, bz).splitlines() # Expect format: # Wrote <filename> fname = out[2].split()[1].strip() assert len(out) == 3 assert fname == "bz-attach-get1.txt" assert open(fname).read() == open(testfile).read() os.unlink(fname) # Get all attachments getbug = bz.getbug(setbug.id) getbug.autorefresh = True numattach = len(getbug.attachments) out = tests.clicomm(cmd + "--getall %s" % getbug.id, bz).splitlines() assert len(out) == (numattach + 2) fnames = [l.split(" ", 1)[1].strip() for l in out[2:]] assert len(fnames) == numattach for f in fnames: if not os.path.exists(f): raise AssertionError("filename '%s' not found" % f) os.unlink(f)
def test15EnsureLoggedIn(self): bz = self.bzclass(url=self.url) comm = "bugzilla --ensure-logged-in query --bug_id 979546" tests.clicomm(comm, bz)
def test7ModifyMultiFlags(self): """ Modify flags and fixed_in for 2 bugs """ bz = self.bzclass(url=self.url, cookiefile=cf, tokenfile=tf) bugid1 = "461686" bugid2 = "461687" cmd = "bugzilla modify %s %s " % (bugid1, bugid2) def flagstr(b): ret = [] for flag in b.flags: ret.append(flag["name"] + flag["status"]) return " ".join(sorted(ret)) def cleardict(b): clearflags = {} for flag in b.flags: clearflags[flag["name"]] = "X" return clearflags bug1 = bz.getbug(bugid1) if cleardict(bug1): bug1.updateflags(cleardict(bug1)) bug2 = bz.getbug(bugid2) if cleardict(bug2): bug2.updateflags(cleardict(bug2)) # Set flags and confirm setflags = "needinfo? requires_doc_text-" tests.clicomm(cmd + " ".join([(" --flag " + f) for f in setflags.split()]), bz) bug1.refresh() bug2.refresh() self.assertEquals(flagstr(bug1), setflags) self.assertEquals(flagstr(bug2), setflags) self.assertEquals(bug1.get_flags("needinfo")[0]["status"], "?") self.assertEquals(bug1.get_flag_status("requires_doc_text"), "-") # Clear flags if cleardict(bug1): bug1.updateflags(cleardict(bug1)) bug1.refresh() if cleardict(bug2): bug2.updateflags(cleardict(bug2)) bug2.refresh() self.assertEquals(cleardict(bug1), {}) self.assertEquals(cleardict(bug2), {}) # Set "Fixed In" field origfix1 = bug1.fixed_in origfix2 = bug2.fixed_in newfix = origfix1 and (origfix1 + "-new1") or "blippy1" if newfix == origfix2: newfix = origfix2 + "-2" tests.clicomm(cmd + "--fixed_in %s" % newfix, bz) bug1.refresh() bug2.refresh() self.assertEquals(bug1.fixed_in, newfix) self.assertEquals(bug2.fixed_in, newfix) # Reset fixed_in tests.clicomm(cmd + "--fixed_in \"-\"", bz) bug1.refresh() bug2.refresh() self.assertEquals(bug1.fixed_in, "-") self.assertEquals(bug2.fixed_in, "-")
def test7ModifyMisc(self): bugid = "461686" cmd = "bugzilla modify %s " % bugid bz = self.bzclass(url=self.url, cookiefile=cf, tokenfile=tf) bug = bz.getbug(bugid) # modify --dependson tests.clicomm(cmd + "--dependson 123456", bz) bug.refresh() self.assertTrue(123456 in bug.depends_on) tests.clicomm(cmd + "--dependson =111222", bz) bug.refresh() self.assertEquals([111222], bug.depends_on) tests.clicomm(cmd + "--dependson -111222", bz) bug.refresh() self.assertEquals([], bug.depends_on) # modify --blocked tests.clicomm(cmd + "--blocked 123,456", bz) bug.refresh() self.assertEquals([123, 456], bug.blocks) tests.clicomm(cmd + "--blocked =", bz) bug.refresh() self.assertEquals([], bug.blocks) # modify --keywords tests.clicomm(cmd + "--keywords +Documentation --keywords EasyFix", bz) bug.refresh() self.assertEquals(["Documentation", "EasyFix"], bug.keywords) tests.clicomm(cmd + "--keywords -EasyFix --keywords -Documentation", bz) bug.refresh() self.assertEquals([], bug.keywords) # modify --target_release # modify --target_milestone targetbugid = 492463 targetbug = bz.getbug(targetbugid) targetcmd = "bugzilla modify %s " % targetbugid tests.clicomm(targetcmd + "--target_milestone beta --target_release 6.2", bz) targetbug.refresh() self.assertEquals(targetbug.target_milestone, "beta") self.assertEquals(targetbug.target_release, ["6.2"]) tests.clicomm(targetcmd + "--target_milestone rc --target_release 6.0", bz) targetbug.refresh() self.assertEquals(targetbug.target_milestone, "rc") self.assertEquals(targetbug.target_release, ["6.0"]) # modify --priority # modify --severity tests.clicomm(cmd + "--priority low --severity high", bz) bug.refresh() self.assertEquals(bug.priority, "low") self.assertEquals(bug.severity, "high") tests.clicomm(cmd + "--priority medium --severity medium", bz) bug.refresh() self.assertEquals(bug.priority, "medium") self.assertEquals(bug.severity, "medium") # modify --os # modify --platform # modify --version tests.clicomm(cmd + "--version rawhide --os Windows --arch ppc " "--url http://example.com", bz) bug.refresh() self.assertEquals(bug.version, "rawhide") self.assertEquals(bug.op_sys, "Windows") self.assertEquals(bug.platform, "ppc") self.assertEquals(bug.url, "http://example.com") tests.clicomm(cmd + "--version rawhide --os Linux --arch s390 " "--url http://example.com/fribby", bz) bug.refresh() self.assertEquals(bug.version, "rawhide") self.assertEquals(bug.op_sys, "Linux") self.assertEquals(bug.platform, "s390") self.assertEquals(bug.url, "http://example.com/fribby") # modify --field tests.clicomm(cmd + "--field cf_fixed_in=foo-bar-1.2.3 \ --field=cf_release_notes=baz", bz) bug.refresh() self.assertEquals(bug.fixed_in, "foo-bar-1.2.3") self.assertEquals(bug.cf_release_notes, "baz")
def test15EnsureLoggedIn(self): bz = self.bzclass(url=self.url, cookiefile=cf, tokenfile=tf) comm = "bugzilla --ensure-logged-in query --bug_id 979546" tests.clicomm(comm, bz)
def _test8Attachments(self): """ Get and set attachments for a bug """ bz = self.bzclass(url=self.url, cookiefile=cf, tokenfile=tf) getallbugid = "663674" setbugid = "461686" cmd = "bugzilla attach " testfile = "../tests/data/bz-attach-get1.txt" # Add attachment as CLI option setbug = bz.getbug(setbugid) orignumattach = len(setbug.attachments) # Add attachment from CLI with mime guessing desc1 = "python-bugzilla cli upload %s" % datetime.datetime.today() out1 = tests.clicomm(cmd + "%s --description \"%s\" --file %s" % (setbugid, desc1, testfile), bz) desc2 = "python-bugzilla cli upload %s" % datetime.datetime.today() out2 = tests.clicomm(cmd + "%s --file test --description \"%s\"" % (setbugid, desc2), bz, stdin=open(testfile)) # Expected output format: # Created attachment <attachid> on bug <bugid> setbug.refresh() self.assertEquals(len(setbug.attachments), orignumattach + 2) self.assertEquals(setbug.attachments[-2]["description"], desc1) self.assertEquals(setbug.attachments[-2]["id"], int(out1.splitlines()[2].split()[2])) self.assertEquals(setbug.attachments[-1]["description"], desc2) self.assertEquals(setbug.attachments[-1]["id"], int(out2.splitlines()[2].split()[2])) attachid = setbug.attachments[-2]["id"] # Set attachment flags self.assertEquals(setbug.attachments[-1]["flags"], []) bz.updateattachmentflags(setbug.id, setbug.attachments[-1]["id"], "review", status="+") setbug.refresh() self.assertEquals(len(setbug.attachments[-1]["flags"]), 1) self.assertEquals(setbug.attachments[-1]["flags"][0]["name"], "review") self.assertEquals(setbug.attachments[-1]["flags"][0]["status"], "+") bz.updateattachmentflags(setbug.id, setbug.attachments[-1]["id"], "review", status="X") setbug.refresh() self.assertEquals(setbug.attachments[-1]["flags"], []) # Get attachment, verify content out = tests.clicomm(cmd + "--get %s" % attachid, bz).splitlines() # Expect format: # Wrote <filename> fname = out[2].split()[1].strip() self.assertEquals(len(out), 3) self.assertEquals(fname, "bz-attach-get1.txt") self.assertEquals(open(fname).read(), open(testfile).read()) os.unlink(fname) # Get all attachments getbug = bz.getbug(getallbugid) numattach = len(getbug.attachments) out = tests.clicomm(cmd + "--getall %s" % getallbugid, bz).splitlines() self.assertEquals(len(out), numattach + 2) fnames = [l.split(" ", 1)[1].strip() for l in out[2:]] self.assertEquals(len(fnames), numattach) for f in fnames: if not os.path.exists(f): raise AssertionError("filename '%s' not found" % f) os.unlink(f)