def test_readconfig(self): bzapi = tests.make_bz("4.4.0", rhbz=True) bzapi.url = "foo.example.com" temp = tempfile.NamedTemporaryFile(mode="w") content = """ [example.com] foo=1 user=test1 password=test2""" temp.write(content) temp.flush() bzapi.readconfig(temp.name) self.assertEquals(bzapi.user, "test1") self.assertEquals(bzapi.password, "test2") content = """ [foo.example.com] user=test3 password=test4""" temp.write(content) temp.flush() bzapi.readconfig(temp.name) self.assertEquals(bzapi.user, "test3") self.assertEquals(bzapi.password, "test4") bzapi.url = "bugzilla.redhat.com" bzapi.user = None bzapi.password = None bzapi.readconfig(temp.name) self.assertEquals(bzapi.user, None) self.assertEquals(bzapi.password, None)
def testPostTranslation(self): def _testPostCompare(bz, indict, outexpect): outdict = indict.copy() bz.post_translation({}, outdict) self.assertTrue(outdict == outexpect) # Make sure multiple calls don't change anything bz.post_translation({}, outdict) self.assertTrue(outdict == outexpect) bug3 = tests.make_bz("3.4.0") rhbz = tests.make_bz("4.4.0", rhbz=True) test1 = { "component": ["comp1"], "version": ["ver1", "ver2"], 'flags': [{ 'is_active': 1, 'name': 'qe_test_coverage', 'setter': '*****@*****.**', 'status': '?', }, { 'is_active': 1, 'name': 'rhel-6.4.0', 'setter': '*****@*****.**', 'status': '+', }], 'alias': ["FOO", "BAR"], 'blocks': [782183, 840699, 923128], 'keywords': ['Security'], 'groups': ['redhat'], } out_simple = test1.copy() out_simple["components"] = out_simple["component"] out_simple["component"] = out_simple["components"][0] out_simple["versions"] = out_simple["version"] out_simple["version"] = out_simple["versions"][0] _testPostCompare(bug3, test1, test1) _testPostCompare(rhbz, test1, out_simple)
def testPostTranslation(self): def _testPostCompare(bz, indict, outexpect): outdict = indict.copy() bz.post_translation({}, outdict) assert outdict == outexpect # Make sure multiple calls don't change anything bz.post_translation({}, outdict) assert outdict == outexpect bug3 = tests.make_bz("3.4.0") rhbz = tests.make_bz("4.4.0", rhbz=True) test1 = { "component": ["comp1"], "version": ["ver1", "ver2"], 'flags': [{ 'is_active': 1, 'name': 'qe_test_coverage', 'setter': '*****@*****.**', 'status': '?', }, { 'is_active': 1, 'name': 'rhel-6.4.0', 'setter': '*****@*****.**', 'status': '+', }], 'alias': ["FOO", "BAR"], 'blocks': [782183, 840699, 923128], 'keywords': ['Security'], 'groups': ['redhat'], } out_simple = test1.copy() out_simple["components"] = out_simple["component"] out_simple["component"] = out_simple["components"][0] out_simple["versions"] = out_simple["version"] out_simple["version"] = out_simple["versions"][0] _testPostCompare(bug3, test1, test1) _testPostCompare(rhbz, test1, out_simple)
def testCookies(self): cookiesbad = os.path.join(os.getcwd(), "tests/data/cookies-bad.txt") cookieslwp = os.path.join(os.getcwd(), "tests/data/cookies-lwp.txt") cookiesmoz = os.path.join(os.getcwd(), "tests/data/cookies-moz.txt") # We used to convert LWP cookies, but it shouldn't matter anymore, # so verify they fail at least try: tests.make_bz("3.0.0", cookiefile=cookieslwp) raise AssertionError("Expected BugzillaError from parsing %s" % os.path.basename(cookieslwp)) except bugzilla.BugzillaError: # Expected result pass # Make sure bad cookies raise an error try: tests.make_bz("3.0.0", cookiefile=cookiesbad) raise AssertionError("Expected BugzillaError from parsing %s" % os.path.basename(cookiesbad)) except bugzilla.BugzillaError: # Expected result pass # Mozilla should 'just work' tests.make_bz("3.0.0", cookiefile=cookiesmoz)
def test_readconfig(self): # Testing for bugzillarc handling bzapi = tests.make_bz("4.4.0", rhbz=True) bzapi.url = "example.com" temp = tempfile.NamedTemporaryFile(mode="w") content = """ [example.com] foo=1 user=test1 password=test2""" temp.write(content) temp.flush() bzapi.readconfig(temp.name) assert bzapi.user == "test1" assert bzapi.password == "test2" assert bzapi.api_key is None bzapi.url = "foo.example.com" bzapi.user = None bzapi.readconfig(temp.name) assert bzapi.user is None content = """ [foo.example.com] user=test3 password=test4 api_key=123abc """ temp.write(content) temp.flush() bzapi.readconfig(temp.name) assert bzapi.user == "test3" assert bzapi.password == "test4" assert bzapi.api_key == "123abc" bzapi.url = "bugzilla.redhat.com" bzapi.user = None bzapi.password = None bzapi.api_key = None bzapi.readconfig(temp.name) assert bzapi.user is None assert bzapi.password is None assert bzapi.api_key is None
def testCookies(self): cookiesbad = os.path.join(os.getcwd(), "tests/data/cookies-bad.txt") cookieslwp = os.path.join(os.getcwd(), "tests/data/cookies-lwp.txt") cookiesmoz = os.path.join(os.getcwd(), "tests/data/cookies-moz.txt") # We used to convert LWP cookies, but it shouldn't matter anymore, # so verify they fail at least with pytest.raises(bugzilla.BugzillaError): tests.make_bz("3.0.0", cookiefile=cookieslwp) with pytest.raises(bugzilla.BugzillaError): tests.make_bz("3.0.0", cookiefile=cookiesbad) # Mozilla should 'just work' tests.make_bz("3.0.0", cookiefile=cookiesmoz)
# Copyright Red Hat, Inc. 2013 # # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory. # ''' Unit tests for building update dictionaries with 'bugzilla modify' ''' import unittest import tests rhbz = tests.make_bz("4.4.0", rhbz=True) class ModifyTest(unittest.TestCase): maxDiff = None bz = rhbz def assertDictEqual(self, *args, **kwargs): # EPEL5 back compat if hasattr(unittest.TestCase, "assertDictEqual"): return unittest.TestCase.assertDictEqual(self, *args, **kwargs) return self.assertEqual(*args, **kwargs) 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
# Copyright Red Hat, Inc. 2013 # # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory. # """ Unit tests for building createbug dictionaries with bin/bugzilla """ import unittest import tests bz4 = tests.make_bz("4.0.0") class CreatebugTest(unittest.TestCase): bz = bz4 def clicomm(self, argstr, out): comm = "bugzilla new --__test-return-result " + argstr q = tests.clicomm(comm, self.bz, returnmain=True) assert out == q def testBasic(self): self.clicomm( "--product foo --component bar --summary baz --version 12", {'component': 'bar', 'product': 'foo', 'summary': 'baz', 'version': '12'}
# # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory. # ''' Unit tests for building query strings with bin/bugzilla ''' import copy import os import unittest import tests bz34 = tests.make_bz("3.4.0") bz4 = tests.make_bz("4.0.0") rhbz4 = tests.make_bz("4.4.0", rhbz=True) class BZ34Test(unittest.TestCase): """ This is the base query class, but it's also functional on its own. """ maxDiff = None def assertDictEqual(self, *args, **kwargs): # EPEL5 back compat if hasattr(unittest.TestCase, "assertDictEqual"): return unittest.TestCase.assertDictEqual(self, *args, **kwargs)
def testUserAgent(self): b3 = tests.make_bz("3.0.0") self.assertTrue("python-bugzilla" in b3.user_agent)
# # Copyright Red Hat, Inc. 2013 # # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory. # ''' Unit tests for building createbug dictionaries with bin/bugzilla ''' import unittest import tests bz4 = tests.make_bz("4.0.0") class CreatebugTest(unittest.TestCase): maxDiff = None bz = bz4 def assertDictEqual(self, *args, **kwargs): # EPEL5 back compat if hasattr(unittest.TestCase, "assertDictEqual"): return unittest.TestCase.assertDictEqual(self, *args, **kwargs) return self.assertEqual(*args, **kwargs) def clicomm(self, argstr, out): comm = "bugzilla new --test-return-result " + argstr if out is None:
# See the COPYING file in the top-level directory. # """ Unit tests for building query strings with bin/bugzilla """ import copy import os import unittest import pytest import tests bz34 = tests.make_bz("3.4.0") bz4 = tests.make_bz("4.0.0") rhbz4 = tests.make_bz("4.4.0", rhbz=True) class BZ34Test(unittest.TestCase): """ This is the base query class, but it's also functional on its own. """ def clicomm(self, argstr, out): comm = "bugzilla query --__test-return-result " + argstr if not out: with pytest.raises(RuntimeError): tests.clicomm(comm, self.bz)
def testUserAgent(self): b3 = tests.make_bz("3.0.0") assert "python-bugzilla" in b3.user_agent