/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Andrew Bennetts
  • Date: 2008-04-02 00:14:00 UTC
  • mfrom: (3324 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3756.
  • Revision ID: andrew.bennetts@canonical.com-20080402001400-r1pqse38i03dl97w
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
"""
26
26
 
27
27
import bz2
28
 
from StringIO import StringIO
29
 
import tempfile
 
28
from cStringIO import StringIO
30
29
import tarfile
31
30
 
32
 
from bzrlib import bzrdir, errors, pack, smart, tests
 
31
from bzrlib import (
 
32
    bzrdir,
 
33
    errors,
 
34
    pack,
 
35
    smart,
 
36
    tests,
 
37
    urlutils,
 
38
    )
 
39
from bzrlib.branch import BranchReferenceFormat
 
40
import bzrlib.smart.branch
 
41
import bzrlib.smart.bzrdir
 
42
import bzrlib.smart.repository
33
43
from bzrlib.smart.request import (
34
44
    FailedSmartServerResponse,
 
45
    SmartServerRequest,
35
46
    SmartServerResponse,
36
47
    SuccessfulSmartServerResponse,
37
48
    )
38
 
import bzrlib.smart.bzrdir
39
 
import bzrlib.smart.branch
40
 
import bzrlib.smart.repository
41
49
from bzrlib.tests import (
42
50
    iter_suite_tests,
43
51
    split_suite_by_re,
44
52
    TestScenarioApplier,
45
53
    )
 
54
from bzrlib.transport import chroot, get_transport
46
55
from bzrlib.util import bencode
47
56
 
48
57
 
69
78
    return result
70
79
 
71
80
 
 
81
class TestCaseWithChrootedTransport(tests.TestCaseWithTransport):
 
82
 
 
83
    def setUp(self):
 
84
        tests.TestCaseWithTransport.setUp(self)
 
85
        self._chroot_server = None
 
86
 
 
87
    def get_transport(self, relpath=None):
 
88
        if self._chroot_server is None:
 
89
            backing_transport = tests.TestCaseWithTransport.get_transport(self)
 
90
            self._chroot_server = chroot.ChrootServer(backing_transport)
 
91
            self._chroot_server.setUp()
 
92
            self.addCleanup(self._chroot_server.tearDown)
 
93
        t = get_transport(self._chroot_server.get_url())
 
94
        if relpath is not None:
 
95
            t = t.clone(relpath)
 
96
        return t
 
97
 
 
98
 
72
99
class TestCaseWithSmartMedium(tests.TestCaseWithTransport):
73
100
 
74
101
    def setUp(self):
98
125
        self.assertNotEqual(None,
99
126
            SmartServerResponse(('ok', )))
100
127
 
101
 
 
102
 
class TestSmartServerRequestFindRepository(tests.TestCaseWithTransport):
 
128
    def test__str__(self):
 
129
        """SmartServerResponses can be stringified."""
 
130
        self.assertEqual(
 
131
            "<SmartServerResponse status=OK args=('args',) body='body'>",
 
132
            str(SuccessfulSmartServerResponse(('args',), 'body')))
 
133
        self.assertEqual(
 
134
            "<SmartServerResponse status=ERR args=('args',) body='body'>",
 
135
            str(FailedSmartServerResponse(('args',), 'body')))
 
136
 
 
137
 
 
138
class TestSmartServerRequest(tests.TestCaseWithMemoryTransport):
 
139
 
 
140
    def test_translate_client_path(self):
 
141
        transport = self.get_transport()
 
142
        request = SmartServerRequest(transport, 'foo/')
 
143
        self.assertEqual('./', request.translate_client_path('foo/'))
 
144
        self.assertRaises(
 
145
            errors.InvalidURLJoin, request.translate_client_path, 'foo/..')
 
146
        self.assertRaises(
 
147
            errors.PathNotChild, request.translate_client_path, '/')
 
148
        self.assertRaises(
 
149
            errors.PathNotChild, request.translate_client_path, 'bar/')
 
150
        self.assertEqual('./baz', request.translate_client_path('foo/baz'))
 
151
 
 
152
    def test_transport_from_client_path(self):
 
153
        transport = self.get_transport()
 
154
        request = SmartServerRequest(transport, 'foo/')
 
155
        self.assertEqual(
 
156
            transport.base,
 
157
            request.transport_from_client_path('foo/').base)
 
158
 
 
159
 
 
160
class TestSmartServerRequestFindRepository(tests.TestCaseWithMemoryTransport):
103
161
    """Tests for BzrDir.find_repository."""
104
162
 
105
163
    def test_no_repository(self):
108
166
        request = self._request_class(backing)
109
167
        self.make_bzrdir('.')
110
168
        self.assertEqual(SmartServerResponse(('norepository', )),
111
 
            request.execute(backing.local_abspath('')))
 
169
            request.execute(''))
112
170
 
113
171
    def test_nonshared_repository(self):
114
172
        # nonshared repositorys only allow 'find' to return a handle when the 
117
175
        backing = self.get_transport()
118
176
        request = self._request_class(backing)
119
177
        result = self._make_repository_and_result()
120
 
        self.assertEqual(result, request.execute(backing.local_abspath('')))
 
178
        self.assertEqual(result, request.execute(''))
121
179
        self.make_bzrdir('subdir')
122
180
        self.assertEqual(SmartServerResponse(('norepository', )),
123
 
            request.execute(backing.local_abspath('subdir')))
 
181
            request.execute('subdir'))
124
182
 
125
183
    def _make_repository_and_result(self, shared=False, format=None):
126
184
        """Convenience function to setup a repository.
150
208
        backing = self.get_transport()
151
209
        request = self._request_class(backing)
152
210
        result = self._make_repository_and_result(shared=True)
153
 
        self.assertEqual(result, request.execute(backing.local_abspath('')))
 
211
        self.assertEqual(result, request.execute(''))
154
212
        self.make_bzrdir('subdir')
155
213
        result2 = SmartServerResponse(result.args[0:1] + ('..', ) + result.args[2:])
156
214
        self.assertEqual(result2,
157
 
            request.execute(backing.local_abspath('subdir')))
 
215
            request.execute('subdir'))
