Colin Watson has proposed merging lp:~cjwatson/launchpad/explicit-proxy-mantis
into lp:launchpad with lp:~cjwatson/launchpad/explicit-proxy-sourceforge as a
prerequisite.
Commit message:
Convert the Mantis external bug tracker to urlfetch.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/explicit-proxy-mantis/+merge/348431
The login arrangements require some care, but fortunately requests hooks are
powerful enough for this.
--
Your team Launchpad code reviewers is requested to review the proposed merge of
lp:~cjwatson/launchpad/explicit-proxy-mantis into lp:launchpad.
=== modified file 'lib/lp/bugs/doc/externalbugtracker-mantis-csv.txt'
--- lib/lp/bugs/doc/externalbugtracker-mantis-csv.txt 2012-04-12 11:38:44 +
+++ lib/lp/bugs/doc/externalbugtracker-mantis-csv.txt 2018-06-23 00:29:08 +
@@ -67,8 +67,8 @@
calls to verify here. We set its batch_query_threshold to 0 so as to
force it to use the CSV import code:
->>> example_ext_bug_tracker = TestMantis(example_bug_tracker.baseurl)
->>> example_ext_bug_tracker.batch_query_threshold = 0
+>>> mantis = TestMantis(example_bug_tracker.baseurl)
+>>> mantis.batch_query_threshold = 0
Collect the Example.com watches:
@@ -84,8 +84,9 @@
>>> from lp.bugs.scripts.checkwatches import CheckwatchesMaster
>>> bug_watch_updater = CheckwatchesMaster(
... transaction, logger=FakeLogger())
->>> bug_watch_updater.updateBugWatches(
-... example_ext_bug_tracker, example_bug_tracker.watches)
+>>> with mantis.responses():
+... bug_watch_updater.updateBugWatches(
+... mantis, example_bug_tracker.watches)
INFO Updating 1 watches for 1 bugs on http://bugs.some.where
>>> for bug_watch in example_bug_tracker.watches:
@@ -117,7 +118,7 @@
... bug=example_bug, owner=sample_person,
... bugtracker=example_bug_tracker,
... remotebug=str(remote_bug_id))
-... example_ext_bug_tracker.bugs[remote_bug_id] = remote_bug
+... mantis.bugs[remote_bug_id] = remote_bug
... expected_remote_statuses[remote_bug_id] = (
... "%s: %s" % (remote_bug['status'], remote_bug['resolution']))
@@ -125,14 +126,14 @@
updateBugWatches() issues only one request to update all watches:
>>> from lp.services.propertycache import get_property_cache
->>> del get_property_cache(example_ext_bug_tracker).csv_data
+>>> del get_property_cache(mantis).csv_data
->>> example_ext_bug_tracker.trace_calls = True
->>> bug_watch_updater.updateBugWatches(
-... example_ext_bug_tracker, example_bug_tracker.watches)
+>>> with mantis.responses(trace_calls=True):
+... bug_watch_updater.updateBugWatches(
+... mantis, example_bug_tracker.watches)
INFO Updating 6 watches for 6 bugs on http://bugs.some.where
-CALLED _postPage('view_all_set.php?f=3', ...)
-CALLED _getPage('csv_export.php')
+POST http://bugs.some.where/view_all_set.php?f=3
+GET http://bugs.some.where/csv_export.php
>>> remote_statuses = dict(
... (int(bug_watch.remotebug), bug_watch.remotestatus)
@@ -164,8 +165,6 @@
* Expected << assigned: open >>
* Got << assigned: open >>
->>> example_ext_bug_tracker.trace_calls = False
-
updateBugWatches() updates the lastchecked attribute on the watches, so
now no bug watches are in need of updating:
@@ -183,8 +182,7 @@
>>> now = datetime.now(pytz.timezone('UTC'))
>>> bug_watch.lastchanged = now - timedelta(weeks=2)
>>> old_last_changed = bug_watch.lastchanged
->>> bug_watch_updater.updateBugWatches(
-... example_ext_bug_tracker, [bug_watch])
+>>> bug_watch_updater.updateBugWatches(mantis, [bug_watch])
INFO Updating 1 watches for 1 bugs on http://bugs.some.where
>>> bug_watch.lastchanged == old_last_changed
=== modified file 'lib/lp/bugs/doc/externalbugtracker-mantis-logging-in.txt'
--- lib/lp/bugs/doc/externalbugtracker-mantis-logging-in.txt 2011-01-20 23:10:56 +
+++ lib/lp/bugs/doc/externalbugtracker-mantis-logging-in.txt 2018-06-23 00:29:08 +
@@ -3,40 +3,49 @@
Mantis is... special. In a headless/batch environment we must do a
little dance in order to log in. Thankfully, we can encapsulate this
-neatly in a urllib2-style handler.
-
-
-MantisLoginHandler
-==
-
->>> from lp.bugs.externalbugtracker import (
-... MantisLoginHandler)
->>> handler = MantisLoginHandler()
+neatly in a requests hook.
+
+
+mantis_login_hook
+=
+
+>>> from requests import Response
+>>> from lp.bugs.externalbugtracker.mantis import mantis_login_hook
+
+>>> def run_hook(url, status_code=302):
+... response = Response()
+... response.status_code = status_code
+... response.headers['Location'] = url
+... response = mantis_login_hook(response)
+