Merge lp:~jtv/launchpad/fakelibrarian-fixture into lp:launchpad

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: no longer in the source branch.
Merged at revision: 11463
Proposed branch: lp:~jtv/launchpad/fakelibrarian-fixture
Merge into: lp:launchpad
Diff against target: 149 lines (+25/-23)
4 files modified
lib/lp/testing/__init__.py (+6/-3)
lib/lp/testing/fakelibrarian.py (+9/-2)
lib/lp/testing/tests/test_fakelibrarian.py (+8/-6)
lib/lp/translations/utilities/tests/test_file_importer.py (+2/-12)
To merge this branch: bzr merge lp:~jtv/launchpad/fakelibrarian-fixture
Reviewer Review Type Date Requested Status
Julian Edwards (community) Approve
Review via email: mp+33892@code.launchpad.net

Commit message

Make FakeLibrarian a fixture; ignore debugID parameter to create().

Description of the change

= Two FakeLibrarian improvements =

Two frankly unrelated fixes for the FakeLibrarian:
 * It's now usable as as test fixture, as in TestCase.installFixture.
 * create() now ignores its debugID parameter to fix problems for Soyuz.

Also,
 * TestCase.installFixture now returns its argument, making setup more convenient.

To test:
{{{
./bin/test -vvc -m lp.testing.tests.test_fakelibrarian
./bin/test -vvc -m lp.translations.utilities.tests.test_file_import
}}}

No lint that I had anything to do with. I did clean up some existing lint.

Jeroen

