Merge lp:~mwhudson/launchpad/no-hosted-area-scanner-tests into lp:launchpad/db-devel

Proposed by Michael Hudson-Doyle
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~mwhudson/launchpad/no-hosted-area-scanner-tests
Merge into: lp:launchpad/db-devel
Prerequisite: lp:~mwhudson/launchpad/no-hosted-area-fix-useBzrBranch-users
Diff against target: 299 lines (+20/-137)
5 files modified
lib/lp/code/stories/branches/xx-branch-mirror-failures.txt (+3/-1)
lib/lp/codehosting/scanner/bzrsync.py (+0/-33)
lib/lp/codehosting/scanner/tests/test_buglinks.py (+1/-1)
lib/lp/codehosting/scanner/tests/test_bzrsync.py (+14/-100)
lib/lp/codehosting/scanner/tests/test_email.py (+2/-2)
To merge this branch: bzr merge lp:~mwhudson/launchpad/no-hosted-area-scanner-tests
Reviewer Review Type Date Requested Status
Tim Penhey (community) conditional Approve
Review via email: mp+24097@code.launchpad.net

Description of the change

Hi Tim,

This branch fixes the tests of the scanner, mostly by deleting obsolete code.

Cheers,
mwh

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

lib/lp/codehosting/scanner/tests/test_bzrsync.py

def makeFixtures(self):
 - assigns self.db_branch to self.makeDatabaseBranch(), just before
   calling self.create_branch_and_tree. I'm pretty sure you can delete
   the first one.

That's all for this one.