158
216
        self.make_bzrdir('subdir/deeper')
159
217
        result3 = SmartServerResponse(result.args[0:1] + ('../..', ) + result.args[2:])
160
218
        self.assertEqual(result3,
161
 
            request.execute(backing.local_abspath('subdir/deeper')))
 
219
            request.execute('subdir/deeper'))
162
220
 
163
221
    def test_rich_root_and_subtree_encoding(self):
164
222
        """Test for the format attributes for rich root and subtree support."""
168
226
        # check the test will be valid
169
227
        self.assertEqual('yes', result.args[2])
170
228
        self.assertEqual('yes', result.args[3])
171
 
        self.assertEqual(result, request.execute(backing.local_abspath('')))
 
229
        self.assertEqual(result, request.execute(''))
172
230
 
173
231
    def test_supports_external_lookups_no_v2(self):
174
232
        """Test for the supports_external_lookups attribute."""
177
235
        result = self._make_repository_and_result(format='dirstate-with-subtree')
178
236
        # check the test will be valid
179
237
        self.assertEqual('no', result.args[4])
180
 
        self.assertEqual(result, request.execute(backing.local_abspath('')))
181
 
 
182
 
 
183
 
class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithTransport):
 
238
        self.assertEqual(result, request.execute(''))
 
239
 
 
240
 
 
241
class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithMemoryTransport):
184
242
 
185
243
    def test_empty_dir(self):
186
244
        """Initializing an empty dir should succeed and do it."""
187
245
        backing = self.get_transport()
188
246
        request = smart.bzrdir.SmartServerRequestInitializeBzrDir(backing)
189
247
        self.assertEqual(SmartServerResponse(('ok', )),
190
 
            request.execute(backing.local_abspath('.')))
 
248
            request.execute(''))
191
249
        made_dir = bzrdir.BzrDir.open_from_transport(backing)
192
250
        # no branch, tree or repository is expected with the current 
193
251
        # default formart.
200
258
        backing = self.get_transport()
201
259
        request = smart.bzrdir.SmartServerRequestInitializeBzrDir(backing)
202
260
        self.assertRaises(errors.NoSuchFile,
203
 
            request.execute, backing.local_abspath('subdir'))
 
261
            request.execute, 'subdir')
204
262
 
205
263
    def test_initialized_dir(self):
206
264
        """Initializing an extant bzrdir should fail like the bzrdir api."""
