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')
177
self.assertEqual(SmartServerResponse(('ok', ),
178
('\x00'.join([r1, r2])).encode('utf8')),
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('.')
219
r1 = tree.commit('1st commit')
220
r2 = tree.commit('2nd commit', rev_id=u'\xc8')
223
SmartServerResponse(('ok', '2', u'\xc8'.encode('utf8'))),
224
request.execute(backing.local_abspath('')))
227
class TestSmartServerBranchRequestGetConfigFile(tests.TestCaseWithTransport):
229
def test_default(self):
230
"""With no file, we get empty content."""
231
backing = self.get_transport()
232
request = smart.branch.SmartServerBranchGetConfigFile(backing)
233
branch = self.make_branch('.')
234
# there should be no file by default
236
self.assertEqual(SmartServerResponse(('ok', ), content),
237
request.execute(backing.local_abspath('')))
239
def test_with_content(self):
240
# SmartServerBranchGetConfigFile should return the content from
241
# branch.control_files.get('branch.conf') for now - in the future it may
242
# perform more complex processing.
243
backing = self.get_transport()
244
request = smart.branch.SmartServerBranchGetConfigFile(backing)
245
branch = self.make_branch('.')
246
branch.control_files.put_utf8('branch.conf', 'foo bar baz')
247
self.assertEqual(SmartServerResponse(('ok', ), 'foo bar baz'),
248
request.execute(backing.local_abspath('')))
251
class TestSmartServerBranchRequestSetLastRevision(tests.TestCaseWithTransport):
253
def test_empty(self):
254
backing = self.get_transport()
255
request = smart.branch.SmartServerBranchRequestSetLastRevision(backing)
256
b = self.make_branch('.')
257
branch_token, repo_token = b.lock_write()
259
self.assertEqual(SmartServerResponse(('ok',)),
261
backing.local_abspath(''), branch_token, repo_token, ''))
265
def test_not_present_revision_id(self):
266
backing = self.get_transport()
267
request = smart.branch.SmartServerBranchRequestSetLastRevision(backing)
268
b = self.make_branch('.')
269
branch_token, repo_token = b.lock_write()
271
revision_id = 'non-existent revision'
273
SmartServerResponse(('NoSuchRevision', revision_id)),
275
backing.local_abspath(''), branch_token, repo_token,
280
def test_revision_id_present(self):
281
backing = self.get_transport()
282
request = smart.branch.SmartServerBranchRequestSetLastRevision(backing)
283
tree = self.make_branch_and_memory_tree('.')
286
r1 = tree.commit('1st commit', rev_id=u'\xc8')
287
r2 = tree.commit('2nd commit')
289
branch_token, repo_token = tree.branch.lock_write()
292
SmartServerResponse(('ok',)),
294
backing.local_abspath(''), branch_token, repo_token,
295
u'\xc8'.encode('utf8')))
296
self.assertEqual([u'\xc8'], tree.branch.revision_history())
300
def test_revision_id_present2(self):
301
backing = self.get_transport()
302
request = smart.branch.SmartServerBranchRequestSetLastRevision(backing)
303
tree = self.make_branch_and_memory_tree('.')
306
r1 = tree.commit('1st commit', rev_id=u'\xc8')
307
r2 = tree.commit('2nd commit')
309
tree.branch.set_revision_history([])
310
branch_token, repo_token = tree.branch.lock_write()
313
SmartServerResponse(('ok',)),
315
backing.local_abspath(''), branch_token, repo_token,
316
u'\xc8'.encode('utf8')))
317
self.assertEqual([u'\xc8'], tree.branch.revision_history())
322
class TestSmartServerBranchRequestLockWrite(tests.TestCaseWithTransport):
325
tests.TestCaseWithTransport.setUp(self)
326
self.reduceLockdirTimeout()
328
def test_lock_write_on_unlocked_branch(self):
329
backing = self.get_transport()
330
request = smart.branch.SmartServerBranchRequestLockWrite(backing)
331
branch = self.make_branch('.')
332
repository = branch.repository
333
response = request.execute(backing.local_abspath(''))
334
branch_nonce = branch.control_files._lock.peek().get('nonce')
335
repository_nonce = repository.control_files._lock.peek().get('nonce')
337
SmartServerResponse(('ok', branch_nonce, repository_nonce)),
339
# The branch (and associated repository) is now locked. Verify that
340
# with a new branch object.
341
new_branch = repository.bzrdir.open_branch()
342
self.assertRaises(errors.LockContention, new_branch.lock_write)
344
def test_lock_write_on_locked_branch(self):
345
backing = self.get_transport()
346
request = smart.branch.SmartServerBranchRequestLockWrite(backing)
347
branch = self.make_branch('.')
349
branch.leave_lock_in_place()
351
response = request.execute(backing.local_abspath(''))
353
SmartServerResponse(('LockContention',)), response)
355
def test_lock_write_with_tokens_on_locked_branch(self):
356
backing = self.get_transport()
357
request = smart.branch.SmartServerBranchRequestLockWrite(backing)
358
branch = self.make_branch('.')
359
branch_token, repo_token = branch.lock_write()
360
branch.leave_lock_in_place()
361
branch.repository.leave_lock_in_place()
363
response = request.execute(backing.local_abspath(''),
364
branch_token, repo_token)
366
SmartServerResponse(('ok', branch_token, repo_token)), response)
368
def test_lock_write_with_mismatched_tokens_on_locked_branch(self):
369
backing = self.get_transport()
370
request = smart.branch.SmartServerBranchRequestLockWrite(backing)
371
branch = self.make_branch('.')
372
branch_token, repo_token = branch.lock_write()
373
branch.leave_lock_in_place()
374
branch.repository.leave_lock_in_place()
376
response = request.execute(backing.local_abspath(''),
377
branch_token+'xxx', repo_token)
379
SmartServerResponse(('TokenMismatch',)), response)
381
def test_lock_write_on_locked_repo(self):
382
backing = self.get_transport()
383
request = smart.branch.SmartServerBranchRequestLockWrite(backing)
384
branch = self.make_branch('.')
385
branch.repository.lock_write()
386
branch.repository.leave_lock_in_place()
387
branch.repository.unlock()
388
response = request.execute(backing.local_abspath(''))
390
SmartServerResponse(('LockContention',)), response)
393
class TestSmartServerBranchRequestUnlock(tests.TestCaseWithTransport):
396
tests.TestCaseWithTransport.setUp(self)
397
self.reduceLockdirTimeout()
399
def test_unlock_on_locked_branch_and_repo(self):
400
backing = self.get_transport()
401
request = smart.branch.SmartServerBranchRequestUnlock(backing)
402
branch = self.make_branch('.')
404
branch_token, repo_token = branch.lock_write()
405
# Unlock the branch (and repo) object, leaving the physical locks
407
branch.leave_lock_in_place()
408
branch.repository.leave_lock_in_place()
410
response = request.execute(backing.local_abspath(''),
411
branch_token, repo_token)
413
SmartServerResponse(('ok',)), response)
414
# The branch is now unlocked. Verify that with a new branch
416
new_branch = branch.bzrdir.open_branch()
417
new_branch.lock_write()
420
def test_unlock_on_unlocked_branch_unlocked_repo(self):
421
backing = self.get_transport()
422
request = smart.branch.SmartServerBranchRequestUnlock(backing)
423
branch = self.make_branch('.')
424
response = request.execute(
425
backing.local_abspath(''), 'branch token', 'repo token')
427
SmartServerResponse(('TokenMismatch',)), response)
429
def test_unlock_on_unlocked_branch_locked_repo(self):
430
backing = self.get_transport()
431
request = smart.branch.SmartServerBranchRequestUnlock(backing)
432
branch = self.make_branch('.')
433
# Lock the repository.
434
repo_token = branch.repository.lock_write()
435
branch.repository.leave_lock_in_place()
436
branch.repository.unlock()
437
# Issue branch lock_write request on the unlocked branch (with locked
439
response = request.execute(
440
backing.local_abspath(''), 'branch token', repo_token)
442
SmartServerResponse(('TokenMismatch',)), response)
445
class TestSmartServerRepositoryRequest(tests.TestCaseWithTransport):
447
def test_no_repository(self):
448
"""Raise NoRepositoryPresent when there is a bzrdir and no repo."""
449
# we test this using a shared repository above the named path,
450
# thus checking the right search logic is used - that is, that
451
# its the exact path being looked at and the server is not
453
backing = self.get_transport()
454
request = smart.repository.SmartServerRepositoryRequest(backing)
455
self.make_repository('.', shared=True)
456
self.make_bzrdir('subdir')
457
self.assertRaises(errors.NoRepositoryPresent,
458
request.execute, backing.local_abspath('subdir'))
461
class TestSmartServerRepositoryGetRevisionGraph(tests.TestCaseWithTransport):
463
def test_none_argument(self):
464
backing = self.get_transport()
465
request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing)
466
tree = self.make_branch_and_memory_tree('.')
469
r1 = tree.commit('1st commit')
470
r2 = tree.commit('2nd commit', rev_id=u'\xc8')
473
# the lines of revision_id->revision_parent_list has no guaranteed
474
# order coming out of a dict, so sort both our test and response
475
lines = sorted([' '.join([r2, r1]), r1])
476
response = request.execute(backing.local_abspath(''), '')
477
response.body = '\n'.join(sorted(response.body.split('\n')))
479
self.assertEqual(SmartServerResponse(('ok', ),
480
'\n'.join(lines).encode('utf8')),
483
def test_specific_revision_argument(self):
484
backing = self.get_transport()
485
request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing)
486
tree = self.make_branch_and_memory_tree('.')
489
r1 = tree.commit('1st commit', rev_id=u'\xc9')
490
r2 = tree.commit('2nd commit', rev_id=u'\xc8')
493
self.assertEqual(SmartServerResponse(('ok', ),
494
u'\xc9'.encode('utf8')),
495
request.execute(backing.local_abspath(''), u'\xc9'.encode('utf8')))
497
def test_no_such_revision(self):
498
backing = self.get_transport()
499
request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing)
500
tree = self.make_branch_and_memory_tree('.')
503
r1 = tree.commit('1st commit')
506
# Note that it still returns body (of zero bytes).
508
SmartServerResponse(('nosuchrevision', 'missingrevision', ), ''),
509
request.execute(backing.local_abspath(''), 'missingrevision'))
512
class TestSmartServerRequestHasRevision(tests.TestCaseWithTransport):
514
def test_missing_revision(self):
515
"""For a missing revision, ('no', ) is returned."""
516
backing = self.get_transport()
517
request = smart.repository.SmartServerRequestHasRevision(backing)
518
self.make_repository('.')
519
self.assertEqual(SmartServerResponse(('no', )),
520
request.execute(backing.local_abspath(''), 'revid'))
522
def test_present_revision(self):
523
"""For a present revision, ('ok', ) is returned."""
524
backing = self.get_transport()
525
request = smart.repository.SmartServerRequestHasRevision(backing)
526
tree = self.make_branch_and_memory_tree('.')
529
r1 = tree.commit('a commit', rev_id=u'\xc8abc')
531
self.assertTrue(tree.branch.repository.has_revision(u'\xc8abc'))
532
self.assertEqual(SmartServerResponse(('ok', )),
533
request.execute(backing.local_abspath(''),
534
u'\xc8abc'.encode('utf8')))
537
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithTransport):
539
def test_empty_revid(self):
540
"""With an empty revid, we get only size an number and revisions"""
541
backing = self.get_transport()
542
request = smart.repository.SmartServerRepositoryGatherStats(backing)
543
repository = self.make_repository('.')
544
stats = repository.gather_stats()
546
expected_body = 'revisions: 0\nsize: %d\n' % size
547
self.assertEqual(SmartServerResponse(('ok', ), expected_body),
548
request.execute(backing.local_abspath(''), '', 'no'))
550
def test_revid_with_committers(self):
551
"""For a revid we get more infos."""
552
backing = self.get_transport()
554
request = smart.repository.SmartServerRepositoryGatherStats(backing)
555
tree = self.make_branch_and_memory_tree('.')
558
# Let's build a predictable result
559
tree.commit('a commit', timestamp=123456.2, timezone=3600)
560
tree.commit('a commit', timestamp=654321.4, timezone=0, rev_id=rev_id)
563
stats = tree.branch.repository.gather_stats()
565
expected_body = ('firstrev: 123456.200 3600\n'
566
'latestrev: 654321.400 0\n'
569
self.assertEqual(SmartServerResponse(('ok', ), expected_body),
570
request.execute(backing.local_abspath(''),
571
rev_id.encode('utf8'), 'no'))
573
def test_not_empty_repository_with_committers(self):
574
"""For a revid and requesting committers we get the whole thing."""
575
backing = self.get_transport()
577
request = smart.repository.SmartServerRepositoryGatherStats(backing)
578
tree = self.make_branch_and_memory_tree('.')
581
# Let's build a predictable result
582
tree.commit('a commit', timestamp=123456.2, timezone=3600,
584
tree.commit('a commit', timestamp=654321.4, timezone=0,
585
committer='bar', rev_id=rev_id)
587
stats = tree.branch.repository.gather_stats()
590
expected_body = ('committers: 2\n'
591
'firstrev: 123456.200 3600\n'
592
'latestrev: 654321.400 0\n'
595
self.assertEqual(SmartServerResponse(('ok', ), expected_body),
596
request.execute(backing.local_abspath(''),
597
rev_id.encode('utf8'), 'yes'))
600
class TestSmartServerRepositoryIsShared(tests.TestCaseWithTransport):
602
def test_is_shared(self):
603
"""For a shared repository, ('yes', ) is returned."""
604
backing = self.get_transport()
605
request = smart.repository.SmartServerRepositoryIsShared(backing)
606
self.make_repository('.', shared=True)
607
self.assertEqual(SmartServerResponse(('yes', )),
608
request.execute(backing.local_abspath(''), ))
610
def test_is_not_shared(self):
611
"""For a shared repository, ('no', ) is returned."""
612
backing = self.get_transport()
613
request = smart.repository.SmartServerRepositoryIsShared(backing)
614
self.make_repository('.', shared=False)
615
self.assertEqual(SmartServerResponse(('no', )),
616
request.execute(backing.local_abspath(''), ))
619
class TestSmartServerRepositoryLockWrite(tests.TestCaseWithTransport):
622
tests.TestCaseWithTransport.setUp(self)
623
self.reduceLockdirTimeout()
625
def test_lock_write_on_unlocked_repo(self):
626
backing = self.get_transport()
627
request = smart.repository.SmartServerRepositoryLockWrite(backing)
628
repository = self.make_repository('.')
629
response = request.execute(backing.local_abspath(''))
630
nonce = repository.control_files._lock.peek().get('nonce')
631
self.assertEqual(SmartServerResponse(('ok', nonce)), response)
632
# The repository is now locked. Verify that with a new repository
634
new_repo = repository.bzrdir.open_repository()
635
self.assertRaises(errors.LockContention, new_repo.lock_write)
637
def test_lock_write_on_locked_repo(self):
638
backing = self.get_transport()
639
request = smart.repository.SmartServerRepositoryLockWrite(backing)
640
repository = self.make_repository('.')
641
repository.lock_write()
642
repository.leave_lock_in_place()
644
response = request.execute(backing.local_abspath(''))
646
SmartServerResponse(('LockContention',)), response)
649
class TestSmartServerRepositoryUnlock(tests.TestCaseWithTransport):
652
tests.TestCaseWithTransport.setUp(self)
653
self.reduceLockdirTimeout()
655
def test_unlock_on_locked_repo(self):
656
backing = self.get_transport()
657
request = smart.repository.SmartServerRepositoryUnlock(backing)
658
repository = self.make_repository('.')
659
token = repository.lock_write()
660
repository.leave_lock_in_place()
662
response = request.execute(backing.local_abspath(''), token)
664
SmartServerResponse(('ok',)), response)
665
# The repository is now unlocked. Verify that with a new repository
667
new_repo = repository.bzrdir.open_repository()
668
new_repo.lock_write()
671
def test_unlock_on_unlocked_repo(self):
672
backing = self.get_transport()
673
request = smart.repository.SmartServerRepositoryUnlock(backing)
674
repository = self.make_repository('.')
675
response = request.execute(backing.local_abspath(''), 'some token')
677
SmartServerResponse(('TokenMismatch',)), response)
680
class TestHandlers(tests.TestCase):
681
"""Tests for the request.request_handlers object."""
683
def test_registered_methods(self):
684
"""Test that known methods are registered to the correct object."""
686
smart.request.request_handlers.get('Branch.get_config_file'),
687
smart.branch.SmartServerBranchGetConfigFile)
689
smart.request.request_handlers.get('Branch.lock_write'),
690
smart.branch.SmartServerBranchRequestLockWrite)
692
smart.request.request_handlers.get('Branch.last_revision_info'),
693
smart.branch.SmartServerBranchRequestLastRevisionInfo)
695
smart.request.request_handlers.get('Branch.revision_history'),
696
smart.branch.SmartServerRequestRevisionHistory)
698
smart.request.request_handlers.get('Branch.set_last_revision'),
699
smart.branch.SmartServerBranchRequestSetLastRevision)
701
smart.request.request_handlers.get('Branch.unlock'),
702
smart.branch.SmartServerBranchRequestUnlock)
704
smart.request.request_handlers.get('BzrDir.find_repository'),
705
smart.bzrdir.SmartServerRequestFindRepository)
707
smart.request.request_handlers.get('BzrDirFormat.initialize'),
708
smart.bzrdir.SmartServerRequestInitializeBzrDir)
710
smart.request.request_handlers.get('BzrDir.open_branch'),
711
smart.bzrdir.SmartServerRequestOpenBranch)
713
smart.request.request_handlers.get('Repository.gather_stats'),
714
smart.repository.SmartServerRepositoryGatherStats)
716
smart.request.request_handlers.get('Repository.get_revision_graph'),
717
smart.repository.SmartServerRepositoryGetRevisionGraph)
719
smart.request.request_handlers.get('Repository.has_revision'),
720
smart.repository.SmartServerRequestHasRevision)
722
smart.request.request_handlers.get('Repository.is_shared'),
723
smart.repository.SmartServerRepositoryIsShared)
725
smart.request.request_handlers.get('Repository.lock_write'),
726
smart.repository.SmartServerRepositoryLockWrite)
728
smart.request.request_handlers.get('Repository.unlock'),
729
smart.repository.SmartServerRepositoryUnlock)