Merge lp:~jtv/launchpad/fakelibrarian-commit 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: 11420
Proposed branch: lp:~jtv/launchpad/fakelibrarian-commit
Merge into: lp:launchpad
Diff against target: 54 lines (+23/-3)
2 files modified
lib/lp/testing/fakelibrarian.py (+14/-3)
lib/lp/testing/tests/test_fakelibrarian.py (+9/-0)
To merge this branch: bzr merge lp:~jtv/launchpad/fakelibrarian-commit
Reviewer Review Type Date Requested Status
Abel Deuring (community) code Approve
Robert Collins code Pending
Review via email: mp+33322@code.launchpad.net

Commit message

FakeLibrarian.pretendCommit

Description of the change

= FakeLibrarian commit =

The FakeLibrarian is a usable substitute for the Librarian in tests that only need the librarian inside their own process. Like the real Librarian, the FakeLibrarian makes a file available only after you commit the transaction that added it.

This branch adds a "fake commit" method to the fake librarian. The fake commit allows tests to add files to the fake librarian and continue using them as if there had been a commit—but without incurring a database commit. Commits in tests can be quite costly because they make it necessary to restore a pristine test database for the next test.

To post a comment you must log in.
Revision history for this message
Abel Deuring (adeuring) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/testing/fakelibrarian.py'
--- lib/lp/testing/fakelibrarian.py 2010-08-20 20:31:18 +0000
+++ lib/lp/testing/fakelibrarian.py 2010-08-22 09:27:48 +0000
@@ -151,6 +151,19 @@
151 alias.checkCommitted()151 alias.checkCommitted()
152 return StringIO(alias.content_string)152 return StringIO(alias.content_string)
153153
154 def pretendCommit(self):
155 """Pretend that there's been a commit.
156
157 When you add a file to the librarian (real or fake), it is not
158 fully available until the transaction that added the file has
159 been committed. Call this method to make the FakeLibrarian act
160 as if there's been a commit, without actually committing a
161 database transaction.
162 """
163 # Note that all files have been committed to storage.
164 for alias in self.aliases.itervalues():
165 alias.file_committed = True
166
154 def _makeAlias(self, file_id, name, content, content_type):167 def _makeAlias(self, file_id, name, content, content_type):
155 """Create a `LibraryFileAlias`."""168 """Create a `LibraryFileAlias`."""
156 alias = InstrumentedLibraryFileAlias(169 alias = InstrumentedLibraryFileAlias(
@@ -195,9 +208,7 @@
195208
196 def afterCompletion(self, txn):209 def afterCompletion(self, txn):
197 """See `ISynchronizer`."""210 """See `ISynchronizer`."""
198 # Note that all files have been committed to storage.211 self.pretendCommit()
199 for alias in self.aliases.itervalues():
200 alias.file_committed = True
201212
202 def newTransaction(self, txn):213 def newTransaction(self, txn):
203 """See `ISynchronizer`."""214 """See `ISynchronizer`."""
204215
=== modified file 'lib/lp/testing/tests/test_fakelibrarian.py'
--- lib/lp/testing/tests/test_fakelibrarian.py 2010-08-20 20:31:18 +0000
+++ lib/lp/testing/tests/test_fakelibrarian.py 2010-08-22 09:27:48 +0000
@@ -109,6 +109,15 @@
109 self.assertTrue(verifyObject(ISynchronizer, self.fake_librarian))109 self.assertTrue(verifyObject(ISynchronizer, self.fake_librarian))
110 self.assertIsInstance(self.fake_librarian, FakeLibrarian)110 self.assertIsInstance(self.fake_librarian, FakeLibrarian)
111111
112 def test_pretend_commit(self):
113 name, text, alias_id = self._storeFile()
114
115 self.fake_librarian.pretendCommit()
116
117 retrieved_alias = getUtility(ILibraryFileAliasSet)[alias_id]
118 retrieved_alias.open()
119 self.assertEqual(text, retrieved_alias.read())
120
112121
113class TestRealLibrarian(LibraryAccessScenarioMixin, TestCaseWithFactory):122class TestRealLibrarian(LibraryAccessScenarioMixin, TestCaseWithFactory):
114 """Test the supported interface subset on the real librarian."""123 """Test the supported interface subset on the real librarian."""