Merge lp:~cjwatson/launchpad/explicit-proxy-sourceforge into lp:launchpad

Proposed by Colin Watson on 2018-06-23
Status: Merged
Merged at revision: 18698
Proposed branch: lp:~cjwatson/launchpad/explicit-proxy-sourceforge
Merge into: lp:launchpad
Prerequisite: lp:~cjwatson/launchpad/explicit-proxy-rt
Diff against target: 206 lines (+54/-50)
3 files modified
lib/lp/bugs/doc/externalbugtracker-sourceforge.txt (+32/-26)
lib/lp/bugs/externalbugtracker/sourceforge.py (+4/-4)
lib/lp/bugs/tests/externalbugtracker.py (+18/-20)
To merge this branch: bzr merge lp:~cjwatson/launchpad/explicit-proxy-sourceforge
Reviewer Review Type Date Requested Status
William Grant code 2018-06-23 Approve on 2018-06-26
Review via email: mp+348430@code.launchpad.net

Commit message

Convert the SourceForge external bug tracker to urlfetch.

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/doc/externalbugtracker-sourceforge.txt'
2--- lib/lp/bugs/doc/externalbugtracker-sourceforge.txt 2012-12-26 01:32:19 +0000
3+++ lib/lp/bugs/doc/externalbugtracker-sourceforge.txt 2018-06-23 00:21:34 +0000
4@@ -78,14 +78,14 @@
5 it a set of remote bug IDs will fetch those bug IDs from the server and
6 file them in a local variable for later use.
7
8-We use a test-oriented implementation for the purposes of these tests,
9-which overrides ExternalBugTracker.urlopen() so that we don't have to
10-rely on a working network connection.
11+We use a test-oriented implementation for the purposes of these tests, which
12+avoids relying on a working network connection.
13
14 >>> from lp.bugs.tests.externalbugtracker import (
15 ... TestSourceForge, print_bugwatches)
16 >>> sourceforge = TestSourceForge('http://example.com/')
17- >>> sourceforge.initializeRemoteBugDB([1722250])
18+ >>> with sourceforge.responses():
19+ ... sourceforge.initializeRemoteBugDB([1722250])
20 >>> sorted(sourceforge.bugs.keys())
21 [1722250]
22
23@@ -93,7 +93,8 @@
24 raised. We use a special sample bug, bug 0, which defines no status or
25 resolution, to demonstrate this:
26
27- >>> sourceforge.initializeRemoteBugDB([0])
28+ >>> with sourceforge.responses():
29+ ... sourceforge.initializeRemoteBugDB([0])
30 Traceback (most recent call last):
31 ...
32 UnparsableBugData: Remote bug 0 does not define a status.
33@@ -102,7 +103,8 @@
34 status from them, we don't raise an error when trying to initialize the
35 remote bug database. Sample bug 99 is private.
36
37- >>> sourceforge.initializeRemoteBugDB([99])
38+ >>> with sourceforge.responses():
39+ ... sourceforge.initializeRemoteBugDB([99])
40 >>> sorted(sourceforge.bugs.keys())
41 [99]
42
43@@ -168,8 +170,9 @@
44 >>> bug_watch_updater = CheckwatchesMaster(
45 ... txn, logger=FakeLogger())
46 >>> sourceforge = TestSourceForge(example_bug_tracker.baseurl)
47- >>> bug_watch_updater.updateBugWatches(
48- ... sourceforge, example_bug_tracker.watches)
49+ >>> with sourceforge.responses():
50+ ... bug_watch_updater.updateBugWatches(
51+ ... sourceforge, example_bug_tracker.watches)
52 INFO Updating 1 watches for 1 bugs on http://bugs.some.where
53 >>> print_bugwatches(example_bug_tracker.watches)
54 Remote bug 1722250: Open:None
55@@ -209,29 +212,30 @@
56
57 >>> transaction.commit()
58
59- >>> sourceforge.trace_calls = True
60- >>> bug_watch_updater.updateBugWatches(
61- ... sourceforge, sorted(example_bug_tracker.watches))
62+ >>> with sourceforge.responses(trace_calls=True):
63+ ... bug_watch_updater.updateBugWatches(
64+ ... sourceforge, sorted(example_bug_tracker.watches))
65 INFO Updating 1 watches for 1 bugs on http://bugs.some.where
66- CALLED _getPage(u'support/tracker.php?aid=1722251')
67+ GET http://bugs.some.where/support/tracker.php?aid=1722251
68
69 For the sake of this test we can set the bug tracker's batch_size to
70 None so that it will process all the updates at once:
71
72 >>> sourceforge.batch_size = None
73- >>> bug_watch_updater.updateBugWatches(
74- ... sourceforge, example_bug_tracker.watches)
75+ >>> with sourceforge.responses(trace_calls=True):
76+ ... bug_watch_updater.updateBugWatches(
77+ ... sourceforge, example_bug_tracker.watches)
78 INFO Updating 10 watches for 10 bugs on http://bugs.some.where
79- CALLED _getPage(u'support/tracker.php?aid=1722250')
80- CALLED _getPage(u'support/tracker.php?aid=1722251')
81- CALLED _getPage(u'support/tracker.php?aid=1722252')
82- CALLED _getPage(u'support/tracker.php?aid=1722253')
83- CALLED _getPage(u'support/tracker.php?aid=1722254')
84- CALLED _getPage(u'support/tracker.php?aid=1722255')
85- CALLED _getPage(u'support/tracker.php?aid=1722256')
86- CALLED _getPage(u'support/tracker.php?aid=1722257')
87- CALLED _getPage(u'support/tracker.php?aid=1722258')
88- CALLED _getPage(u'support/tracker.php?aid=1722259')
89+ GET http://bugs.some.where/support/tracker.php?aid=1722250
90+ GET http://bugs.some.where/support/tracker.php?aid=1722251
91+ GET http://bugs.some.where/support/tracker.php?aid=1722252
92+ GET http://bugs.some.where/support/tracker.php?aid=1722253
93+ GET http://bugs.some.where/support/tracker.php?aid=1722254
94+ GET http://bugs.some.where/support/tracker.php?aid=1722255
95+ GET http://bugs.some.where/support/tracker.php?aid=1722256
96+ GET http://bugs.some.where/support/tracker.php?aid=1722257
97+ GET http://bugs.some.where/support/tracker.php?aid=1722258
98+ GET http://bugs.some.where/support/tracker.php?aid=1722259
99
100 The bug statuses have now been imported from the Example.com bug
101 tracker, so the bug watches should now have valid Launchpad bug
102@@ -276,7 +280,9 @@
103 If SourceForge can't find the group_id and atid for the bug (for example
104 if the bug is private), getRemoteProduct() will return None.
105
106- >>> sourceforge.trace_calls = False
107- >>> sourceforge.initializeRemoteBugDB([99])
108+ >>> transaction.commit()
109+
110+ >>> with sourceforge.responses():
111+ ... sourceforge.initializeRemoteBugDB([99])
112 >>> print sourceforge.getRemoteProduct(99)
113 None
114
115=== modified file 'lib/lp/bugs/externalbugtracker/sourceforge.py'
116--- lib/lp/bugs/externalbugtracker/sourceforge.py 2017-10-21 18:14:14 +0000
117+++ lib/lp/bugs/externalbugtracker/sourceforge.py 2018-06-23 00:21:34 +0000
118@@ -1,4 +1,4 @@
119-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
120+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
121 # GNU Affero General Public License version 3 (see the file LICENSE).
122
123 """Sourceforge ExternalBugTracker utility."""
124@@ -11,7 +11,7 @@
125
126 from lp.bugs.externalbugtracker import (
127 BugNotFound,
128- ExternalBugTracker,
129+ ExternalBugTrackerRequests,
130 InvalidBugId,
131 LookupTree,
132 PrivateRemoteBug,
133@@ -27,7 +27,7 @@
134 from lp.services.webapp import urlsplit
135
136
137-class SourceForge(ExternalBugTracker):
138+class SourceForge(ExternalBugTrackerRequests):
139 """An ExternalBugTracker for SourceForge bugs."""
140
141 # We only allow ourselves to update one SourceForge bug at a time to
142@@ -48,7 +48,7 @@
143
144 for bug_id in bug_ids:
145 query_url = self.export_url % bug_id
146- page_data = self._getPage(query_url)
147+ page_data = self._getPage(query_url).content
148
149 soup = BeautifulSoup(page_data)
150 status_tag = soup.find(text=re.compile('Status:'))
151
152=== modified file 'lib/lp/bugs/tests/externalbugtracker.py'
153--- lib/lp/bugs/tests/externalbugtracker.py 2018-06-23 00:21:33 +0000
154+++ lib/lp/bugs/tests/externalbugtracker.py 2018-06-23 00:21:34 +0000
155@@ -26,6 +26,7 @@
156 import responses
157 from six.moves.urllib_parse import (
158 parse_qs,
159+ urljoin,
160 urlsplit,
161 )
162 from zope.component import getUtility
163@@ -1608,26 +1609,23 @@
164 'GET', re.compile(re.escape(self.baseurl)), self._getCallback)
165
166
167-class TestSourceForge(SourceForge):
168- """Test-oriented SourceForge ExternalBugTracker.
169-
170- Overrides _getPage() so that access to SourceForge itself is not
171- required.
172- """
173-
174- trace_calls = False
175-
176- def _getPage(self, page):
177- if self.trace_calls:
178- print "CALLED _getPage(%r)" % (page)
179-
180- page_re = re.compile('support/tracker.php\?aid=([0-9]+)')
181- bug_id = page_re.match(page).groups()[0]
182-
183- file_path = os.path.join(
184- os.path.dirname(__file__), 'testfiles',
185- 'sourceforge-sample-bug-%s.html' % bug_id)
186- return open(file_path, 'r').read()
187+class TestSourceForge(BugTrackerResponsesMixin, SourceForge):
188+ """Test-oriented SourceForge ExternalBugTracker."""
189+
190+ @staticmethod
191+ def _getCallback(request):
192+ url = urlsplit(request.url)
193+ bug_id = parse_qs(url.query)['aid'][0]
194+ body = read_test_file('sourceforge-sample-bug-%s.html' % bug_id)
195+ return 200, {'Content-Type': 'text/html'}, body
196+
197+ def addResponses(self, requests_mock):
198+ """Add test responses."""
199+ requests_mock.add_callback(
200+ 'GET',
201+ re.compile(
202+ re.escape(urljoin(self.baseurl, 'support/tracker.php'))),
203+ self._getCallback)
204
205
206 class TestDebianBug(debbugs.Bug):