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
self.make_branch('.')
257
self.assertEqual(SmartServerResponse(('ok',)),
258
request.execute(backing.local_abspath(''), ''))
260
def test_not_present_revision_id(self):
261
backing = self.get_transport()
262
request = smart.branch.SmartServerBranchRequestSetLastRevision(backing)
263
self.make_branch('.')
264
revision_id = 'non-existent revision'
265
self.assertEqual(SmartServerResponse(('NoSuchRevision', revision_id)),
266
request.execute(backing.local_abspath(''), revision_id))
268
def test_revision_id_present(self):
269
backing = self.get_transport()
270
request = smart.branch.SmartServerBranchRequestSetLastRevision(backing)
271
tree = self.make_branch_and_memory_tree('.')
274
r1 = tree.commit('1st commit', rev_id=u'\xc8')
275
r2 = tree.commit('2nd commit')
278
SmartServerResponse(('ok',)),
279
request.execute(backing.local_abspath(''), u'\xc8'.encode('utf8')))
280
self.assertEqual([u'\xc8'], tree.branch.revision_history())
282
def test_revision_id_present2(self):
283
backing = self.get_transport()
284
request = smart.branch.SmartServerBranchRequestSetLastRevision(backing)
285
tree = self.make_branch_and_memory_tree('.')
288
r1 = tree.commit('1st commit', rev_id=u'\xc8')
289
r2 = tree.commit('2nd commit')
291
tree.branch.set_revision_history([])
293
SmartServerResponse(('ok',)),
294
request.execute(backing.local_abspath(''), u'\xc8'.encode('utf8')))
295
self.assertEqual([u'\xc8'], tree.branch.revision_history())
298
class TestSmartServerBranchRequestLockWrite(tests.TestCaseWithTransport):
301
tests.TestCaseWithTransport.setUp(self)
302
self.reduceLockdirTimeout()
304
def test_lock_write_on_unlocked_branch(self):
305
backing = self.get_transport()
306
request = smart.branch.SmartServerBranchRequestLockWrite(backing)
307
branch = self.make_branch('.')
308
repository = branch.repository
309
response = request.execute(backing.local_abspath(''))
310
branch_nonce = branch.control_files._lock.peek().get('nonce')
311
repository_nonce = repository.control_files._lock.peek().get('nonce')
313
SmartServerResponse(('ok', branch_nonce, repository_nonce)),
315
# The branch (and associated repository) is now locked. Verify that
316
# with a new branch object.
317
new_branch = repository.bzrdir.open_branch()
318
self.assertRaises(errors.LockContention, new_branch.lock_write)
320
def test_lock_write_on_locked_branch(self):
321
backing = self.get_transport()
322
request = smart.branch.SmartServerBranchRequestLockWrite(backing)
323
branch = self.make_branch('.')
325
branch.leave_lock_in_place()
327
response = request.execute(backing.local_abspath(''))
329
SmartServerResponse(('LockContention',)), response)
331
def test_lock_write_with_tokens_on_locked_branch(self):
332
backing = self.get_transport()
333
request = smart.branch.SmartServerBranchRequestLockWrite(backing)
334
branch = self.make_branch('.')
335
branch_token, repo_token = branch.lock_write()
336
branch.leave_lock_in_place()
337
branch.repository.leave_lock_in_place()
339
response = request.execute(backing.local_abspath(''),
340
branch_token, repo_token)
342
SmartServerResponse(('ok', branch_token, repo_token)), response)
344
def test_lock_write_with_mismatched_tokens_on_locked_branch(self):
345
backing = self.get_transport()
346
request = smart.branch.SmartServerBranchRequestLockWrite(backing)
347
branch = self.make_branch('.')
348
branch_token, repo_token = branch.lock_write()
349
branch.leave_lock_in_place()
350
branch.repository.leave_lock_in_place()
352
response = request.execute(backing.local_abspath(''),
353
branch_token+'xxx', repo_token)
355
SmartServerResponse(('TokenMismatch',)), response)
357
def test_lock_write_on_locked_repo(self):
358
backing = self.get_transport()
359
request = smart.branch.SmartServerBranchRequestLockWrite(backing)
360
branch = self.make_branch('.')
361
branch.repository.lock_write()
362
branch.repository.leave_lock_in_place()
363
branch.repository.unlock()
364
response = request.execute(backing.local_abspath(''))
366
SmartServerResponse(('LockContention',)), response)
369
class TestSmartServerBranchRequestUnlock(tests.TestCaseWithTransport):
372
tests.TestCaseWithTransport.setUp(self)
373
self.reduceLockdirTimeout()
375
def test_unlock_on_locked_branch_and_repo(self):
376
backing = self.get_transport()
377
request = smart.branch.SmartServerBranchRequestUnlock(backing)
378
branch = self.make_branch('.')
380
branch_token, repo_token = branch.lock_write()
381
# Unlock the branch (and repo) object, leaving the physical locks
383
branch.leave_lock_in_place()
384
branch.repository.leave_lock_in_place()
386
response = request.execute(backing.local_abspath(''),
387
branch_token, repo_token)
389
SmartServerResponse(('ok',)), response)
390
# The branch is now unlocked. Verify that with a new branch
392
new_branch = branch.bzrdir.open_branch()
393
new_branch.lock_write()
396
def test_unlock_on_unlocked_branch_unlocked_repo(self):
397
backing = self.get_transport()
398
request = smart.branch.SmartServerBranchRequestUnlock(backing)
399
branch = self.make_branch('.')
400
response = request.execute(
401
backing.local_abspath(''), 'branch token', 'repo token')
403
SmartServerResponse(('TokenMismatch',)), response)
405
def test_unlock_on_unlocked_branch_locked_repo(self):
406
backing = self.get_transport()
407
request = smart.branch.SmartServerBranchRequestUnlock(backing)
408
branch = self.make_branch('.')
409
# Lock the repository.
410
repo_token = branch.repository.lock_write()
411
branch.repository.leave_lock_in_place()
412
branch.repository.unlock()
413
# Issue branch lock_write request on the unlocked branch (with locked
415
response = request.execute(
416
backing.local_abspath(''), 'branch token', repo_token)
418
SmartServerResponse(('TokenMismatch',)), response)
421
class TestSmartServerRepositoryRequest(tests.TestCaseWithTransport):
423
def test_no_repository(self):
424
"""Raise NoRepositoryPresent when there is a bzrdir and no repo."""
425
# we test this using a shared repository above the named path,
426
# thus checking the right search logic is used - that is, that
427
# its the exact path being looked at and the server is not
429
backing = self.get_transport()
430
request = smart.repository.SmartServerRepositoryRequest(backing)
431
self.make_repository('.', shared=True)
432
self.make_bzrdir('subdir')
433
self.assertRaises(errors.NoRepositoryPresent,
434
request.execute, backing.local_abspath('subdir'))
437
class TestSmartServerRepositoryGetRevisionGraph(tests.TestCaseWithTransport):
439
def test_none_argument(self):
440
backing = self.get_transport()
441
request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing)
442
tree = self.make_branch_and_memory_tree('.')
445
r1 = tree.commit('1st commit')
446
r2 = tree.commit('2nd commit', rev_id=u'\xc8')
449
# the lines of revision_id->revision_parent_list has no guaranteed
450
# order coming out of a dict, so sort both our test and response
451
lines = sorted([' '.join([r2, r1]), r1])
452
response = request.execute(backing.local_abspath(''), '')
453
response.body = '\n'.join(sorted(response.body.split('\n')))
455
self.assertEqual(SmartServerResponse(('ok', ),
456
'\n'.join(lines).encode('utf8')),
459
def test_specific_revision_argument(self):
460
backing = self.get_transport()
461
request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing)
462
tree = self.make_branch_and_memory_tree('.')
465
r1 = tree.commit('1st commit', rev_id=u'\xc9')
466
r2 = tree.commit('2nd commit', rev_id=u'\xc8')
469
self.assertEqual(SmartServerResponse(('ok', ),
470
u'\xc9'.encode('utf8')),
471
request.execute(backing.local_abspath(''), u'\xc9'.encode('utf8')))
473
def test_no_such_revision(self):
474
backing = self.get_transport()
475
request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing)
476
tree = self.make_branch_and_memory_tree('.')
479
r1 = tree.commit('1st commit')
482
self.assertEqual(SmartServerResponse(
483
('nosuchrevision', 'missingrevision', )),
484
request.execute(backing.local_abspath(''), 'missingrevision'))
487
class TestSmartServerRequestHasRevision(tests.TestCaseWithTransport):
489
def test_missing_revision(self):
490
"""For a missing revision, ('no', ) is returned."""
491
backing = self.get_transport()
492
request = smart.repository.SmartServerRequestHasRevision(backing)
493
self.make_repository('.')
494
self.assertEqual(SmartServerResponse(('no', )),
495
request.execute(backing.local_abspath(''), 'revid'))
497
def test_present_revision(self):
498
"""For a present revision, ('ok', ) is returned."""
499
backing = self.get_transport()
500
request = smart.repository.SmartServerRequestHasRevision(backing)
501
tree = self.make_branch_and_memory_tree('.')
504
r1 = tree.commit('a commit', rev_id=u'\xc8abc')
506
self.assertTrue(tree.branch.repository.has_revision(u'\xc8abc'))
507
self.assertEqual(SmartServerResponse(('ok', )),
508
request.execute(backing.local_abspath(''),
509
u'\xc8abc'.encode('utf8')))
512
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithTransport):
514
def test_empty_revid(self):
515
"""With an empty revid, we get only size an number and revisions"""
516
backing = self.get_transport()
517
request = smart.repository.SmartServerRepositoryGatherStats(backing)
518
repository = self.make_repository('.')
519
stats = repository.gather_stats()
521
expected_body = 'revisions: 0\nsize: %d\n' % size
522
self.assertEqual(SmartServerResponse(('ok', ), expected_body),
523
request.execute(backing.local_abspath(''), '', 'no'))
525
def test_revid_with_committers(self):
526
"""For a revid we get more infos."""
527
backing = self.get_transport()
529
request = smart.repository.SmartServerRepositoryGatherStats(backing)
530
tree = self.make_branch_and_memory_tree('.')
533
# Let's build a predictable result
534
tree.commit('a commit', timestamp=123456.2, timezone=3600)
535
tree.commit('a commit', timestamp=654321.4, timezone=0, rev_id=rev_id)
538
stats = tree.branch.repository.gather_stats()
540
expected_body = ('firstrev: 123456.200 3600\n'
541
'latestrev: 654321.400 0\n'
544
self.assertEqual(SmartServerResponse(('ok', ), expected_body),
545
request.execute(backing.local_abspath(''),
546
rev_id.encode('utf8'), 'no'))
548
def test_not_empty_repository_with_committers(self):
549
"""For a revid and requesting committers we get the whole thing."""
550
backing = self.get_transport()
552
request = smart.repository.SmartServerRepositoryGatherStats(backing)
553
tree = self.make_branch_and_memory_tree('.')
556
# Let's build a predictable result
557
tree.commit('a commit', timestamp=123456.2, timezone=3600,
559
tree.commit('a commit', timestamp=654321.4, timezone=0,
560
committer='bar', rev_id=rev_id)
562
stats = tree.branch.repository.gather_stats()
565
expected_body = ('committers: 2\n'
566
'firstrev: 123456.200 3600\n'
567
'latestrev: 654321.400 0\n'
570
self.assertEqual(SmartServerResponse(('ok', ), expected_body),
571
request.execute(backing.local_abspath(''),
572
rev_id.encode('utf8'), 'yes'))
575
class TestSmartServerRepositoryIsShared(tests.TestCaseWithTransport):
577
def test_is_shared(self):
578
"""For a shared repository, ('yes', ) is returned."""
579
backing = self.get_transport()
580
request = smart.repository.SmartServerRepositoryIsShared(backing)
581
self.make_repository('.', shared=True)
582
self.assertEqual(SmartServerResponse(('yes', )),
583
request.execute(backing.local_abspath(''), ))
585
def test_is_not_shared(self):
586
"""For a shared repository, ('no', ) is returned."""
587
backing = self.get_transport()
588
request = smart.repository.SmartServerRepositoryIsShared(backing)
589
self.make_repository('.', shared=False)
590
self.assertEqual(SmartServerResponse(('no', )),
591
request.execute(backing.local_abspath(''), ))
594
class TestSmartServerRepositoryLockWrite(tests.TestCaseWithTransport):
597
tests.TestCaseWithTransport.setUp(self)
598
self.reduceLockdirTimeout()
600
def test_lock_write_on_unlocked_repo(self):
601
backing = self.get_transport()
602
request = smart.repository.SmartServerRepositoryLockWrite(backing)
603
repository = self.make_repository('.')
604
response = request.execute(backing.local_abspath(''))
605
nonce = repository.control_files._lock.peek().get('nonce')
606
self.assertEqual(SmartServerResponse(('ok', nonce)), response)
607
# The repository is now locked. Verify that with a new repository
609
new_repo = repository.bzrdir.open_repository()
610
self.assertRaises(errors.LockContention, new_repo.lock_write)
612
def test_lock_write_on_locked_repo(self):
613
backing = self.get_transport()
614
request = smart.repository.SmartServerRepositoryLockWrite(backing)
615
repository = self.make_repository('.')
616
repository.lock_write()
617
repository.leave_lock_in_place()
619
response = request.execute(backing.local_abspath(''))
621
SmartServerResponse(('LockContention',)), response)
624
class TestSmartServerRepositoryUnlock(tests.TestCaseWithTransport):
627
tests.TestCaseWithTransport.setUp(self)
628
self.reduceLockdirTimeout()
630
def test_unlock_on_locked_repo(self):
631
backing = self.get_transport()
632
request = smart.repository.SmartServerRepositoryUnlock(backing)
633
repository = self.make_repository('.')
634
token = repository.lock_write()
635
repository.leave_lock_in_place()
637
response = request.execute(backing.local_abspath(''), token)
639
SmartServerResponse(('ok',)), response)
640
# The repository is now unlocked. Verify that with a new repository
642
new_repo = repository.bzrdir.open_repository()
643
new_repo.lock_write()
646
def test_unlock_on_unlocked_repo(self):
647
backing = self.get_transport()
648
request = smart.repository.SmartServerRepositoryUnlock(backing)
649
repository = self.make_repository('.')
650
response = request.execute(backing.local_abspath(''), 'some token')
652
SmartServerResponse(('TokenMismatch',)), response)
655
class TestHandlers(tests.TestCase):
656
"""Tests for the request.request_handlers object."""
658
def test_registered_methods(self):
659
"""Test that known methods are registered to the correct object."""
661
smart.request.request_handlers.get('Branch.get_config_file'),
662
smart.branch.SmartServerBranchGetConfigFile)
664
smart.request.request_handlers.get('Branch.lock_write'),
665
smart.branch.SmartServerBranchRequestLockWrite)
667
smart.request.request_handlers.get('Branch.last_revision_info'),
668
smart.branch.SmartServerBranchRequestLastRevisionInfo)
670
smart.request.request_handlers.get('Branch.revision_history'),
671
smart.branch.SmartServerRequestRevisionHistory)
673
smart.request.request_handlers.get('Branch.set_last_revision'),
674
smart.branch.SmartServerBranchRequestSetLastRevision)
676
smart.request.request_handlers.get('Branch.unlock'),
677
smart.branch.SmartServerBranchRequestUnlock)
679
smart.request.request_handlers.get('BzrDir.find_repository'),
680
smart.bzrdir.SmartServerRequestFindRepository)
682
smart.request.request_handlers.get('BzrDirFormat.initialize'),
683
smart.bzrdir.SmartServerRequestInitializeBzrDir)
685
smart.request.request_handlers.get('BzrDir.open_branch'),
686
smart.bzrdir.SmartServerRequestOpenBranch)
688
smart.request.request_handlers.get('Repository.gather_stats'),
689
smart.repository.SmartServerRepositoryGatherStats)
691
smart.request.request_handlers.get('Repository.get_revision_graph'),
692
smart.repository.SmartServerRepositoryGetRevisionGraph)
694
smart.request.request_handlers.get('Repository.has_revision'),
695
smart.repository.SmartServerRequestHasRevision)
697
smart.request.request_handlers.get('Repository.is_shared'),
698
smart.repository.SmartServerRepositoryIsShared)
700
smart.request.request_handlers.get('Repository.lock_write'),
701
smart.repository.SmartServerRepositoryLockWrite)
703
smart.request.request_handlers.get('Repository.unlock'),
704
smart.repository.SmartServerRepositoryUnlock)