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
1=== modified file 'lib/lp/testing/__init__.py'
2--- lib/lp/testing/__init__.py 2010-08-24 17:11:12 +0000
3+++ lib/lp/testing/__init__.py 2010-08-27 11:26:31 +0000
4@@ -3,7 +3,6 @@
5
6 # pylint: disable-msg=W0401,C0301,F0401
7
8-
9 from __future__ import with_statement
10
11
12@@ -287,9 +286,11 @@
13 `addCleanup`).
14
15 :param fixture: Any object that has a `setUp` and `tearDown` method.
16+ :return: `fixture`.
17 """
18 fixture.setUp()
19 self.addCleanup(fixture.tearDown)
20+ return fixture
21
22 def __str__(self):
23 """The string representation of a test is its id.
24@@ -575,7 +576,8 @@
25 bzr_branch = self.createBranchAtURL(db_branch.getInternalBzrUrl())
26 if parent:
27 bzr_branch.pull(parent)
28- removeSecurityProxy(db_branch).last_scanned_id = bzr_branch.last_revision()
29+ naked_branch = removeSecurityProxy(db_branch)
30+ naked_branch.last_scanned_id = bzr_branch.last_revision()
31 return bzr_branch
32
33 @staticmethod
34@@ -631,6 +633,7 @@
35 This testcase provides an API similar to page tests, and can be used for
36 cases when one wants a unit test and not a frakking pagetest.
37 """
38+
39 def setUp(self):
40 """Provide useful defaults."""
41 super(BrowserTestCase, self).setUp()
42@@ -764,7 +767,7 @@
43 # unlikely that any one approach is going to work for every
44 # class. It's better to fail early and draw attention here.
45 assert isinstance(result, ZopeTestResult), (
46- "result must be a Zope result object, not %r." % (result,))
47+ "result must be a Zope result object, not %r." % (result, ))
48 pread, pwrite = os.pipe()
49 pid = os.fork()
50 if pid == 0:
51
52=== modified file 'lib/lp/testing/fakelibrarian.py'
53--- lib/lp/testing/fakelibrarian.py 2010-08-24 16:08:16 +0000
54+++ lib/lp/testing/fakelibrarian.py 2010-08-27 11:26:31 +0000
55@@ -115,6 +115,14 @@
56
57 self.installed_as_librarian = False
58
59+ def setUp(self):
60+ """Fixture API: install as the librarian."""
61+ self.installAsLibrarian()
62+
63+ def tearDown(self):
64+ """Fixture API: uninstall."""
65+ self.uninstall()
66+
67 def __init__(self):
68 self.aliases = {}
69 self.download_url = config.librarian.download_url
70@@ -183,8 +191,7 @@
71 def create(self, name, size, file, contentType, expires=None,
72 debugID=None, restricted=False):
73 "See `ILibraryFileAliasSet`."""
74- return self.addFile(
75- name, size, file, contentType, expires=expires, debugID=debugID)
76+ return self.addFile(name, size, file, contentType, expires=expires)
77
78 def __getitem__(self, key):
79 "See `ILibraryFileAliasSet`."""
80
81=== modified file 'lib/lp/testing/tests/test_fakelibrarian.py'
82--- lib/lp/testing/tests/test_fakelibrarian.py 2010-08-24 16:08:16 +0000
83+++ lib/lp/testing/tests/test_fakelibrarian.py 2010-08-27 11:26:31 +0000
84@@ -90,6 +90,13 @@
85 getUtility(ILibrarianClient).addFile,
86 name, wrong_length, StringIO(text), 'text/plain')
87
88+ def test_debugID_is_harmless(self):
89+ # addFile takes an argument debugID that doesn't do anything
90+ # observable. We get a LibraryFileAlias regardless.
91+ alias_id = getUtility(ILibraryFileAliasSet).create(
92+ 'txt.txt', 3, StringIO('txt'), 'text/plain', debugID='txt')
93+ self.assertNotEqual(None, alias_id)
94+
95
96 class TestFakeLibrarian(LibraryAccessScenarioMixin, TestCaseWithFactory):
97 """Test the supported interface subset on the fake librarian."""
98@@ -98,12 +105,7 @@
99
100 def setUp(self):
101 super(TestFakeLibrarian, self).setUp()
102- self.fake_librarian = FakeLibrarian()
103- self.fake_librarian.installAsLibrarian()
104-
105- def tearDown(self):
106- super(TestFakeLibrarian, self).tearDown()
107- self.fake_librarian.uninstall()
108+ self.fake_librarian = self.installFixture(FakeLibrarian())
109
110 def test_fake(self):
111 self.assertTrue(verifyObject(ISynchronizer, self.fake_librarian))
112
113=== modified file 'lib/lp/translations/utilities/tests/test_file_importer.py'
114--- lib/lp/translations/utilities/tests/test_file_importer.py 2010-08-22 10:07:55 +0000
115+++ lib/lp/translations/utilities/tests/test_file_importer.py 2010-08-27 11:26:31 +0000
116@@ -167,15 +167,10 @@
117
118 def setUp(self):
119 super(FileImporterTestCase, self).setUp()
120- self.fake_librarian = FakeLibrarian()
121- self.fake_librarian.installAsLibrarian()
122+ self.fake_librarian = self.installFixture(FakeLibrarian())
123 self.translation_import_queue = getUtility(ITranslationImportQueue)
124 self.importer_person = self.factory.makePerson()
125
126- def tearDown(self):
127- self.fake_librarian.uninstall()
128- super(FileImporterTestCase, self).tearDown()
129-
130 def test_FileImporter_importMessage_NotImplemented(self):
131 importer = self._createFileImporter()
132 self.failUnlessRaises(NotImplementedError,
133@@ -501,15 +496,10 @@
134
135 def setUp(self):
136 super(CreateFileImporterTestCase, self).setUp()
137- self.fake_librarian = FakeLibrarian()
138- self.fake_librarian.installAsLibrarian()
139+ self.fake_librarian = self.installFixture(FakeLibrarian())
140 self.translation_import_queue = getUtility(ITranslationImportQueue)
141 self.importer_person = self.factory.makePerson()
142
143- def tearDown(self):
144- self.fake_librarian.uninstall()
145- super(CreateFileImporterTestCase, self).tearDown()
146-
147 def _make_queue_entry(self, is_published):
148 pofile = self.factory.makePOFile('eo')
149 # Create a header with a newer date than what is found in