208
266
        request = smart.bzrdir.SmartServerRequestInitializeBzrDir(backing)
209
267
        self.make_bzrdir('subdir')
210
268
        self.assertRaises(errors.FileExists,
211
 
            request.execute, backing.local_abspath('subdir'))
212
 
 
213
 
 
214
 
class TestSmartServerRequestOpenBranch(tests.TestCaseWithTransport):
 
269
            request.execute, 'subdir')
 
270
 
 
271
 
 
272
class TestSmartServerRequestOpenBranch(TestCaseWithChrootedTransport):
215
273
 
216
274
    def test_no_branch(self):
217
275
        """When there is no branch, ('nobranch', ) is returned."""
219
277
        request = smart.bzrdir.SmartServerRequestOpenBranch(backing)
220
278
        self.make_bzrdir('.')
221
279
        self.assertEqual(SmartServerResponse(('nobranch', )),
222
 
            request.execute(backing.local_abspath('')))
 
280
            request.execute(''))
223
281
 
224
282
    def test_branch(self):
225
283
        """When there is a branch, 'ok' is returned."""
227
285
        request = smart.bzrdir.SmartServerRequestOpenBranch(backing)
228
286
        self.make_branch('.')
229
287
        self.assertEqual(SmartServerResponse(('ok', '')),
230
 
            request.execute(backing.local_abspath('')))
 
288
            request.execute(''))
231
289
 
232
290
    def test_branch_reference(self):
233
291
        """When there is a branch reference, the reference URL is returned."""
235
293
        request = smart.bzrdir.SmartServerRequestOpenBranch(backing)
236
294
        branch = self.make_branch('branch')
237
295
        checkout = branch.create_checkout('reference',lightweight=True)
238
 
        # TODO: once we have an API to probe for references of any sort, we
239
 
        # can use it here.
240
 
        reference_url = backing.abspath('branch') + '/'
 
296
        reference_url = BranchReferenceFormat().get_reference(checkout.bzrdir)
241
297
        self.assertFileEqual(reference_url, 'reference/.bzr/branch/location')
242
298
        self.assertEqual(SmartServerResponse(('ok', reference_url)),
243
 
            request.execute(backing.local_abspath('reference')))
244
 
 
245
 
 
246
 
class TestSmartServerRequestRevisionHistory(tests.TestCaseWithTransport):
 
299
            request.execute('reference'))
 
300
 
 
301
 
 
302
class TestSmartServerRequestRevisionHistory(tests.TestCaseWithMemoryTransport):
247
303
 
248
304
    def test_empty(self):
249
305
        """For an empty branch, the body is empty."""
251
307
        request = smart.branch.SmartServerRequestRevisionHistory(backing)
252
308
        self.make_branch('.')
253
309
        self.assertEqual(SmartServerResponse(('ok', ), ''),
254
 
            request.execute(backing.local_abspath('')))
 
310
            request.execute(''))
255
311
 
256
312
    def test_not_empty(self):
257
313
        """For a non-empty branch, the body is empty."""
265
321
        tree.unlock()
266
322
        self.assertEqual(
267
323
            SmartServerResponse(('ok', ), ('\x00'.join([r1, r2]))),
268
 
            request.execute(backing.local_abspath('')))
269
 
 
270
 
 
271
 
class TestSmartServerBranchRequest(tests.TestCaseWithTransport):
 
324
            request.execute(''))
 
325
 
 
326
 
 
327
class TestSmartServerBranchRequest(tests.TestCaseWithMemoryTransport):
272
328
 
273
329
    def test_no_branch(self):
274
330
        """When there is a bzrdir and no branch, NotBranchError is raised."""
276
332
        request = smart.branch.SmartServerBranchRequest(backing)
277
333
        self.make_bzrdir('.')
278
334
        self.assertRaises(errors.NotBranchError,
279
 
            request.execute, backing.local_abspath(''))
 
335
            request.execute, '')
280
336
 
281
337
    def test_branch_reference(self):
282
338
        """When there is a branch reference, NotBranchError is raised."""
285
341
        branch = self.make_branch('branch')
286
342
        checkout = branch.create_checkout('reference',lightweight=True)
287
343
        self.assertRaises(errors.NotBranchError,
288
 
            request.execute, backing.local_abspath('checkout'))
289
 
 
290
 
 
291
 
