def test_post_to_search_form_does_not_crash(self): responses.add("POST", self.base_url + "xml.cgi", body="<bugzilla>%s</bugzilla>" % self.factory.getUniqueString()) bugzilla = Bugzilla(self.base_url) bugzilla.getRemoteBugBatch([])
def test_repost_on_redirect_does_not_crash(self): responses.add("POST", self.base_url + "xml.cgi", status=302, headers={"Location": self.base_url + "buglist.cgi"}) responses.add("POST", self.base_url + "buglist.cgi", body="<bugzilla>%s</bugzilla>" % self.factory.getUniqueString()) bugzilla = Bugzilla(self.base_url) bugzilla.getRemoteBugBatch([])
def _makeInstrumentedBugzilla(self, page=None, content=None): """Create a `Bugzilla` with a fake urlopen.""" if page is None: page = self.factory.getUniqueString() bugzilla = Bugzilla(self.base_url) if content is None: content = "<bugzilla>%s</bugzilla>" % (self.factory.getUniqueString()) fake_page = StringIO(content) fake_page.url = self.base_url + page bugzilla.urlopen = FakeMethod(result=fake_page) return bugzilla
def _makeInstrumentedBugzilla(self, page=None, content=None): """Create a `Bugzilla` with a fake urlopen.""" if page is None: page = self.factory.getUniqueString() bugzilla = Bugzilla(self.base_url) if content is None: content = "<bugzilla>%s</bugzilla>" % ( self.factory.getUniqueString()) fake_page = StringIO(content) fake_page.url = self.base_url + page bugzilla.urlopen = FakeMethod(result=fake_page) return bugzilla
def test_create(self): # CheckwatchesMaster.remote_bug_updater_factory points to the # RemoteBugUpdater class, so it can be used to create # RemoteBugUpdaters. remote_system = Bugzilla('http://example.com') remote_bug_id = '42' bug_watch_ids = [1, 2] unmodified_remote_ids = ['76'] updater = self.makeUpdater(remote_system, remote_bug_id, bug_watch_ids, unmodified_remote_ids) self.assertTrue(isinstance(updater, RemoteBugUpdater), "updater should be an instance of RemoteBugUpdater.") self.assertEqual( remote_system, updater.external_bugtracker, "Unexpected external_bugtracker for RemoteBugUpdater.") self.assertEqual( remote_bug_id, updater.remote_bug, "RemoteBugUpdater's remote_bug should be '%s', was '%s'" % (remote_bug_id, updater.remote_bug)) self.assertEqual( bug_watch_ids, updater.bug_watch_ids, "RemoteBugUpdater's bug_watch_ids should be '%s', were '%s'" % (bug_watch_ids, updater.bug_watch_ids)) self.assertEqual( unmodified_remote_ids, updater.unmodified_remote_ids, "RemoteBugUpdater's unmodified_remote_ids should be '%s', " "were '%s'" % (unmodified_remote_ids, updater.unmodified_remote_ids))
def test_expat_error(self): # If an `ExpatError` is raised when sniffing for XML-RPC capabilities, # it is taken to mean that no XML-RPC capabilities exist. bugzilla = Bugzilla("http://not.real") class Transport(xmlrpclib.Transport): def request(self, host, handler, request, verbose=None): raise ExpatError("mismatched tag") bugzilla._test_xmlrpc_proxy = xmlrpclib.ServerProxy("%s/xmlrpc.cgi" % bugzilla.baseurl, transport=Transport()) # We must abort any existing transactions before attempting to call # the _remoteSystemHas*() functions because they require that none be # in progress. transaction.abort() self.assertFalse(bugzilla._remoteSystemHasBugzillaAPI()) self.assertFalse(bugzilla._remoteSystemHasPluginAPI())
def test_expat_error(self): # If an `ExpatError` is raised when sniffing for XML-RPC capabilities, # it is taken to mean that no XML-RPC capabilities exist. bugzilla = Bugzilla("http://not.real") class Transport(xmlrpclib.Transport): def request(self, host, handler, request, verbose=None): raise ExpatError("mismatched tag") bugzilla._test_xmlrpc_proxy = xmlrpclib.ServerProxy( '%s/xmlrpc.cgi' % bugzilla.baseurl, transport=Transport()) # We must abort any existing transactions before attempting to call # the _remoteSystemHas*() functions because they require that none be # in progress. transaction.abort() self.assertFalse(bugzilla._remoteSystemHasBugzillaAPI()) self.assertFalse(bugzilla._remoteSystemHasPluginAPI())
def test_reports_invalid_search_result(self): # Sometimes bug searches may go wrong, yielding an HTML page # instead. getRemoteBugBatch rejects and reports search results # of the wrong page type. result_text = """ <html> <body> <h1>This is not actually a search result.</h1> </body> </html> """ responses.add("POST", self.base_url + "xml.cgi", body=result_text) bugzilla = Bugzilla(self.base_url) self.assertRaises(UnparsableBugData, bugzilla.getRemoteBugBatch, [])