~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

Add a Branch.set_last_revision smart method, and make RemoteBranch.set_revision_history use it.  Also some test tweaks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
155
155
        self.assertEqual((2, u'\xc8'), result)
156
156
 
157
157
 
 
158
class TestBranchSetLastRevision(tests.TestCase):
 
159
 
 
160
    def test_set_empty(self):
 
161
        # set_revision_history([]) is translated to calling
 
162
        # Branch.set_last_revision(path, '') on the wire.
 
163
        client = FakeClient([(('ok',), )])
 
164
        transport = MemoryTransport()
 
165
        transport.mkdir('branch')
 
166
        transport = transport.clone('branch')
 
167
 
 
168
        bzrdir = RemoteBzrDir(transport, _client=False)
 
169
        branch = RemoteBranch(bzrdir, None, _client=client)
 
170
 
 
171
        result = branch.set_revision_history([])
 
172
        self.assertEqual(
 
173
            [('call', 'Branch.set_last_revision', ('///branch/', ''))],
 
174
            client._calls)
 
175
        self.assertEqual(None, result)
 
176
 
 
177
    def test_set_nonempty(self):
 
178
        # set_revision_history([rev-id1, ..., rev-idN]) is translated to calling
 
179
        # Branch.set_last_revision(path, rev-idN) on the wire.
 
180
        client = FakeClient([(('ok',), )])
 
181
        transport = MemoryTransport()
 
182
        transport.mkdir('branch')
 
183
        transport = transport.clone('branch')
 
184
 
 
185
        bzrdir = RemoteBzrDir(transport, _client=False)
 
186
        branch = RemoteBranch(bzrdir, None, _client=client)
 
187
 
 
188
        result = branch.set_revision_history(['rev-id1', 'rev-id2'])
 
189
        self.assertEqual(
 
190
            [('call', 'Branch.set_last_revision', ('///branch/', 'rev-id2'))],
 
191
            client._calls)
 
192
        self.assertEqual(None, result)
 
193
 
 
194
    def test_no_such_revision(self):
 
195
        # A response of 'NoSuchRevision' is translated into an exception.
 
196
        client = FakeClient([(('NoSuchRevision', 'rev-id'), )])
 
197
        transport = MemoryTransport()
 
198
        transport.mkdir('branch')
 
199
        transport = transport.clone('branch')
 
200
 
 
201
        bzrdir = RemoteBzrDir(transport, _client=False)
 
202
        branch = RemoteBranch(bzrdir, None, _client=client)
 
203
 
 
204
        self.assertRaises(
 
205
            NoSuchRevision, branch.set_revision_history, ['rev-id'])
 
206
 
 
207
 
158
208
class TestBranchControlGetBranchConf(tests.TestCase):
159
209
    """Test branch.control_files api munging...
160
210
 
161
 
    we special case RemoteBranch.control_files.get('branch.conf') to 
 
211
    we special case RemoteBranch.control_files.get('branch.conf') to
162
212
    call a specific API so that RemoteBranch's can intercept configuration
163
213
    file reading, allowing them to signal to the client about things like
164
214
    'email is configured for commits'.
194
244
        return repo, client
195
245
 
196
246
 
197
 
class TestRepositoryGatherStats(tests.TestCase):
198
 
 
199
 
    def setup_fake_client_and_repository(self, responses, transport_path):
200
 
        """Create the fake client and repository for testing with."""
201
 
        client = FakeClient(responses)
202
 
        transport = MemoryTransport()
203
 
        transport.mkdir(transport_path)
204
 
        transport = transport.clone(transport_path)
205
 
        # we do not want bzrdir to make any remote calls
206
 
        bzrdir = RemoteBzrDir(transport, _client=False)
207
 
        repo = RemoteRepository(bzrdir, None, _client=client)
208
 
        return repo, client
 
247
class TestRepositoryGatherStats(TestRemoteRepository):
209
248
 
210
249
    def test_revid_none(self):
211
250
        # ('ok',), body with revisions and size