class TestSmartServerBranchRequestLastRevisionInfo(tests.TestCaseWithTransport):
 
344
            request.execute, 'checkout')
 
345
 
 
346
 
 
347
class TestSmartServerBranchRequestLastRevisionInfo(tests.TestCaseWithMemoryTransport):
292
348
 
293
349
    def test_empty(self):
294
350
        """For an empty branch, the result is ('ok', '0', 'null:')."""
296
352
        request = smart.branch.SmartServerBranchRequestLastRevisionInfo(backing)
297
353
        self.make_branch('.')
298
354
        self.assertEqual(SmartServerResponse(('ok', '0', 'null:')),
299
 
            request.execute(backing.local_abspath('')))
 
355
            request.execute(''))
300
356
 
301
357
    def test_not_empty(self):
302
358
        """For a non-empty branch, the result is ('ok', 'revno', 'revid')."""
311
367
        tree.unlock()
312
368
        self.assertEqual(
313
369
            SmartServerResponse(('ok', '2', rev_id_utf8)),
314
 
            request.execute(backing.local_abspath('')))
315
 
 
316
 
 
317
 
class TestSmartServerBranchRequestGetConfigFile(tests.TestCaseWithTransport):
 
370
            request.execute(''))
 
371
 
 
372
 
 
373
class TestSmartServerBranchRequestGetConfigFile(tests.TestCaseWithMemoryTransport):
318
374
 
319
375
    def test_default(self):
320
376
        """With no file, we get empty content."""
324
380
        # there should be no file by default
325
381
        content = ''
326
382
        self.assertEqual(SmartServerResponse(('ok', ), content),
327
 
            request.execute(backing.local_abspath('')))
 
383
            request.execute(''))
328
384
 
329
385
    def test_with_content(self):
330
386
        # SmartServerBranchGetConfigFile should return the content from
335
391
        branch = self.make_branch('.')
336
392
        branch.control_files.put_utf8('branch.conf', 'foo bar baz')
337
393
        self.assertEqual(SmartServerResponse(('ok', ), 'foo bar baz'),
338
 
            request.execute(backing.local_abspath('')))
339
 
 
340
 
 
341
 
class TestSmartServerBranchRequestSetLastRevision(tests.TestCaseWithTransport):
 
394
            request.execute(''))
 
395
 
 
396
 
 
397
class TestSmartServerBranchRequestSetLastRevision(tests.TestCaseWithMemoryTransport):
342
398
 
343
399
    def test_empty(self):
344
400
        backing = self.get_transport()
350
406
        try:
351
407
            self.assertEqual(SmartServerResponse(('ok',)),
352
408
                request.execute(
353
 
                    backing.local_abspath(''), branch_token, repo_token,
 
409
                    '', branch_token, repo_token,
354
410
                    'null:'))
355
411
        finally:
356
412
            b.unlock()
367
423
            self.assertEqual(
368
424
                SmartServerResponse(('NoSuchRevision', revision_id)),
369
425
                request.execute(
370
 
                    backing.local_abspath(''), branch_token, repo_token,
 
426
                    '', branch_token, repo_token,
371
427
                    revision_id))
372
428
        finally:
373
429
            b.unlock()
389
445
            self.assertEqual(
390
446
                SmartServerResponse(('ok',)),
391
447
                request.execute(
392
 
                    backing.local_abspath(''), branch_token, repo_token,
 
448
                    '', branch_token, repo_token,
393
449
                    rev_id_utf8))
394
450
            self.assertEqual([rev_id_utf8], tree.branch.revision_history())
395
451
        finally:
413
469
            self.assertEqual(
414
470
                SmartServerResponse(('ok',)),
415
471
                request.execute(
416
 
                    backing.local_abspath(''), branch_token, repo_token,
 
472
                    '', branch_token, repo_token,
417
473
                    rev_id_utf8))
418
474
            self.assertEqual([rev_id_utf8], tree.branch.revision_history())
419
475
        finally:
420
476
            tree.branch.unlock()
421
477
 
422
478
 
423
 
class TestSmartServerBranchRequestLockWrite(tests.TestCaseWithTransport):
 
479
class TestSmartServerBranchRequestLockWrite(tests.TestCaseWithMemoryTransport):
424
480
 
425
481
    def setUp(self):
426
 
        tests.TestCaseWithTransport.setUp(self)
427
 
        self.reduceLockdirTimeout()
 
482
        tests.TestCaseWithMemoryTransport.setUp(self)
428
483
 
429
484
    def test_lock_write_on_unlocked_branch(self):
430
485
        backing = self.get_transport()
431
486
        request = smart.branch.SmartServerBranchRequestLockWrite(backing)
432
487
        branch = self.make_branch('.', format='knit')
433
488
        repository = branch.repository
434
 
        response = request.execute(backing.local_abspath(''))
 
489
        response = request.execute('')
435
490
        branch_nonce = branch.control_files._lock.peek().get('nonce')
436
491
        repository_nonce = repository.control_files._lock.peek().get('nonce')
437
492
        self.assertEqual(
449
504
        branch.lock_write()
450
505
        branch.leave_lock_in_place()
451
506
        branch.unlock()
452
 
        response = request.execute(backing.local_abspath(''))
 
507
        response = request.execute('')
453
508
        self.assertEqual(
454
509
            SmartServerResponse(('LockContention',)), response)
455
510
 
463
518
        branch.leave_lock_in_place()
464
519
        branch.repository.leave_lock_in_place()
465
520
        branch.unlock()
466
 
        response = request.execute(backing.local_abspath(''),
 
521
        response = request.execute('',
467
522
                                   branch_token, repo_token)
468
523
        self.assertEqual(
469
524
            SmartServerResponse(('ok', branch_token, repo_token)), response)
478
533
        branch.leave_lock_in_place()
479
534
        branch.repository.leave_lock_in_place()
480
535
        branch.unlock()
481
 
        response = request.execute(backing.local_abspath(''),
 
536
        response = request.execute('',
482
537
                                   branch_token+'xxx', repo_token)
483
538
        self.assertEqual(
484
539
            SmartServerResponse(('TokenMismatch',)), response)
490
545
        branch.repository.lock_write()
491
546
        branch.repository.leave_lock_in_place()
492
547
        branch.repository.unlock()
493
 
        response = request.execute(backing.local_abspath(''))
 
548
        response = request.execute('')
494
549
        self.assertEqual(
495
550
            SmartServerResponse(('LockContention',)), response)
496
551
 
498
553
        backing = self.get_readonly_transport()
499
554
        request = smart.branch.SmartServerBranchRequestLockWrite(backing)
500
555
        branch = self.make_branch('.')
501
 
        response = request.execute('')
 
556
        root = self.get_transport().clone('/')
 
557
        path = urlutils.relative_url(root.base, self.get_transport().base)
 
558
        response = request.execute(path)
502
559
        error_name, lock_str, why_str = response.args
503
560
        self.assertFalse(response.is_successful())
504
561
        self.assertEqual('LockFailed', error_name)
505
562
 
506
563
 
507
 
class TestSmartServerBranchRequestUnlock(tests.TestCaseWithTransport):
 
564
class TestSmartServerBranchRequestUnlock(tests.TestCaseWithMemoryTransport):
508
565
 
509
566
    def setUp(self):
510
 
        tests.TestCaseWithTransport.setUp(self)
511
 
        self.reduceLockdirTimeout()
 
567
        tests.TestCaseWithMemoryTransport.setUp(self)
512
568
 
513
569
    def test_unlock_on_locked_branch_and_repo(self):
514
570
        backing = self.get_transport()
523
579
        branch.leave_lock_in_place()
524
580
        branch.repository.leave_lock_in_place()
525
581
        branch.unlock()
526
 
        response = request.execute(backing.local_abspath(''),
 
582
        response = request.execute('',
527
583
                                   branch_token, repo_token)
528
584
        self.assertEqual(
529
585
            SmartServerResponse(('ok',)), response)
538
594
        request = smart.branch.SmartServerBranchRequestUnlock(backing)
539
595
        branch = self.make_branch('.', format='knit')
540
596
        response = request.execute(
541
 
            backing.local_abspath(''), 'branch token', 'repo token')
 
597
            '', 'branch token', 'repo token')
542
598
        self.assertEqual(
543
599
            SmartServerResponse(('TokenMismatch',)), response)
544
600
 
553
609
        # Issue branch lock_write request on the unlocked branch (with locked
554
610
        # repo).
555
611
        response = request.execute(
556
 
            backing.local_abspath(''), 'branch token', repo_token)
 
612
            '', 'branch token', repo_token)
557
613
        self.assertEqual(
558
614
            SmartServerResponse(('TokenMismatch',)), response)
559
615
 
560
616
 
561
 
class TestSmartServerRepositoryRequest(tests.TestCaseWithTransport):
 
617
class TestSmartServerRepositoryRequest(tests.TestCaseWithMemoryTransport):
562
618
 
563
619
    def test_no_repository(self):
564
620
        """Raise NoRepositoryPresent when there is a bzrdir and no repo."""
571
627
        self.make_repository('.', shared=True)
572
628
        self.make_bzrdir('subdir')
573
629
        self.assertRaises(errors.NoRepositoryPresent,
574
 
            request.execute, backing.local_abspath('subdir'))
 
630
            request.execute, 'subdir')
575
631
 
576
632
 
577
633
class TestSmartServerRepositoryGetParentMap(tests.TestCaseWithTransport):
583
639
        tree = self.make_branch_and_memory_tree('.')
584
640
 
585
641
        self.assertEqual(None,
586
 
            request.execute(backing.local_abspath(''), 'missing-id'))
 
642
            request.execute('', 'missing-id'))
587
643
        # Note that it returns a body (of '' bzipped).
588
644
        self.assertEqual(
589
645
            SuccessfulSmartServerResponse(('ok', ), bz2.compress('')),
590
646
            request.do_body('\n\n0\n'))
591
647
 
592
648
 
593
 
class TestSmartServerRepositoryGetRevisionGraph(tests.TestCaseWithTransport):
 
649
class TestSmartServerRepositoryGetRevisionGraph(tests.TestCaseWithMemoryTransport):
594
650
 
595
651
    def test_none_argument(self):
596
652
        backing = self.get_transport()
605
661
        # the lines of revision_id->revision_parent_list has no guaranteed
606
662
        # order coming out of a dict, so sort both our test and response
607
663
        lines = sorted([' '.join([r2, r1]), r1])
608
 
        response = request.execute(backing.local_abspath(''), '')
 
664
        response = request.execute('', '')
609
665
        response.body = '\n'.join(sorted(response.body.split('\n')))
610
666
 
611
667
        self.assertEqual(
623
679
        tree.unlock()
624
680
 
625
681
        self.assertEqual(SmartServerResponse(('ok', ), rev_id_utf8),
626
 
            request.execute(backing.local_abspath(''), rev_id_utf8))
 
682
            request.execute('', rev_id_utf8))
627
683
    
628
684
    def test_no_such_revision(self):
629
685
        backing = self.get_transport()
637
693
        # Note that it still returns body (of zero bytes).
638
694
        self.assertEqual(
639
695
            SmartServerResponse(('nosuchrevision', 'missingrevision', ), ''),
640
 
            request.execute(backing.local_abspath(''), 'missingrevision'))
641
 
 
642
 
 
643
 
class TestSmartServerRequestHasRevision(tests.TestCaseWithTransport):
 
696
            request.execute('', 'missingrevision'))
 
697
 
 
698
 
 
699
class TestSmartServerRequestHasRevision(tests.TestCaseWithMemoryTransport):
644
700
 
645
701
    def test_missing_revision(self):
646
702
        """For a missing revision, ('no', ) is returned."""
648
704
        request = smart.repository.SmartServerRequestHasRevision(backing)
649
705
        self.make_repository('.')
650
706
        self.assertEqual(SmartServerResponse(('no', )),
651
 
            request.execute(backing.local_abspath(''), 'revid'))
 
707
            request.execute('', 'revid'))
652
708
 
653
709
    def test_present_revision(self):
654
710
        """For a present revision, ('yes', ) is returned."""
662
718
        tree.unlock()
663
719
        self.assertTrue(tree.branch.repository.has_revision(rev_id_utf8))
664
720
        self.assertEqual(SmartServerResponse(('yes', )),
665
 
            request.execute(backing.local_abspath(''), rev_id_utf8))
666
 
 
667
 
 
668
 
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithTransport):
 
721
            request.execute('', rev_id_utf8))
 
722
 
 
723
 
 
724
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithMemoryTransport):
669
725
 
670
726
    def test_empty_revid(self):
671
727
        """With an empty revid, we get only size an number and revisions"""
676
732
        size = stats['size']
677
733
        expected_body = 'revisions: 0\nsize: %d\n' % size
678
734
        self.assertEqual(SmartServerResponse(('ok', ), expected_body),
679
 
                         request.execute(backing.local_abspath(''), '', 'no'))
 
735
                         request.execute('', '', 'no'))
680
736
 
681
737
    def test_revid_with_committers(self):
682
738
        """For a revid we get more infos."""
699
755
                         'revisions: 2\n'
700
756
                         'size: %d\n' % size)
701
757
        self.assertEqual(SmartServerResponse(('ok', ), expected_body),
702
 
                         request.execute(backing.local_abspath(''),
 
758
                         request.execute('',
703
759
                                         rev_id_utf8, 'no'))
704
760
 
705
761
    def test_not_empty_repository_with_committers(self):
725
781
                         'revisions: 2\n'
726
782
                         'size: %d\n' % size)
727
783
        self.assertEqual(SmartServerResponse(('ok', ), expected_body),
728
 
                         request.execute(backing.local_abspath(''),
 
784
                         request.execute('',
729
785
                                         rev_id_utf8, 'yes'))
730
786
 
731
787
 
732
 
class TestSmartServerRepositoryIsShared(tests.TestCaseWithTransport):
 
788
class TestSmartServerRepositoryIsShared(tests.TestCaseWithMemoryTransport):
733
789
 
734
790
    def test_is_shared(self):
735
791
        """For a shared repository, ('yes', ) is returned."""
737
793
        request = smart.repository.SmartServerRepositoryIsShared(backing)
738
794
        self.make_repository('.', shared=True)
739
795
        self.assertEqual(SmartServerResponse(('yes', )),
740
 
            request.execute(backing.local_abspath(''), ))
 
796
            request.execute('', ))
741
797
 
742
798
    def test_is_not_shared(self):
743
799
        """For a shared repository, ('no', ) is returned."""
745
801
        request = smart.repository.SmartServerRepositoryIsShared(backing)
746
802
        self.make_repository('.', shared=False)
747
803
        self.assertEqual(SmartServerResponse(('no', )),
748
 
            request.execute(backing.local_abspath(''), ))
749
 
 
750
 
 
751
 
class TestSmartServerRepositoryLockWrite(tests.TestCaseWithTransport):
 
804
            request.execute('', ))
 
805
 
 
806
 
 
807
class TestSmartServerRepositoryLockWrite(tests.TestCaseWithMemoryTransport):
752
808
 
753
809
    def setUp(self):
754
 
        tests.TestCaseWithTransport.setUp(self)
755
 
        self.reduceLockdirTimeout()
 
810
        tests.TestCaseWithMemoryTransport.setUp(self)
756
811
 
757
812
    def test_lock_write_on_unlocked_repo(self):
758
813
        backing = self.get_transport()
759
814
        request = smart.repository.SmartServerRepositoryLockWrite(backing)
760
815
        repository = self.make_repository('.', format='knit')
761
 
        response = request.execute(backing.local_abspath(''))
 
816
        response = request.execute('')
762
817
        nonce = repository.control_files._lock.peek().get('nonce')
763
818
        self.assertEqual(SmartServerResponse(('ok', nonce)), response)
764
819
        # The repository is now locked.  Verify that with a new repository
773
828
        repository.lock_write()
774
829
        repository.leave_lock_in_place()
775
830
        repository.unlock()
776
 
        response = request.execute(backing.local_abspath(''))
 
831
        response = request.execute('')
777
832
        self.assertEqual(
778
833
            SmartServerResponse(('LockContention',)), response)
779
834
 
786
841
        self.assertEqual('LockFailed', response.args[0])
787
842
 
788
843
 
789
 
class TestSmartServerRepositoryUnlock(tests.TestCaseWithTransport):
 
844
class TestSmartServerRepositoryUnlock(tests.TestCaseWithMemoryTransport):
790
845
 
791
846
    def setUp(self):
792
 
        tests.TestCaseWithTransport.setUp(self)
793
 
        self.reduceLockdirTimeout()
 
847
        tests.TestCaseWithMemoryTransport.setUp(self)
794
848
 
795
849
    def test_unlock_on_locked_repo(self):
796
850
        backing = self.get_transport()
799
853
        token = repository.lock_write()
800
854
        repository.leave_lock_in_place()
801
855
        repository.unlock()
802
 
        response = request.execute(backing.local_abspath(''), token)
 
856
        response = request.execute('', token)
803
857
        self.assertEqual(
804
858
            SmartServerResponse(('ok',)), response)
805
859
        # The repository is now unlocked.  Verify that with a new repository
812
866
        backing = self.get_transport()
813
867
        request = smart.repository.SmartServerRepositoryUnlock(backing)
814
868
        repository = self.make_repository('.', format='knit')
815
 
        response = request.execute(backing.local_abspath(''), 'some token')
 
869
        response = request.execute('', 'some token')
816
870
        self.assertEqual(
817
871
            SmartServerResponse(('TokenMismatch',)), response)
818
872
 
826
880
        # make some extraneous junk in the repository directory which should
827
881
        # not be copied
828
882
        self.build_tree(['.bzr/repository/extra-junk'])
829
 
        response = request.execute(backing.local_abspath(''), 'bz2')
 
883
        response = request.execute('', 'bz2')
830
884
        self.assertEqual(('ok',), response.args)
831
885
        # body should be a tbz2
832
886
        body_file = StringIO(response.body)
841
895
            "extraneous file present in tar file")
842
896
 
843
897
 
844
 
class TestSmartServerRepositoryStreamKnitData(tests.TestCaseWithTransport):
 
898
class TestSmartServerRepositoryStreamKnitData(tests.TestCaseWithMemoryTransport):
845
899
 
846
900
    def test_fetch_revisions(self):
847
901
        backing = self.get_transport()
855
909
        r1 = tree.commit('2nd commit', rev_id=rev_id2_utf8)
856
910
        tree.unlock()
857
911
 
858
 
        response = request.execute(backing.local_abspath(''), rev_id2_utf8)
 
912
        response = request.execute('', rev_id2_utf8)
859
913
        self.assertEqual(('ok',), response.args)
860
 
        from cStringIO import StringIO
861
914
        unpacker = pack.ContainerReader(StringIO(response.body))
862
915
        names = []
863
916
        for [name], read_bytes in unpacker.iter_records():
873
926
        request = smart.repository.SmartServerRepositoryStreamKnitDataForRevisions(backing)
874
927
        repo = self.make_repository('.')
875
928
        rev_id1_utf8 = u'\xc8'.encode('utf-8')
876
 
        response = request.execute(backing.local_abspath(''), rev_id1_utf8)
 
929
        response = request.execute('', rev_id1_utf8)
877
930
        self.assertEqual(
878
931
            SmartServerResponse(('NoSuchRevision', rev_id1_utf8)),
879
932
            response)
880
933
 
881
934
 
882
 
class TestSmartServerRepositoryStreamRevisionsChunked(tests.TestCaseWithTransport):
 
935
class TestSmartServerRepositoryStreamRevisionsChunked(tests.TestCaseWithMemoryTransport):
883
936
 
884
937
    def test_fetch_revisions(self):
885
938
        backing = self.get_transport()
894
947
        tree.commit('2nd commit', rev_id=rev_id2_utf8)
895
948
        tree.unlock()
896
949
 
897
 
        response = request.execute(backing.local_abspath(''))
 
950
        response = request.execute('')
898
951
        self.assertEqual(None, response)
899
952
        response = request.do_body("%s\n%s\n1" % (rev_id2_utf8, rev_id1_utf8))
900
953
        self.assertEqual(('ok',), response.args)
901
 
        from cStringIO import StringIO
902
954
        parser = pack.ContainerPushParser()
903
955
        names = []
904
956
        for stream_bytes in response.body_stream:
916
968
            backing)
917
969
        repo = self.make_repository('.')
918
970
        rev_id1_utf8 = u'\xc8'.encode('utf-8')
919
 
        response = request.execute(backing.local_abspath(''))
 
971
        response = request.execute('')
920
972
        self.assertEqual(None, response)
921
973
        response = request.do_body("%s\n\n1" % (rev_id1_utf8,))
922
974
        self.assertEqual(
924
976
            response)
925
977
 
926
978
 
927
 
class TestSmartServerIsReadonly(tests.TestCaseWithTransport):
 
979
class TestSmartServerIsReadonly(tests.TestCaseWithMemoryTransport):
928
980
 
929
981
    def test_is_readonly_no(self):
930
982
        backing = self.get_transport()