1
# Copyright (C) 2006 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Tests for the smart wire/domain protococl."""
19
from bzrlib import bzrdir, errors, smart, tests
20
from bzrlib.smart.request import SmartServerResponse
21
import bzrlib.smart.bzrdir
22
import bzrlib.smart.branch
23
import bzrlib.smart.repository
26
class TestCaseWithSmartMedium(tests.TestCaseWithTransport):
29
super(TestCaseWithSmartMedium, self).setUp()
30
# We're allowed to set the transport class here, so that we don't use
31
# the default or a parameterized class, but rather use the
32
# TestCaseWithTransport infrastructure to set up a smart server and
34
self.transport_server = smart.server.SmartTCPServer_for_testing
36
def get_smart_medium(self):
37
"""Get a smart medium to use in tests."""
38
return self.get_transport().get_smart_medium()
41
class TestSmartServerResponse(tests.TestCase):
44
self.assertEqual(SmartServerResponse(('ok', )),
45
SmartServerResponse(('ok', )))
46
self.assertEqual(SmartServerResponse(('ok', ), 'body'),
47
SmartServerResponse(('ok', ), 'body'))
48
self.assertNotEqual(SmartServerResponse(('ok', )),
49
SmartServerResponse(('notok', )))
50
self.assertNotEqual(SmartServerResponse(('ok', ), 'body'),
51
SmartServerResponse(('ok', )))
52
self.assertNotEqual(None,
53
SmartServerResponse(('ok', )))
56
class TestSmartServerRequestFindRepository(tests.TestCaseWithTransport):
58
def test_no_repository(self):
59
"""When there is no repository to be found, ('norepository', ) is returned."""
60
backing = self.get_transport()
61
request = smart.bzrdir.SmartServerRequestFindRepository(backing)
63
self.assertEqual(SmartServerResponse(('norepository', )),
64
request.execute(backing.local_abspath('')))
66
def test_nonshared_repository(self):
67
# nonshared repositorys only allow 'find' to return a handle when the
68
# path the repository is being searched on is the same as that that
69
# the repository is at.
70
backing = self.get_transport()
71
request = smart.bzrdir.SmartServerRequestFindRepository(backing)
72
self.make_repository('.')
73
self.assertEqual(SmartServerResponse(('ok', '')),
74
request.execute(backing.local_abspath('')))
75
self.make_bzrdir('subdir')
76
self.assertEqual(SmartServerResponse(('norepository', )),
77
request.execute(backing.local_abspath('subdir')))
79
def test_shared_repository(self):
80
"""When there is a shared repository, we get 'ok', 'relpath-to-repo'."""
81
backing = self.get_transport()
82
request = smart.bzrdir.SmartServerRequestFindRepository(backing)
83
self.make_repository('.', shared=True)
84
self.assertEqual(SmartServerResponse(('ok', '')),
85
request.execute(backing.local_abspath('')))
86
self.make_bzrdir('subdir')
87
self.assertEqual(SmartServerResponse(('ok', '..')),
88
request.execute(backing.local_abspath('subdir')))
89
self.make_bzrdir('subdir/deeper')
90
self.assertEqual(SmartServerResponse(('ok', '../..')),
91
request.execute(backing.local_abspath('subdir/deeper')))
94
class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithTransport):
96
def test_empty_dir(self):
97
"""Initializing an empty dir should succeed and do it."""
98
backing = self.get_transport()
99
request = smart.bzrdir.SmartServerRequestInitializeBzrDir(backing)
100
self.assertEqual(SmartServerResponse(('ok', )),
101
request.execute(backing.local_abspath('.')))
102
made_dir = bzrdir.BzrDir.open_from_transport(backing)
103
# no branch, tree or repository is expected with the current
105
self.assertRaises(errors.NoWorkingTree, made_dir.open_workingtree)
106
self.assertRaises(errors.NotBranchError, made_dir.open_branch)
107
self.assertRaises(errors.NoRepositoryPresent, made_dir.open_repository)
109
def test_missing_dir(self):
110
"""Initializing a missing directory should fail like the bzrdir api."""
111
backing = self.get_transport()
112
request = smart.bzrdir.SmartServerRequestInitializeBzrDir(backing)
113
self.assertRaises(errors.NoSuchFile,
114
request.execute, backing.local_abspath('subdir'))
116
def test_initialized_dir(self):
117
"""Initializing an extant bzrdir should fail like the bzrdir api."""
118
backing = self.get_transport()
119
request = smart.bzrdir.SmartServerRequestInitializeBzrDir(backing)
120
self.make_bzrdir('subdir')
121
self.assertRaises(errors.FileExists,
122
request.execute, backing.local_abspath('subdir'))
125
class TestSmartServerRequestOpenBranch(tests.TestCaseWithTransport):
127
def test_no_branch(self):
128
"""When there is no branch, ('nobranch', ) is returned."""
129
backing = self.get_transport()
130
request = smart.bzrdir.SmartServerRequestOpenBranch(backing)
131
self.make_bzrdir('.')
132
self.assertEqual(SmartServerResponse(('nobranch', )),
133
request.execute(backing.local_abspath('')))
135
def test_branch(self):
136
"""When there is a branch, 'ok' is returned."""
137
backing = self.get_transport()
138
request = smart.bzrdir.SmartServerRequestOpenBranch(backing)
139
self.make_branch('.')
140
self.assertEqual(SmartServerResponse(('ok', '')),
141
request.execute(backing.local_abspath('')))
143
def test_branch_reference(self):
144
"""When there is a branch reference, the reference URL is returned."""
145
backing = self.get_transport()
146
request = smart.bzrdir.SmartServerRequestOpenBranch(backing)
147
branch = self.make_branch('branch')
148
checkout = branch.create_checkout('reference',lightweight=True)
149
# TODO: once we have an API to probe for references of any sort, we
151
reference_url = backing.abspath('branch') + '/'
152
self.assertFileEqual(reference_url, 'reference/.bzr/branch/location')
153
self.assertEqual(SmartServerResponse(('ok', reference_url)),
154
request.execute(backing.local_abspath('reference')))
157
class TestSmartServerRequestRevisionHistory(tests.TestCaseWithTransport):
159
def test_empty(self):
160
"""For an empty branch, the body is empty."""
161
backing = self.get_transport()
162
request = smart.branch.SmartServerRequestRevisionHistory(backing)
163
self.make_branch('.')
164
self.assertEqual(SmartServerResponse(('ok', ), ''),
165
request.execute(backing.local_abspath('')))
167
def test_not_empty(self):
168
"""For a non-empty branch, the body is empty."""
169
backing = self.get_transport()
170
request = smart.branch.SmartServerRequestRevisionHistory(backing)
171
tree = self.make_branch_and_memory_tree('.')
174
r1 = tree.commit('1st commit')
175
r2 = tree.commit('2nd commit', rev_id=u'\xc8')
178
SmartServerResponse(('ok', ), ('\x00'.join([r1, r2]))),
179
request.execute(backing.local_abspath('')))
182
class TestSmartServerBranchRequest(tests.TestCaseWithTransport):
184
def test_no_branch(self):
185
"""When there is a bzrdir and no branch, NotBranchError is raised."""
186
backing = self.get_transport()
187
request = smart.branch.SmartServerBranchRequest(backing)
188
self.make_bzrdir('.')
189
self.assertRaises(errors.NotBranchError,
190
request.execute, backing.local_abspath(''))
192
def test_branch_reference(self):
193
"""When there is a branch reference, NotBranchError is raised."""
194
backing = self.get_transport()
195
request = smart.branch.SmartServerBranchRequest(backing)
196
branch = self.make_branch('branch')
197
checkout = branch.create_checkout('reference',lightweight=True)
198
self.assertRaises(errors.NotBranchError,
199
request.execute, backing.local_abspath('checkout'))
202
class TestSmartServerBranchRequestLastRevisionInfo(tests.TestCaseWithTransport):
204
def test_empty(self):
205
"""For an empty branch, the result is ('ok', '0', '')."""
206
backing = self.get_transport()
207
request = smart.branch.SmartServerBranchRequestLastRevisionInfo(backing)
208
self.make_branch('.')
209
self.assertEqual(SmartServerResponse(('ok', '0', '')),
210
request.execute(backing.local_abspath('')))
212
def test_not_empty(self):
213
"""For a non-empty branch, the result is ('ok', 'revno', 'revid')."""
214
backing = self.get_transport()
215
request = smart.branch.SmartServerBranchRequestLastRevisionInfo(backing)
216
tree = self.make_branch_and_memory_tree('.')
220
rev_id_utf8 = rev_id.encode('utf-8')
221
r1 = tree.commit('1st commit')
222
r2 = tree.commit('2nd commit', rev_id=rev_id)
225
SmartServerResponse(('ok', '2', rev_id_utf8)),
226
request.execute(backing.local_abspath('')))
229
class TestSmartServerBranchRequestGetConfigFile(tests.TestCaseWithTransport):
231
def test_default(self):
232
"""With no file, we get empty content."""
233
backing = self.get_transport()
234
request = smart.branch.SmartServerBranchGetConfigFile(backing)
235
branch = self.make_branch('.')
236
# there should be no file by default
238
self.assertEqual(SmartServerResponse(('ok', ), content),
239
request.execute(backing.local_abspath('')))
241
def test_with_content(self):
242
# SmartServerBranchGetConfigFile should return the content from
243
# branch.control_files.get('branch.conf') for now - in the future it may
244
# perform more complex processing.
245
backing = self.get_transport()
246
request = smart.branch.SmartServerBranchGetConfigFile(backing)
247
branch = self.make_branch('.')
248
branch.control_files.put_utf8('branch.conf', 'foo bar baz')
249
self.assertEqual(SmartServerResponse(('ok', ), 'foo bar baz'),
250
request.execute(backing.local_abspath('')))
253
class TestSmartServerBranchRequestSetLastRevision(tests.TestCaseWithTransport):
255
def test_empty(self):
256
backing = self.get_transport()
257
request = smart.branch.SmartServerBranchRequestSetLastRevision(backing)
258
b = self.make_branch('.')
259
branch_token, repo_token = b.lock_write()
261
self.assertEqual(SmartServerResponse(('ok',)),
263
backing.local_abspath(''), branch_token, repo_token, ''))
267
def test_not_present_revision_id(self):
268
backing = self.get_transport()
269
request = smart.branch.SmartServerBranchRequestSetLastRevision(backing)
270
b = self.make_branch('.')
271
branch_token, repo_token = b.lock_write()
273
revision_id = 'non-existent revision'
275
SmartServerResponse(('NoSuchRevision', revision_id)),
277
backing.local_abspath(''), branch_token, repo_token,
282
def test_revision_id_present(self):
283
backing = self.get_transport()
284
request = smart.branch.SmartServerBranchRequestSetLastRevision(backing)
285
tree = self.make_branch_and_memory_tree('.')
289
rev_id_utf8 = rev_id.encode('utf-8')
290
r1 = tree.commit('1st commit', rev_id=rev_id)
291
r2 = tree.commit('2nd commit')
293
branch_token, repo_token = tree.branch.lock_write()
296
SmartServerResponse(('ok',)),
298
backing.local_abspath(''), branch_token, repo_token,
300
self.assertEqual([rev_id_utf8], tree.branch.revision_history())
304
def test_revision_id_present2(self):
305
backing = self.get_transport()
306
request = smart.branch.SmartServerBranchRequestSetLastRevision(backing)
307
tree = self.make_branch_and_memory_tree('.')
311
rev_id_utf8 = rev_id.encode('utf-8')
312
r1 = tree.commit('1st commit', rev_id=rev_id)
313
r2 = tree.commit('2nd commit')
315
tree.branch.set_revision_history([])
316
branch_token, repo_token = tree.branch.lock_write()
319
SmartServerResponse(('ok',)),
321
backing.local_abspath(''), branch_token, repo_token,
323
self.assertEqual([rev_id_utf8], tree.branch.revision_history())
328
class TestSmartServerBranchRequestLockWrite(tests.TestCaseWithTransport):
331
tests.TestCaseWithTransport.setUp(self)
332
self.reduceLockdirTimeout()
334
def test_lock_write_on_unlocked_branch(self):
335
backing = self.get_transport()
336
request = smart.branch.SmartServerBranchRequestLockWrite(backing)
337
branch = self.make_branch('.')
338
repository = branch.repository
339
response = request.execute(backing.local_abspath(''))
340
branch_nonce = branch.control_files._lock.peek().get('nonce')
341
repository_nonce = repository.control_files._lock.peek().get('nonce')
343
SmartServerResponse(('ok', branch_nonce, repository_nonce)),
345
# The branch (and associated repository) is now locked. Verify that
346
# with a new branch object.
347
new_branch = repository.bzrdir.open_branch()
348
self.assertRaises(errors.LockContention, new_branch.lock_write)
350
def test_lock_write_on_locked_branch(self):
351
backing = self.get_transport()
352
request = smart.branch.SmartServerBranchRequestLockWrite(backing)
353
branch = self.make_branch('.')
355
branch.leave_lock_in_place()
357
response = request.execute(backing.local_abspath(''))
359
SmartServerResponse(('LockContention',)), response)
361
def test_lock_write_with_tokens_on_locked_branch(self):
362
backing = self.get_transport()
363
request = smart.branch.SmartServerBranchRequestLockWrite(backing)
364
branch = self.make_branch('.')
365
branch_token, repo_token = branch.lock_write()
366
branch.leave_lock_in_place()
367
branch.repository.leave_lock_in_place()
369
response = request.execute(backing.local_abspath(''),
370
branch_token, repo_token)
372
SmartServerResponse(('ok', branch_token, repo_token)), response)
374
def test_lock_write_with_mismatched_tokens_on_locked_branch(self):
375
backing = self.get_transport()
376
request = smart.branch.SmartServerBranchRequestLockWrite(backing)
377
branch = self.make_branch('.')
378
branch_token, repo_token = branch.lock_write()
379
branch.leave_lock_in_place()
380
branch.repository.leave_lock_in_place()
382
response = request.execute(backing.local_abspath(''),
383
branch_token+'xxx', repo_token)
385
SmartServerResponse(('TokenMismatch',)), response)
387
def test_lock_write_on_locked_repo(self):
388
backing = self.get_transport()
389
request = smart.branch.SmartServerBranchRequestLockWrite(backing)
390
branch = self.make_branch('.')
391
branch.repository.lock_write()
392
branch.repository.leave_lock_in_place()
393
branch.repository.unlock()
394
response = request.execute(backing.local_abspath(''))
396
SmartServerResponse(('LockContention',)), response)
399
class TestSmartServerBranchRequestUnlock(tests.TestCaseWithTransport):
402
tests.TestCaseWithTransport.setUp(self)
403
self.reduceLockdirTimeout()
405
def test_unlock_on_locked_branch_and_repo(self):
406
backing = self.get_transport()
407
request = smart.branch.SmartServerBranchRequestUnlock(backing)
408
branch = self.make_branch('.')
410
branch_token, repo_token = branch.lock_write()
411
# Unlock the branch (and repo) object, leaving the physical locks
413
branch.leave_lock_in_place()
414
branch.repository.leave_lock_in_place()
416
response = request.execute(backing.local_abspath(''),
417
branch_token, repo_token)
419
SmartServerResponse(('ok',)), response)
420
# The branch is now unlocked. Verify that with a new branch
422
new_branch = branch.bzrdir.open_branch()
423
new_branch.lock_write()
426
def test_unlock_on_unlocked_branch_unlocked_repo(self):
427
backing = self.get_transport()
428
request = smart.branch.SmartServerBranchRequestUnlock(backing)
429
branch = self.make_branch('.')
430
response = request.execute(
431
backing.local_abspath(''), 'branch token', 'repo token')
433
SmartServerResponse(('TokenMismatch',)), response)
435
def test_unlock_on_unlocked_branch_locked_repo(self):
436
backing = self.get_transport()
437
request = smart.branch.SmartServerBranchRequestUnlock(backing)
438
branch = self.make_branch('.')
439
# Lock the repository.
440
repo_token = branch.repository.lock_write()
441
branch.repository.leave_lock_in_place()
442
branch.repository.unlock()
443
# Issue branch lock_write request on the unlocked branch (with locked
445
response = request.execute(
446
backing.local_abspath(''), 'branch token', repo_token)
448
SmartServerResponse(('TokenMismatch',)), response)
451
class TestSmartServerRepositoryRequest(tests.TestCaseWithTransport):
453
def test_no_repository(self):
454
"""Raise NoRepositoryPresent when there is a bzrdir and no repo."""
455
# we test this using a shared repository above the named path,
456
# thus checking the right search logic is used - that is, that
457
# its the exact path being looked at and the server is not
459
backing = self.get_transport()
460
request = smart.repository.SmartServerRepositoryRequest(backing)
461
self.make_repository('.', shared=True)
462
self.make_bzrdir('subdir')
463
self.assertRaises(errors.NoRepositoryPresent,
464
request.execute, backing.local_abspath('subdir'))
467
class TestSmartServerRepositoryGetRevisionGraph(tests.TestCaseWithTransport):
469
def test_none_argument(self):
470
backing = self.get_transport()
471
request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing)
472
tree = self.make_branch_and_memory_tree('.')
475
r1 = tree.commit('1st commit')
476
r2 = tree.commit('2nd commit', rev_id=u'\xc8')
479
# the lines of revision_id->revision_parent_list has no guaranteed
480
# order coming out of a dict, so sort both our test and response
481
lines = sorted([' '.join([r2, r1]), r1])
482
response = request.execute(backing.local_abspath(''), '')
483
response.body = '\n'.join(sorted(response.body.split('\n')))
486
SmartServerResponse(('ok', ), '\n'.join(lines)), response)
488
def test_specific_revision_argument(self):
489
backing = self.get_transport()
490
request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing)
491
tree = self.make_branch_and_memory_tree('.')
494
r1 = tree.commit('1st commit', rev_id=u'\xc9')
495
r2 = tree.commit('2nd commit', rev_id=u'\xc8')
498
self.assertEqual(SmartServerResponse(('ok', ),
499
u'\xc9'.encode('utf8')),
500
request.execute(backing.local_abspath(''), u'\xc9'.encode('utf8')))
502
def test_no_such_revision(self):
503
backing = self.get_transport()
504
request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing)
505
tree = self.make_branch_and_memory_tree('.')
508
r1 = tree.commit('1st commit')
511
# Note that it still returns body (of zero bytes).
513
SmartServerResponse(('nosuchrevision', 'missingrevision', ), ''),
514
request.execute(backing.local_abspath(''), 'missingrevision'))
517
class TestSmartServerRequestHasRevision(tests.TestCaseWithTransport):
519
def test_missing_revision(self):
520
"""For a missing revision, ('no', ) is returned."""
521
backing = self.get_transport()
522
request = smart.repository.SmartServerRequestHasRevision(backing)
523
self.make_repository('.')
524
self.assertEqual(SmartServerResponse(('no', )),
525
request.execute(backing.local_abspath(''), 'revid'))
527
def test_present_revision(self):
528
"""For a present revision, ('ok', ) is returned."""
529
backing = self.get_transport()
530
request = smart.repository.SmartServerRequestHasRevision(backing)
531
tree = self.make_branch_and_memory_tree('.')
534
r1 = tree.commit('a commit', rev_id=u'\xc8abc')
536
self.assertTrue(tree.branch.repository.has_revision(u'\xc8abc'))
537
self.assertEqual(SmartServerResponse(('ok', )),
538
request.execute(backing.local_abspath(''),
539
u'\xc8abc'.encode('utf8')))
542
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithTransport):
544
def test_empty_revid(self):
545
"""With an empty revid, we get only size an number and revisions"""
546
backing = self.get_transport()
547
request = smart.repository.SmartServerRepositoryGatherStats(backing)
548
repository = self.make_repository('.')
549
stats = repository.gather_stats()
551
expected_body = 'revisions: 0\nsize: %d\n' % size
552
self.assertEqual(SmartServerResponse(('ok', ), expected_body),
553
request.execute(backing.local_abspath(''), '', 'no'))
555
def test_revid_with_committers(self):
556
"""For a revid we get more infos."""
557
backing = self.get_transport()
559
request = smart.repository.SmartServerRepositoryGatherStats(backing)
560
tree = self.make_branch_and_memory_tree('.')
563
# Let's build a predictable result
564
tree.commit('a commit', timestamp=123456.2, timezone=3600)
565
tree.commit('a commit', timestamp=654321.4, timezone=0, rev_id=rev_id)
568
stats = tree.branch.repository.gather_stats()
570
expected_body = ('firstrev: 123456.200 3600\n'
571
'latestrev: 654321.400 0\n'
574
self.assertEqual(SmartServerResponse(('ok', ), expected_body),
575
request.execute(backing.local_abspath(''),
576
rev_id.encode('utf8'), 'no'))
578
def test_not_empty_repository_with_committers(self):
579
"""For a revid and requesting committers we get the whole thing."""
580
backing = self.get_transport()
582
request = smart.repository.SmartServerRepositoryGatherStats(backing)
583
tree = self.make_branch_and_memory_tree('.')
586
# Let's build a predictable result
587
tree.commit('a commit', timestamp=123456.2, timezone=3600,
589
tree.commit('a commit', timestamp=654321.4, timezone=0,
590
committer='bar', rev_id=rev_id)
592
stats = tree.branch.repository.gather_stats()
595
expected_body = ('committers: 2\n'
596
'firstrev: 123456.200 3600\n'
597
'latestrev: 654321.400 0\n'
600
self.assertEqual(SmartServerResponse(('ok', ), expected_body),
601
request.execute(backing.local_abspath(''),
602
rev_id.encode('utf8'), 'yes'))
605
class TestSmartServerRepositoryIsShared(tests.TestCaseWithTransport):
607
def test_is_shared(self):
608
"""For a shared repository, ('yes', ) is returned."""
609
backing = self.get_transport()
610
request = smart.repository.SmartServerRepositoryIsShared(backing)
611
self.make_repository('.', shared=True)
612
self.assertEqual(SmartServerResponse(('yes', )),
613
request.execute(backing.local_abspath(''), ))
615
def test_is_not_shared(self):
616
"""For a shared repository, ('no', ) is returned."""
617
backing = self.get_transport()
618
request = smart.repository.SmartServerRepositoryIsShared(backing)
619
self.make_repository('.', shared=False)
620
self.assertEqual(SmartServerResponse(('no', )),
621
request.execute(backing.local_abspath(''), ))
624
class TestSmartServerRepositoryLockWrite(tests.TestCaseWithTransport):
627
tests.TestCaseWithTransport.setUp(self)
628
self.reduceLockdirTimeout()
630
def test_lock_write_on_unlocked_repo(self):
631
backing = self.get_transport()
632
request = smart.repository.SmartServerRepositoryLockWrite(backing)
633
repository = self.make_repository('.')
634
response = request.execute(backing.local_abspath(''))
635
nonce = repository.control_files._lock.peek().get('nonce')
636
self.assertEqual(SmartServerResponse(('ok', nonce)), response)
637
# The repository is now locked. Verify that with a new repository
639
new_repo = repository.bzrdir.open_repository()
640
self.assertRaises(errors.LockContention, new_repo.lock_write)
642
def test_lock_write_on_locked_repo(self):
643
backing = self.get_transport()
644
request = smart.repository.SmartServerRepositoryLockWrite(backing)
645
repository = self.make_repository('.')
646
repository.lock_write()
647
repository.leave_lock_in_place()
649
response = request.execute(backing.local_abspath(''))
651
SmartServerResponse(('LockContention',)), response)
654
class TestSmartServerRepositoryUnlock(tests.TestCaseWithTransport):
657
tests.TestCaseWithTransport.setUp(self)
658
self.reduceLockdirTimeout()
660
def test_unlock_on_locked_repo(self):
661
backing = self.get_transport()
662
request = smart.repository.SmartServerRepositoryUnlock(backing)
663
repository = self.make_repository('.')
664
token = repository.lock_write()
665
repository.leave_lock_in_place()
667
response = request.execute(backing.local_abspath(''), token)
669
SmartServerResponse(('ok',)), response)
670
# The repository is now unlocked. Verify that with a new repository
672
new_repo = repository.bzrdir.open_repository()
673
new_repo.lock_write()
676
def test_unlock_on_unlocked_repo(self):
677
backing = self.get_transport()
678
request = smart.repository.SmartServerRepositoryUnlock(backing)
679
repository = self.make_repository('.')
680
response = request.execute(backing.local_abspath(''), 'some token')
682
SmartServerResponse(('TokenMismatch',)), response)
685
class TestHandlers(tests.TestCase):
686
"""Tests for the request.request_handlers object."""
688
def test_registered_methods(self):
689
"""Test that known methods are registered to the correct object."""
691
smart.request.request_handlers.get('Branch.get_config_file'),
692
smart.branch.SmartServerBranchGetConfigFile)
694
smart.request.request_handlers.get('Branch.lock_write'),
695
smart.branch.SmartServerBranchRequestLockWrite)
697
smart.request.request_handlers.get('Branch.last_revision_info'),
698
smart.branch.SmartServerBranchRequestLastRevisionInfo)
700
smart.request.request_handlers.get('Branch.revision_history'),
701
smart.branch.SmartServerRequestRevisionHistory)
703
smart.request.request_handlers.get('Branch.set_last_revision'),
704
smart.branch.SmartServerBranchRequestSetLastRevision)
706
smart.request.request_handlers.get('Branch.unlock'),
707
smart.branch.SmartServerBranchRequestUnlock)
709
smart.request.request_handlers.get('BzrDir.find_repository'),
710
smart.bzrdir.SmartServerRequestFindRepository)
712
smart.request.request_handlers.get('BzrDirFormat.initialize'),
713
smart.bzrdir.SmartServerRequestInitializeBzrDir)
715
smart.request.request_handlers.get('BzrDir.open_branch'),
716
smart.bzrdir.SmartServerRequestOpenBranch)
718
smart.request.request_handlers.get('Repository.gather_stats'),
719
smart.repository.SmartServerRepositoryGatherStats)
721
smart.request.request_handlers.get('Repository.get_revision_graph'),
722
smart.repository.SmartServerRepositoryGetRevisionGraph)
724
smart.request.request_handlers.get('Repository.has_revision'),
725
smart.repository.SmartServerRequestHasRevision)
727
smart.request.request_handlers.get('Repository.is_shared'),
728
smart.repository.SmartServerRepositoryIsShared)
730
smart.request.request_handlers.get('Repository.lock_write'),
731
smart.repository.SmartServerRepositoryLockWrite)
733
smart.request.request_handlers.get('Repository.unlock'),
734
smart.repository.SmartServerRepositoryUnlock)