review: Approve (conditional)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/stories/branches/xx-branch-mirror-failures.txt'
2--- lib/lp/code/stories/branches/xx-branch-mirror-failures.txt 2010-04-27 02:23:41 +0000
3+++ lib/lp/code/stories/branches/xx-branch-mirror-failures.txt 2010-04-27 02:23:46 +0000
4@@ -163,7 +163,9 @@
5 >>> login(ANONYMOUS)
6 >>> mirror_branch = getUtility(IBranchLookup).getByUniqueName(mirror_name)
7 >>> mirror_branch.startMirroring()
8- >>> mirror_branch.branchChanged('', 'some-revision-id', None, None, None)
9+ >>> from zope.security.proxy import removeSecurityProxy
10+ >>> removeSecurityProxy(mirror_branch).branchChanged(
11+ ... '', 'some-revision-id', None, None, None)
12 >>> logout()
13
14 >>> browser.open(branch_location)
15
16=== modified file 'lib/lp/codehosting/scanner/bzrsync.py'
17--- lib/lp/codehosting/scanner/bzrsync.py 2010-04-27 02:23:41 +0000
18+++ lib/lp/codehosting/scanner/bzrsync.py 2010-04-27 02:23:46 +0000
19@@ -21,14 +21,8 @@
20 from zope.component import getUtility
21 from zope.event import notify
22
23-from bzrlib import urlutils
24-
25-from lazr.uri import URI
26-
27 from lp.codehosting import iter_list_chunks
28-from lp.codehosting.puller.worker import BranchMirrorer
29 from lp.codehosting.scanner import events
30-from lp.codehosting.vfs.branchfs import BranchPolicy
31 from lp.code.interfaces.branchjob import IRosettaUploadJobSource
32 from lp.code.interfaces.branchrevision import IBranchRevisionSet
33 from lp.code.interfaces.revision import IRevisionSet
34@@ -38,33 +32,6 @@
35 UTC = pytz.timezone('UTC')
36
37
38-class InvalidStackedBranchURL(Exception):
39- """Raised when we try to scan a branch stacked on an invalid URL."""
40-
41-
42-class WarehouseBranchPolicy(BranchPolicy):
43-
44- def checkOneURL(self, url):
45- """See `BranchOpener.checkOneURL`.
46-
47- If the URLs we are mirroring from are anything but a
48- lp-mirrored:///~user/project/branch URLs, we don't want to scan them.
49- Opening branches on remote systems takes too long, and we want all of
50- our local access to be channelled through this transport.
51- """
52- uri = URI(url)
53- if uri.scheme != 'lp-mirrored':
54- raise InvalidStackedBranchURL(url)
55-
56- def transformFallbackLocation(self, branch, url):
57- """See `BranchPolicy.transformFallbackLocation`.
58-
59- We're happy to open stacked branches in the usual manner, but want to
60- go on checking the URLs of any branches we then open.
61- """
62- return urlutils.join(branch.base, url), True
63-
64-
65 class BzrSync:
66 """Import version control metadata from a Bazaar branch into the database.
67 """
68
69=== modified file 'lib/lp/codehosting/scanner/tests/test_buglinks.py'
70--- lib/lp/codehosting/scanner/tests/test_buglinks.py 2010-03-02 18:56:25 +0000
71+++ lib/lp/codehosting/scanner/tests/test_buglinks.py 2010-04-27 02:23:46 +0000
72@@ -246,7 +246,7 @@
73
74 def test_got_new_revision_subscribed(self):
75 """got_new_revision is subscribed to NewRevision."""
76- self.useBzrBranches()
77+ self.useBzrBranches(direct_database=True)
78 db_branch, tree = self.create_branch_and_tree()
79 bug = self.factory.makeBug()
80 self.layer.txn.commit()
81
82=== modified file 'lib/lp/codehosting/scanner/tests/test_bzrsync.py'
83--- lib/lp/codehosting/scanner/tests/test_bzrsync.py 2010-04-27 02:23:41 +0000
84+++ lib/lp/codehosting/scanner/tests/test_bzrsync.py 2010-04-27 02:23:46 +0000
85@@ -13,9 +13,6 @@
86 import unittest
87
88 from bzrlib.revision import NULL_REVISION, Revision as BzrRevision
89-from bzrlib.transport import (
90- get_transport, register_transport, unregister_transport)
91-from bzrlib.transport.chroot import ChrootServer
92 from bzrlib.uncommit import uncommit
93 from bzrlib.tests import TestCaseWithTransport
94 import pytz
95@@ -32,9 +29,8 @@
96 from lp.code.model.branchrevision import BranchRevision
97 from lp.code.model.branchmergeproposaljob import IUpdatePreviewDiffJobSource
98 from lp.code.model.revision import Revision, RevisionAuthor, RevisionParent
99-from lp.codehosting.scanner.bzrsync import (
100- BzrSync, InvalidStackedBranchURL)
101-from lp.testing.factory import LaunchpadObjectFactory
102+from lp.codehosting.scanner.bzrsync import BzrSync
103+from lp.testing import TestCaseWithFactory
104 from canonical.testing import LaunchpadZopelessLayer
105
106
107@@ -55,44 +51,7 @@
108 return _run_with_different_user
109
110
111-class FakeTransportServer:
112- """Set up a fake transport at a given URL prefix.
113-
114- For testing purposes.
115- """
116-
117- def __init__(self, transport, url_prefix='lp-mirrored:///'):
118- """Constructor.
119-
120- :param transport: The backing transport to store the data with.
121- :param url_prefix: The URL prefix to access this transport.
122- """
123- self._transport = transport
124- self._url_prefix = url_prefix
125- self._chroot_server = None
126-
127- def start_server(self):
128- """Activate the transport URL."""
129- # The scanner tests assume that branches live on a Launchpad virtual
130- # filesystem rooted at 'lp-mirrored:///'. Rather than provide the
131- # entire virtual filesystem here, we fake it by having a chrooted
132- # transport do the work.
133- register_transport(self._url_prefix, self._transportFactory)
134- self._chroot_server = ChrootServer(self._transport)
135- self._chroot_server.start_server()
136-
137- def stop_server(self):
138- """Deactivate the transport URL."""
139- self._chroot_server.stop_server()
140- unregister_transport(self._url_prefix, self._transportFactory)
141-
142- def _transportFactory(self, url):
143- assert url.startswith(self._url_prefix)
144- url = self._chroot_server.get_url() + url[len(self._url_prefix):]
145- return get_transport(url)
146-
147-
148-class BzrSyncTestCase(TestCaseWithTransport):
149+class BzrSyncTestCase(TestCaseWithTransport, TestCaseWithFactory):
150 """Common base for BzrSync test cases."""
151
152 layer = LaunchpadZopelessLayer
153@@ -101,21 +60,17 @@
154
155 def setUp(self):
156 TestCaseWithTransport.setUp(self)
157- self.factory = LaunchpadObjectFactory()
158+ TestCaseWithFactory.setUp(self)
159+ self.disable_directory_isolation()
160+ self.useBzrBranches(direct_database=True)
161+ self.lp_db_user = config.launchpad.dbuser
162 self.makeFixtures()
163- self.lp_db_user = config.launchpad.dbuser
164 LaunchpadZopelessLayer.switchDbUser(config.branchscanner.dbuser)
165- # The lp-mirrored transport is set up by the branch_scanner module.
166- # Here we set up a fake so that we can test without worrying about
167- # authservers and the like.
168- server = FakeTransportServer(self.get_transport())
169- server.start_server()
170- self.addCleanup(server.stop_server)
171
172 def makeFixtures(self):
173 """Makes test fixtures before we switch to the scanner db user."""
174- self.db_branch = self.makeDatabaseBranch()
175- self.bzr_tree = self.makeBzrBranchAndTree(self.db_branch)
176+ self.db_branch, self.bzr_tree = self.create_branch_and_tree(
177+ db_branch=self.makeDatabaseBranch())
178 self.bzr_branch = self.bzr_tree.branch
179
180 def syncBazaarBranchToDatabase(self, bzr_branch, db_branch):
181@@ -123,11 +78,6 @@
182 syncer = self.makeBzrSync(db_branch)
183 syncer.syncBranchAndClose(bzr_branch)
184
185- def makeBzrBranchAndTree(self, db_branch, format=None):
186- """Make a Bazaar branch at the warehouse location of `db_branch`."""
187- self.get_transport(db_branch.unique_name).create_prefix()
188- return self.make_branch_and_tree(db_branch.unique_name, format=format)
189-
190 def makeDatabaseBranch(self, *args, **kwargs):
191 """Make an arbitrary branch in the database."""
192 LaunchpadZopelessLayer.txn.begin()
193@@ -248,12 +198,14 @@
194
195 # Make the base revision.
196 db_branch = self.makeDatabaseBranch()
197- trunk_tree = self.makeBzrBranchAndTree(db_branch)
198+ db_branch, trunk_tree = self.create_branch_and_tree(
199+ db_branch=db_branch)
200 trunk_tree.commit(u'base revision', rev_id=base_rev_id)
201
202 # Branch from the base revision.
203 new_db_branch = self.makeDatabaseBranch(product=db_branch.product)
204- branch_tree = self.makeBzrBranchAndTree(new_db_branch)
205+ new_db_branch, branch_tree = self.create_branch_and_tree(
206+ db_branch=new_db_branch)
207 branch_tree.pull(trunk_tree.branch)
208
209 # Commit to both branches.
210@@ -517,7 +469,7 @@
211 (branch_revision.revision.revision_id, branch_revision.id)
212 for branch_revision in sampledata)
213
214- self.makeBzrBranchAndTree(branch)
215+ self.create_branch_and_tree(db_branch=branch)
216
217 bzrsync = self.makeBzrSync(branch)
218 db_ancestry, db_history, db_branch_revision_map = (
219@@ -527,37 +479,6 @@
220 self.assertEqual(expected_mapping, db_branch_revision_map)
221
222
223-class TestScanStackedBranches(BzrSyncTestCase):
224- """Tests for scanning stacked branches."""
225-
226- @run_as_db_user(config.launchpad.dbuser)
227- def testStackedBranchBadURL(self):
228- # The scanner will raise an InvalidStackedBranchURL when it tries to
229- # open a branch stacked on a non- lp-mirrored:// schema.
230- db_branch = self.makeDatabaseBranch()
231- stacked_on_branch = self.make_branch('stacked-on', format='1.6')
232- self.assertFalse(stacked_on_branch.base.startswith('lp-mirrored://'))
233- bzr_tree = self.makeBzrBranchAndTree(db_branch, format='1.6')
234- bzr_tree.branch.set_stacked_on_url(stacked_on_branch.base)
235- scanner = self.makeBzrSync(db_branch)
236- self.assertRaises(InvalidStackedBranchURL, scanner.syncBranchAndClose)
237-
238- @run_as_db_user(config.launchpad.dbuser)
239- def testStackedBranch(self):
240- # We can scan a stacked branch that's stacked on a branch that has an
241- # lp-mirrored:// URL.
242- db_stacked_on_branch = self.factory.makeAnyBranch()
243- self.makeBzrBranchAndTree(db_stacked_on_branch, format='1.6')
244- db_stacked_branch = self.factory.makeAnyBranch()
245- stacked_tree = self.makeBzrBranchAndTree(
246- db_stacked_branch, format='1.6')
247- stacked_tree.branch.set_stacked_on_url(
248- 'lp-mirrored:///%s' % db_stacked_on_branch.unique_name)
249- scanner = self.makeBzrSync(db_stacked_branch)
250- # This does not raise an exception.
251- scanner.syncBranchAndClose()
252-
253-
254 class TestBzrSyncOneRevision(BzrSyncTestCase):
255 """Tests for `BzrSync.syncOneRevision`."""
256
257@@ -594,9 +515,6 @@
258 class TestBzrTranslationsUploadJob(BzrSyncTestCase):
259 """Tests BzrSync support for generating TranslationsUploadJobs."""
260
261- def setUp(self):
262- BzrSyncTestCase.setUp(self)
263-
264 def _makeProductSeries(self, mode = None):
265 """Switch to the Launchpad db user to create and configure a
266 product series that is linked to the the branch.
267@@ -647,10 +565,6 @@
268 class TestUpdatePreviewDiffJob(BzrSyncTestCase):
269 """Test the scheduling of jobs to update preview diffs."""
270
271- def setUp(self):
272- """Set up `schedule_diff_updates` to handle tip changes."""
273- BzrSyncTestCase.setUp(self)
274-
275 @run_as_db_user(config.launchpad.dbuser)
276 def test_create_on_new_revision(self):
277 """When branch tip changes, a job is created."""
278
279=== modified file 'lib/lp/codehosting/scanner/tests/test_email.py'
280--- lib/lp/codehosting/scanner/tests/test_email.py 2010-02-26 21:40:42 +0000
281+++ lib/lp/codehosting/scanner/tests/test_email.py 2010-04-27 02:23:46 +0000
282@@ -142,7 +142,7 @@
283
284 def test_queue_tip_changed_email_jobs_subscribed(self):
285 """A queue_tip_changed_email_jobs is run when TipChanged emitted."""
286- self.useBzrBranches()
287+ self.useBzrBranches(direct_database=True)
288 db_branch, tree = self.create_branch_and_tree()
289 db_branch.subscribe(
290 db_branch.registrant,
291@@ -155,7 +155,7 @@
292
293 def test_send_removed_revision_emails_subscribed(self):
294 """send_removed_revision_emails run when RevisionsRemoved emitted."""
295- self.useBzrBranches()
296+ self.useBzrBranches(direct_database=True)
297 db_branch, tree = self.create_branch_and_tree()
298 db_branch.subscribe(
299 db_branch.registrant,

Subscribers

People subscribed via source and target branches

to status/vote changes: