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
=== modified file 'lib/lp/code/stories/branches/xx-branch-mirror-failures.txt'
--- lib/lp/code/stories/branches/xx-branch-mirror-failures.txt 2010-04-27 02:23:41 +0000
+++ lib/lp/code/stories/branches/xx-branch-mirror-failures.txt 2010-04-27 02:23:46 +0000
@@ -163,7 +163,9 @@
163 >>> login(ANONYMOUS)163 >>> login(ANONYMOUS)
164 >>> mirror_branch = getUtility(IBranchLookup).getByUniqueName(mirror_name)164 >>> mirror_branch = getUtility(IBranchLookup).getByUniqueName(mirror_name)
165 >>> mirror_branch.startMirroring()165 >>> mirror_branch.startMirroring()
166 >>> mirror_branch.branchChanged('', 'some-revision-id', None, None, None)166 >>> from zope.security.proxy import removeSecurityProxy
167 >>> removeSecurityProxy(mirror_branch).branchChanged(
168 ... '', 'some-revision-id', None, None, None)
167 >>> logout()169 >>> logout()
168170
169 >>> browser.open(branch_location)171 >>> browser.open(branch_location)
170172
=== modified file 'lib/lp/codehosting/scanner/bzrsync.py'
--- lib/lp/codehosting/scanner/bzrsync.py 2010-04-27 02:23:41 +0000
+++ lib/lp/codehosting/scanner/bzrsync.py 2010-04-27 02:23:46 +0000
@@ -21,14 +21,8 @@
21from zope.component import getUtility21from zope.component import getUtility
22from zope.event import notify22from zope.event import notify
2323
24from bzrlib import urlutils
25
26from lazr.uri import URI
27
28from lp.codehosting import iter_list_chunks24from lp.codehosting import iter_list_chunks
29from lp.codehosting.puller.worker import BranchMirrorer
30from lp.codehosting.scanner import events25from lp.codehosting.scanner import events
31from lp.codehosting.vfs.branchfs import BranchPolicy
32from lp.code.interfaces.branchjob import IRosettaUploadJobSource26from lp.code.interfaces.branchjob import IRosettaUploadJobSource
33from lp.code.interfaces.branchrevision import IBranchRevisionSet27from lp.code.interfaces.branchrevision import IBranchRevisionSet
34from lp.code.interfaces.revision import IRevisionSet28from lp.code.interfaces.revision import IRevisionSet
@@ -38,33 +32,6 @@
38UTC = pytz.timezone('UTC')32UTC = pytz.timezone('UTC')
3933
4034
41class InvalidStackedBranchURL(Exception):
42 """Raised when we try to scan a branch stacked on an invalid URL."""
43
44
45class WarehouseBranchPolicy(BranchPolicy):
46
47 def checkOneURL(self, url):
48 """See `BranchOpener.checkOneURL`.
49
50 If the URLs we are mirroring from are anything but a
51 lp-mirrored:///~user/project/branch URLs, we don't want to scan them.
52 Opening branches on remote systems takes too long, and we want all of
53 our local access to be channelled through this transport.
54 """
55 uri = URI(url)
56 if uri.scheme != 'lp-mirrored':
57 raise InvalidStackedBranchURL(url)
58
59 def transformFallbackLocation(self, branch, url):
60 """See `BranchPolicy.transformFallbackLocation`.
61
62 We're happy to open stacked branches in the usual manner, but want to
63 go on checking the URLs of any branches we then open.
64 """
65 return urlutils.join(branch.base, url), True
66
67
68class BzrSync:35class BzrSync:
69 """Import version control metadata from a Bazaar branch into the database.36 """Import version control metadata from a Bazaar branch into the database.
70 """37 """
7138
=== modified file 'lib/lp/codehosting/scanner/tests/test_buglinks.py'
--- lib/lp/codehosting/scanner/tests/test_buglinks.py 2010-03-02 18:56:25 +0000
+++ lib/lp/codehosting/scanner/tests/test_buglinks.py 2010-04-27 02:23:46 +0000
@@ -246,7 +246,7 @@
246246
247 def test_got_new_revision_subscribed(self):247 def test_got_new_revision_subscribed(self):
248 """got_new_revision is subscribed to NewRevision."""248 """got_new_revision is subscribed to NewRevision."""
249 self.useBzrBranches()249 self.useBzrBranches(direct_database=True)
250 db_branch, tree = self.create_branch_and_tree()250 db_branch, tree = self.create_branch_and_tree()
251 bug = self.factory.makeBug()251 bug = self.factory.makeBug()
252 self.layer.txn.commit()252 self.layer.txn.commit()
253253
=== modified file 'lib/lp/codehosting/scanner/tests/test_bzrsync.py'
--- lib/lp/codehosting/scanner/tests/test_bzrsync.py 2010-04-27 02:23:41 +0000
+++ lib/lp/codehosting/scanner/tests/test_bzrsync.py 2010-04-27 02:23:46 +0000
@@ -13,9 +13,6 @@
13import unittest13import unittest
1414
15from bzrlib.revision import NULL_REVISION, Revision as BzrRevision15from bzrlib.revision import NULL_REVISION, Revision as BzrRevision
16from bzrlib.transport import (
17 get_transport, register_transport, unregister_transport)
18from bzrlib.transport.chroot import ChrootServer
19from bzrlib.uncommit import uncommit16from bzrlib.uncommit import uncommit
20from bzrlib.tests import TestCaseWithTransport17from bzrlib.tests import TestCaseWithTransport
21import pytz18import pytz
@@ -32,9 +29,8 @@
32from lp.code.model.branchrevision import BranchRevision29from lp.code.model.branchrevision import BranchRevision
33from lp.code.model.branchmergeproposaljob import IUpdatePreviewDiffJobSource30from lp.code.model.branchmergeproposaljob import IUpdatePreviewDiffJobSource
34from lp.code.model.revision import Revision, RevisionAuthor, RevisionParent31from lp.code.model.revision import Revision, RevisionAuthor, RevisionParent
35from lp.codehosting.scanner.bzrsync import (32from lp.codehosting.scanner.bzrsync import BzrSync
36 BzrSync, InvalidStackedBranchURL)33from lp.testing import TestCaseWithFactory
37from lp.testing.factory import LaunchpadObjectFactory
38from canonical.testing import LaunchpadZopelessLayer34from canonical.testing import LaunchpadZopelessLayer
3935
4036
@@ -55,44 +51,7 @@
55 return _run_with_different_user51 return _run_with_different_user
5652
5753
58class FakeTransportServer:54class BzrSyncTestCase(TestCaseWithTransport, TestCaseWithFactory):
59 """Set up a fake transport at a given URL prefix.
60
61 For testing purposes.
62 """
63
64 def __init__(self, transport, url_prefix='lp-mirrored:///'):
65 """Constructor.
66
67 :param transport: The backing transport to store the data with.
68 :param url_prefix: The URL prefix to access this transport.
69 """
70 self._transport = transport
71 self._url_prefix = url_prefix
72 self._chroot_server = None
73
74 def start_server(self):
75 """Activate the transport URL."""
76 # The scanner tests assume that branches live on a Launchpad virtual
77 # filesystem rooted at 'lp-mirrored:///'. Rather than provide the
78 # entire virtual filesystem here, we fake it by having a chrooted
79 # transport do the work.
80 register_transport(self._url_prefix, self._transportFactory)
81 self._chroot_server = ChrootServer(self._transport)
82 self._chroot_server.start_server()
83
84 def stop_server(self):
85 """Deactivate the transport URL."""
86 self._chroot_server.stop_server()
87 unregister_transport(self._url_prefix, self._transportFactory)
88
89 def _transportFactory(self, url):
90 assert url.startswith(self._url_prefix)
91 url = self._chroot_server.get_url() + url[len(self._url_prefix):]
92 return get_transport(url)
93
94
95class BzrSyncTestCase(TestCaseWithTransport):
96 """Common base for BzrSync test cases."""55 """Common base for BzrSync test cases."""
9756
98 layer = LaunchpadZopelessLayer57 layer = LaunchpadZopelessLayer
@@ -101,21 +60,17 @@
10160
102 def setUp(self):61 def setUp(self):
103 TestCaseWithTransport.setUp(self)62 TestCaseWithTransport.setUp(self)
104 self.factory = LaunchpadObjectFactory()63 TestCaseWithFactory.setUp(self)
64 self.disable_directory_isolation()
65 self.useBzrBranches(direct_database=True)
66 self.lp_db_user = config.launchpad.dbuser
105 self.makeFixtures()67 self.makeFixtures()
106 self.lp_db_user = config.launchpad.dbuser
107 LaunchpadZopelessLayer.switchDbUser(config.branchscanner.dbuser)68 LaunchpadZopelessLayer.switchDbUser(config.branchscanner.dbuser)
108 # The lp-mirrored transport is set up by the branch_scanner module.
109 # Here we set up a fake so that we can test without worrying about
110 # authservers and the like.
111 server = FakeTransportServer(self.get_transport())
112 server.start_server()
113 self.addCleanup(server.stop_server)
11469
115 def makeFixtures(self):70 def makeFixtures(self):
116 """Makes test fixtures before we switch to the scanner db user."""71 """Makes test fixtures before we switch to the scanner db user."""
117 self.db_branch = self.makeDatabaseBranch()72 self.db_branch, self.bzr_tree = self.create_branch_and_tree(
118 self.bzr_tree = self.makeBzrBranchAndTree(self.db_branch)73 db_branch=self.makeDatabaseBranch())
119 self.bzr_branch = self.bzr_tree.branch74 self.bzr_branch = self.bzr_tree.branch
12075
121 def syncBazaarBranchToDatabase(self, bzr_branch, db_branch):76 def syncBazaarBranchToDatabase(self, bzr_branch, db_branch):
@@ -123,11 +78,6 @@
123 syncer = self.makeBzrSync(db_branch)78 syncer = self.makeBzrSync(db_branch)
124 syncer.syncBranchAndClose(bzr_branch)79 syncer.syncBranchAndClose(bzr_branch)
12580
126 def makeBzrBranchAndTree(self, db_branch, format=None):
127 """Make a Bazaar branch at the warehouse location of `db_branch`."""
128 self.get_transport(db_branch.unique_name).create_prefix()
129 return self.make_branch_and_tree(db_branch.unique_name, format=format)
130
131 def makeDatabaseBranch(self, *args, **kwargs):81 def makeDatabaseBranch(self, *args, **kwargs):
132 """Make an arbitrary branch in the database."""82 """Make an arbitrary branch in the database."""
133 LaunchpadZopelessLayer.txn.begin()83 LaunchpadZopelessLayer.txn.begin()
@@ -248,12 +198,14 @@
248198
249 # Make the base revision.199 # Make the base revision.
250 db_branch = self.makeDatabaseBranch()200 db_branch = self.makeDatabaseBranch()
251 trunk_tree = self.makeBzrBranchAndTree(db_branch)201 db_branch, trunk_tree = self.create_branch_and_tree(
202 db_branch=db_branch)
252 trunk_tree.commit(u'base revision', rev_id=base_rev_id)203 trunk_tree.commit(u'base revision', rev_id=base_rev_id)
253204
254 # Branch from the base revision.205 # Branch from the base revision.
255 new_db_branch = self.makeDatabaseBranch(product=db_branch.product)206 new_db_branch = self.makeDatabaseBranch(product=db_branch.product)
256 branch_tree = self.makeBzrBranchAndTree(new_db_branch)207 new_db_branch, branch_tree = self.create_branch_and_tree(
208 db_branch=new_db_branch)
257 branch_tree.pull(trunk_tree.branch)209 branch_tree.pull(trunk_tree.branch)
258210
259 # Commit to both branches.211 # Commit to both branches.
@@ -517,7 +469,7 @@
517 (branch_revision.revision.revision_id, branch_revision.id)469 (branch_revision.revision.revision_id, branch_revision.id)
518 for branch_revision in sampledata)470 for branch_revision in sampledata)
519471
520 self.makeBzrBranchAndTree(branch)472 self.create_branch_and_tree(db_branch=branch)
521473
522 bzrsync = self.makeBzrSync(branch)474 bzrsync = self.makeBzrSync(branch)
523 db_ancestry, db_history, db_branch_revision_map = (475 db_ancestry, db_history, db_branch_revision_map = (
@@ -527,37 +479,6 @@
527 self.assertEqual(expected_mapping, db_branch_revision_map)479 self.assertEqual(expected_mapping, db_branch_revision_map)
528480
529481
530class TestScanStackedBranches(BzrSyncTestCase):
531 """Tests for scanning stacked branches."""
532
533 @run_as_db_user(config.launchpad.dbuser)
534 def testStackedBranchBadURL(self):
535 # The scanner will raise an InvalidStackedBranchURL when it tries to
536 # open a branch stacked on a non- lp-mirrored:// schema.
537 db_branch = self.makeDatabaseBranch()
538 stacked_on_branch = self.make_branch('stacked-on', format='1.6')
539 self.assertFalse(stacked_on_branch.base.startswith('lp-mirrored://'))
540 bzr_tree = self.makeBzrBranchAndTree(db_branch, format='1.6')
541 bzr_tree.branch.set_stacked_on_url(stacked_on_branch.base)
542 scanner = self.makeBzrSync(db_branch)
543 self.assertRaises(InvalidStackedBranchURL, scanner.syncBranchAndClose)
544
545 @run_as_db_user(config.launchpad.dbuser)
546 def testStackedBranch(self):
547 # We can scan a stacked branch that's stacked on a branch that has an
548 # lp-mirrored:// URL.
549 db_stacked_on_branch = self.factory.makeAnyBranch()
550 self.makeBzrBranchAndTree(db_stacked_on_branch, format='1.6')
551 db_stacked_branch = self.factory.makeAnyBranch()
552 stacked_tree = self.makeBzrBranchAndTree(
553 db_stacked_branch, format='1.6')
554 stacked_tree.branch.set_stacked_on_url(
555 'lp-mirrored:///%s' % db_stacked_on_branch.unique_name)
556 scanner = self.makeBzrSync(db_stacked_branch)
557 # This does not raise an exception.
558 scanner.syncBranchAndClose()
559
560
561class TestBzrSyncOneRevision(BzrSyncTestCase):482class TestBzrSyncOneRevision(BzrSyncTestCase):
562 """Tests for `BzrSync.syncOneRevision`."""483 """Tests for `BzrSync.syncOneRevision`."""
563484
@@ -594,9 +515,6 @@
594class TestBzrTranslationsUploadJob(BzrSyncTestCase):515class TestBzrTranslationsUploadJob(BzrSyncTestCase):
595 """Tests BzrSync support for generating TranslationsUploadJobs."""516 """Tests BzrSync support for generating TranslationsUploadJobs."""
596517
597 def setUp(self):
598 BzrSyncTestCase.setUp(self)
599
600 def _makeProductSeries(self, mode = None):518 def _makeProductSeries(self, mode = None):
601 """Switch to the Launchpad db user to create and configure a519 """Switch to the Launchpad db user to create and configure a
602 product series that is linked to the the branch.520 product series that is linked to the the branch.
@@ -647,10 +565,6 @@
647class TestUpdatePreviewDiffJob(BzrSyncTestCase):565class TestUpdatePreviewDiffJob(BzrSyncTestCase):
648 """Test the scheduling of jobs to update preview diffs."""566 """Test the scheduling of jobs to update preview diffs."""
649567
650 def setUp(self):
651 """Set up `schedule_diff_updates` to handle tip changes."""
652 BzrSyncTestCase.setUp(self)
653
654 @run_as_db_user(config.launchpad.dbuser)568 @run_as_db_user(config.launchpad.dbuser)
655 def test_create_on_new_revision(self):569 def test_create_on_new_revision(self):
656 """When branch tip changes, a job is created."""570 """When branch tip changes, a job is created."""
657571
=== modified file 'lib/lp/codehosting/scanner/tests/test_email.py'
--- lib/lp/codehosting/scanner/tests/test_email.py 2010-02-26 21:40:42 +0000
+++ lib/lp/codehosting/scanner/tests/test_email.py 2010-04-27 02:23:46 +0000
@@ -142,7 +142,7 @@
142142
143 def test_queue_tip_changed_email_jobs_subscribed(self):143 def test_queue_tip_changed_email_jobs_subscribed(self):
144 """A queue_tip_changed_email_jobs is run when TipChanged emitted."""144 """A queue_tip_changed_email_jobs is run when TipChanged emitted."""
145 self.useBzrBranches()145 self.useBzrBranches(direct_database=True)
146 db_branch, tree = self.create_branch_and_tree()146 db_branch, tree = self.create_branch_and_tree()
147 db_branch.subscribe(147 db_branch.subscribe(
148 db_branch.registrant,148 db_branch.registrant,
@@ -155,7 +155,7 @@
155155
156 def test_send_removed_revision_emails_subscribed(self):156 def test_send_removed_revision_emails_subscribed(self):
157 """send_removed_revision_emails run when RevisionsRemoved emitted."""157 """send_removed_revision_emails run when RevisionsRemoved emitted."""
158 self.useBzrBranches()158 self.useBzrBranches(direct_database=True)
159 db_branch, tree = self.create_branch_and_tree()159 db_branch, tree = self.create_branch_and_tree()
160 db_branch.subscribe(160 db_branch.subscribe(
161 db_branch.registrant,161 db_branch.registrant,

Subscribers

People subscribed via source and target branches

to status/vote changes: