~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
smart protocol as appropriate, so that locking operations on RemoteRepositories
work correctly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
from cStringIO import StringIO
25
25
 
26
 
from bzrlib import bzrdir, remote, tests
 
26
from bzrlib import (
 
27
    bzrdir,
 
28
    errors,
 
29
    remote,
 
30
    tests,
 
31
    )
27
32
from bzrlib.branch import Branch
28
33
from bzrlib.bzrdir import BzrDir, BzrDirFormat
29
 
from bzrlib.errors import NoSuchRevision
30
34
from bzrlib.remote import (
31
35
    RemoteBranch,
32
36
    RemoteBzrDir,
202
206
        branch = RemoteBranch(bzrdir, None, _client=client)
203
207
 
204
208
        self.assertRaises(
205
 
            NoSuchRevision, branch.set_revision_history, ['rev-id'])
 
209
            errors.NoSuchRevision, branch.set_revision_history, ['rev-id'])
206
210
 
207
211
 
208
212
class TestBranchControlGetBranchConf(tests.TestCase):
359
363
        repo, client = self.setup_fake_client_and_repository(
360
364
            responses, transport_path)
361
365
        # also check that the right revision is reported in the error
362
 
        self.assertRaises(NoSuchRevision,
 
366
        self.assertRaises(errors.NoSuchRevision,
363
367
            repo.get_revision_graph, revid)
364
368
        self.assertEqual(
365
369
            [('call2', 'Repository.get_revision_graph', ('///sinhala/', revid))],
391
395
            [('call', 'Repository.is_shared', ('///qwack/',))],
392
396
            client._calls)
393
397
        self.assertEqual(False, result)
 
398
 
 
399
 
 
400
class TestRepositoryLockWrite(TestRemoteRepository):
 
401
 
 
402
    def test_lock_write(self):
 
403
        responses = [(('ok', 'a token'), '')]
 
404
        transport_path = 'quack'
 
405
        repo, client = self.setup_fake_client_and_repository(
 
406
            responses, transport_path)
 
407
        result = repo.lock_write()
 
408
        self.assertEqual(
 
409
            [('call', 'Repository.lock_write', ('///quack/',))],
 
410
            client._calls)
 
411
        self.assertEqual('a token', result)
 
412
 
 
413
    def test_lock_write_already_locked(self):
 
414
        responses = [(('LockContention', ), '')]
 
415
        transport_path = 'quack'
 
416
        repo, client = self.setup_fake_client_and_repository(
 
417
            responses, transport_path)
 
418
        self.assertRaises(errors.LockContention, repo.lock_write)
 
419
        self.assertEqual(
 
420
            [('call', 'Repository.lock_write', ('///quack/',))],
 
421
            client._calls)
 
422
 
 
423
 
 
424
class TestRepositoryUnlock(TestRemoteRepository):
 
425
 
 
426
    def test_unlock(self):
 
427
        responses = [(('ok', 'a token'), ''),
 
428
                     (('ok',), '')]
 
429
        transport_path = 'quack'
 
430
        repo, client = self.setup_fake_client_and_repository(
 
431
            responses, transport_path)
 
432
        repo.lock_write()
 
433
        repo.unlock()
 
434
        self.assertEqual(
 
435
            [('call', 'Repository.lock_write', ('///quack/',)),
 
436
             ('call', 'Repository.unlock', ('///quack/', 'a token'))],
 
437
            client._calls)
 
438
 
 
439
    def test_unlock_wrong_token(self):
 
440
        # If somehow the token is wrong, unlock will raise TokenMismatch.
 
441
        responses = [(('ok', 'a token'), ''),
 
442
                     (('TokenMismatch',), '')]
 
443
        transport_path = 'quack'
 
444
        repo, client = self.setup_fake_client_and_repository(
 
445
            responses, transport_path)
 
446
        repo.lock_write()
 
447
        self.assertRaises(errors.TokenMismatch, repo.unlock)
 
448
 
 
449