~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_hooks.py

  • Committer: Andrew Bennetts
  • Date: 2009-03-06 07:06:43 UTC
  • mto: (4086.1.1 hpss-integration)
  • mto: This revision was merged to the branch mainline in revision 4087.
  • Revision ID: andrew.bennetts@canonical.com-20090306070643-iwpe2aqu0k2pg3s6
Adjust test_hooks.py for create_branch RPC.

Show diffs side-by-side

added added

removed removed

Lines of Context:
148
148
        b = self.make_branch('.')
149
149
        if isinstance(b, RemoteBranch):
150
150
            # RemoteBranch creation:
151
 
            # - creates the branch via the VFS (for older servers)
152
 
            # - does a branch open (by creating a RemoteBranch object)
153
 
            # - this has the nearly the same behaviour as simple branch opening
154
151
            if (self.transport_readonly_server ==
155
152
                server.ReadonlySmartTCPServer_for_testing_v2_only):
156
153
                # Older servers:
 
154
                self.assertEqual(3, len(self.hook_calls))
 
155
                # creates the branch via the VFS (for older servers)
157
156
                self.assertEqual(b._real_branch, self.hook_calls[0])
158
 
                self.assertOpenedRemoteBranch(self.hook_calls[1:], b)
 
157
                # creates a RemoteBranch object
 
158
                self.assertEqual(b, self.hook_calls[1])
 
159
                # get_stacked_on_url RPC
 
160
                self.assertRealBranch(self.hook_calls[2])
159
161
            else:
160
 
                self.assertOpenedRemoteBranch(self.hook_calls, b,
161
 
                    remote_first=True)
 
162
                self.assertEqual(2, len(self.hook_calls))
 
163
                # create_branch RPC
 
164
                self.assertRealBranch(self.hook_calls[0])
 
165
                # create RemoteBranch locally
 
166
                self.assertEqual(b, self.hook_calls[1])
162
167
        else:
163
168
            self.assertEqual([b], self.hook_calls)
164
169
 
167
172
        self.install_hook()
168
173
        b = Branch.open(branch_url)
169
174
        if isinstance(b, RemoteBranch):
170
 
            self.assertOpenedRemoteBranch(self.hook_calls, b)
 
175
            self.assertEqual(3, len(self.hook_calls))
 
176
            # open_branchV2 RPC
 
177
            self.assertRealBranch(self.hook_calls[0])
 
178
            # create RemoteBranch locally
 
179
            self.assertEqual(b, self.hook_calls[1])
 
180
            # get_stacked_on_url RPC
 
181
            self.assertRealBranch(self.hook_calls[2])
171
182
        else:
172
183
            self.assertEqual([b], self.hook_calls)
173
184
 
174
 
    def assertOpenedRemoteBranch(self, hook_calls, b, remote_first=False):
175
 
        """Assert that the expected calls were recorded for opening 'b'.
176
 
 
177
 
        :param remote_first: If True expect the server side operation to open
178
 
            the branch object first.
179
 
        """
180
 
        # RemoteBranch open always opens the backing branch to get stacking
181
 
        # details. As that is done remotely we can't see the branch object
182
 
        # nor even compare base url's etc. So we just assert that the first
183
 
        # branch returned is the RemoteBranch, and that the second is a
184
 
        # Branch but not a RemoteBranch.
185
 
        #
186
 
        # RemoteBranch *creation* on the other hand creates the branch object
187
 
        # on the server, and then creates the local proxy object in the client,
188
 
        # so it sees the reverse order.
189
 
        self.assertEqual(2, len(hook_calls))
190
 
        if remote_first:
191
 
            real_index = 0
192
 
            remote_index = 1
193
 
        else:
194
 
            real_index = 1
195
 
            remote_index = 0
196
 
        self.assertEqual(b, hook_calls[remote_index])
197
 
        self.assertIsInstance(hook_calls[real_index], Branch)
198
 
        self.assertFalse(isinstance(hook_calls[real_index], RemoteBranch))
 
185
    def assertRealBranch(self, b):
 
186
        # Branches opened on the server don't have comparable URLs, so we just
 
187
        # assert that it is not a RemoteBranch.
 
188
        self.assertIsInstance(b, Branch)
 
189
        self.assertFalse(isinstance(b, RemoteBranch))
199
190
 
200
191
 
201
192
class TestPreChangeBranchTip(ChangeBranchTipTestCase):