To post a comment you must log in.
Revision history for this message
Julian Edwards (julian-edwards) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/testing/__init__.py'
--- lib/lp/testing/__init__.py 2010-08-24 17:11:12 +0000
+++ lib/lp/testing/__init__.py 2010-08-27 11:26:31 +0000
@@ -3,7 +3,6 @@
33
4# pylint: disable-msg=W0401,C0301,F04014# pylint: disable-msg=W0401,C0301,F0401
55
6
7from __future__ import with_statement6from __future__ import with_statement
87
98
@@ -287,9 +286,11 @@
287 `addCleanup`).286 `addCleanup`).
288287
289 :param fixture: Any object that has a `setUp` and `tearDown` method.288 :param fixture: Any object that has a `setUp` and `tearDown` method.
289 :return: `fixture`.
290 """290 """
291 fixture.setUp()291 fixture.setUp()
292 self.addCleanup(fixture.tearDown)292 self.addCleanup(fixture.tearDown)
293 return fixture
293294
294 def __str__(self):295 def __str__(self):
295 """The string representation of a test is its id.296 """The string representation of a test is its id.
@@ -575,7 +576,8 @@
575 bzr_branch = self.createBranchAtURL(db_branch.getInternalBzrUrl())576 bzr_branch = self.createBranchAtURL(db_branch.getInternalBzrUrl())
576 if parent:577 if parent:
577 bzr_branch.pull(parent)578 bzr_branch.pull(parent)
578 removeSecurityProxy(db_branch).last_scanned_id = bzr_branch.last_revision()579 naked_branch = removeSecurityProxy(db_branch)
580 naked_branch.last_scanned_id = bzr_branch.last_revision()
579 return bzr_branch581 return bzr_branch
580582
581 @staticmethod583 @staticmethod
@@ -631,6 +633,7 @@
631 This testcase provides an API similar to page tests, and can be used for633 This testcase provides an API similar to page tests, and can be used for
632 cases when one wants a unit test and not a frakking pagetest.634 cases when one wants a unit test and not a frakking pagetest.
633 """635 """
636
634 def setUp(self):637 def setUp(self):
635 """Provide useful defaults."""638 """Provide useful defaults."""
636 super(BrowserTestCase, self).setUp()639 super(BrowserTestCase, self).setUp()
@@ -764,7 +767,7 @@
764 # unlikely that any one approach is going to work for every767 # unlikely that any one approach is going to work for every
765 # class. It's better to fail early and draw attention here.768 # class. It's better to fail early and draw attention here.
766 assert isinstance(result, ZopeTestResult), (769 assert isinstance(result, ZopeTestResult), (
767 "result must be a Zope result object, not %r." % (result,))770 "result must be a Zope result object, not %r." % (result, ))
768 pread, pwrite = os.pipe()771 pread, pwrite = os.pipe()
769 pid = os.fork()772 pid = os.fork()
770 if pid == 0:773 if pid == 0:
771774
=== modified file 'lib/lp/testing/fakelibrarian.py'
--- lib/lp/testing/fakelibrarian.py 2010-08-24 16:08:16 +0000
+++ lib/lp/testing/fakelibrarian.py 2010-08-27 11:26:31 +0000
@@ -115,6 +115,14 @@
115115
116 self.installed_as_librarian = False116 self.installed_as_librarian = False
117117
118 def setUp(self):
119 """Fixture API: install as the librarian."""
120 self.installAsLibrarian()
121
122 def tearDown(self):
123 """Fixture API: uninstall."""
124 self.uninstall()
125
118 def __init__(self):126 def __init__(self):
119 self.aliases = {}127 self.aliases = {}
120 self.download_url = config.librarian.download_url128 self.download_url = config.librarian.download_url
@@ -183,8 +191,7 @@
183 def create(self, name, size, file, contentType, expires=None,191 def create(self, name, size, file, contentType, expires=None,
184 debugID=None, restricted=False):192 debugID=None, restricted=False):
185 "See `ILibraryFileAliasSet`."""193 "See `ILibraryFileAliasSet`."""
186 return self.addFile(194 return self.addFile(name, size, file, contentType, expires=expires)
187 name, size, file, contentType, expires=expires, debugID=debugID)
188195
189 def __getitem__(self, key):196 def __getitem__(self, key):
190 "See `ILibraryFileAliasSet`."""197 "See `ILibraryFileAliasSet`."""
191198
=== modified file 'lib/lp/testing/tests/test_fakelibrarian.py'
--- lib/lp/testing/tests/test_fakelibrarian.py 2010-08-24 16:08:16 +0000
+++ lib/lp/testing/tests/test_fakelibrarian.py 2010-08-27 11:26:31 +0000
@@ -90,6 +90,13 @@
90 getUtility(ILibrarianClient).addFile,90 getUtility(ILibrarianClient).addFile,
91 name, wrong_length, StringIO(text), 'text/plain')91 name, wrong_length, StringIO(text), 'text/plain')
9292
93 def test_debugID_is_harmless(self):
94 # addFile takes an argument debugID that doesn't do anything
95 # observable. We get a LibraryFileAlias regardless.
96 alias_id = getUtility(ILibraryFileAliasSet).create(
97 'txt.txt', 3, StringIO('txt'), 'text/plain', debugID='txt')
98 self.assertNotEqual(None, alias_id)
99
93100
94class TestFakeLibrarian(LibraryAccessScenarioMixin, TestCaseWithFactory):101class TestFakeLibrarian(LibraryAccessScenarioMixin, TestCaseWithFactory):
95 """Test the supported interface subset on the fake librarian."""102 """Test the supported interface subset on the fake librarian."""
@@ -98,12 +105,7 @@
98105
99 def setUp(self):106 def setUp(self):
100 super(TestFakeLibrarian, self).setUp()107 super(TestFakeLibrarian, self).setUp()
101 self.fake_librarian = FakeLibrarian()108 self.fake_librarian = self.installFixture(FakeLibrarian())
102 self.fake_librarian.installAsLibrarian()
103
104 def tearDown(self):
105 super(TestFakeLibrarian, self).tearDown()
106 self.fake_librarian.uninstall()
107109
108 def test_fake(self):110 def test_fake(self):
109 self.assertTrue(verifyObject(ISynchronizer, self.fake_librarian))111 self.assertTrue(verifyObject(ISynchronizer, self.fake_librarian))
110112
=== modified file 'lib/lp/translations/utilities/tests/test_file_importer.py'
--- lib/lp/translations/utilities/tests/test_file_importer.py 2010-08-22 10:07:55 +0000
+++ lib/lp/translations/utilities/tests/test_file_importer.py 2010-08-27 11:26:31 +0000
@@ -167,15 +167,10 @@
167167
168 def setUp(self):168 def setUp(self):
169 super(FileImporterTestCase, self).setUp()169 super(FileImporterTestCase, self).setUp()
170 self.fake_librarian = FakeLibrarian()170 self.fake_librarian = self.installFixture(FakeLibrarian())
171 self.fake_librarian.installAsLibrarian()
172 self.translation_import_queue = getUtility(ITranslationImportQueue)171 self.translation_import_queue = getUtility(ITranslationImportQueue)
173 self.importer_person = self.factory.makePerson()172 self.importer_person = self.factory.makePerson()
174173
175 def tearDown(self):
176 self.fake_librarian.uninstall()
177 super(FileImporterTestCase, self).tearDown()
178
179 def test_FileImporter_importMessage_NotImplemented(self):174 def test_FileImporter_importMessage_NotImplemented(self):
180 importer = self._createFileImporter()175 importer = self._createFileImporter()
181 self.failUnlessRaises(NotImplementedError,176 self.failUnlessRaises(NotImplementedError,
@@ -501,15 +496,10 @@
501496
502 def setUp(self):497 def setUp(self):
503 super(CreateFileImporterTestCase, self).setUp()498 super(CreateFileImporterTestCase, self).setUp()
504 self.fake_librarian = FakeLibrarian()499 self.fake_librarian = self.installFixture(FakeLibrarian())
505 self.fake_librarian.installAsLibrarian()
506 self.translation_import_queue = getUtility(ITranslationImportQueue)500 self.translation_import_queue = getUtility(ITranslationImportQueue)
507 self.importer_person = self.factory.makePerson()501 self.importer_person = self.factory.makePerson()
508502
509 def tearDown(self):
510 self.fake_librarian.uninstall()
511 super(CreateFileImporterTestCase, self).tearDown()
512
513 def _make_queue_entry(self, is_published):503 def _make_queue_entry(self, is_published):
514 pofile = self.factory.makePOFile('eo')504 pofile = self.factory.makePOFile('eo')
515 # Create a header with a newer date than what is found in505 # Create a header with a newer date than what is found in