~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Robert Collins
  • Date: 2008-04-04 00:02:23 UTC
  • mfrom: (3331 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3332.
  • Revision ID: robertc@robertcollins.net-20080404000223-m270i246sp9uatmt
Fix conflicts.

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)
 
482
        tests.TestCaseWithMemoryTransport.setUp(self)
427
483
 
428
484
    def test_lock_write_on_unlocked_branch(self):
429
485
        backing = self.get_transport()
430
486
        request = smart.branch.SmartServerBranchRequestLockWrite(backing)
431
487
        branch = self.make_branch('.', format='knit')
432
488
        repository = branch.repository
433
 
        response = request.execute(backing.local_abspath(''))
 
489
        response = request.execute('')
434
490
        branch_nonce = branch.control_files._lock.peek().get('nonce')
435
491
        repository_nonce = repository.control_files._lock.peek().get('nonce')
436
492
        self.assertEqual(
448
504
        branch.lock_write()
449
505
        branch.leave_lock_in_place()
450
506
        branch.unlock()
451
 
        response = request.execute(backing.local_abspath(''))
 
507
        response = request.execute('')
452
508
        self.assertEqual(
453
509
            SmartServerResponse(('LockContention',)), response)
454
510
 
462
518
        branch.leave_lock_in_place()
463
519
        branch.repository.leave_lock_in_place()
464
520
        branch.unlock()
465
 
        response = request.execute(backing.local_abspath(''),
 
521
        response = request.execute('',
466
522
                                   branch_token, repo_token)
467
523
        self.assertEqual(
468
524
            SmartServerResponse(('ok', branch_token, repo_token)), response)
477
533
        branch.leave_lock_in_place()
478
534
        branch.repository.leave_lock_in_place()
479
535
        branch.unlock()
480
 
        response = request.execute(backing.local_abspath(''),
 
536
        response = request.execute('',
481
537
                                   branch_token+'xxx', repo_token)
482
538
        self.assertEqual(
483
539
            SmartServerResponse(('TokenMismatch',)), response)
489
545
        branch.repository.lock_write()
490
546
        branch.repository.leave_lock_in_place()
491
547
        branch.repository.unlock()
492
 
        response = request.execute(backing.local_abspath(''))
 
548
        response = request.execute('')
493
549
        self.assertEqual(
494
550
            SmartServerResponse(('LockContention',)), response)
495
551
 
497
553
        backing = self.get_readonly_transport()
498
554
        request = smart.branch.SmartServerBranchRequestLockWrite(backing)
499
555
        branch = self.make_branch('.')
500
 
        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)
501
559
        error_name, lock_str, why_str = response.args
502
560
        self.assertFalse(response.is_successful())
503
561
        self.assertEqual('LockFailed', error_name)
504
562
 
505
563
 
506
 
class TestSmartServerBranchRequestUnlock(tests.TestCaseWithTransport):
 
564
class TestSmartServerBranchRequestUnlock(tests.TestCaseWithMemoryTransport):
507
565
 
508
566
    def setUp(self):
509
 
        tests.TestCaseWithTransport.setUp(self)
 
567
        tests.TestCaseWithMemoryTransport.setUp(self)
510
568
 
511
569
    def test_unlock_on_locked_branch_and_repo(self):
512
570
        backing = self.get_transport()
521
579
        branch.leave_lock_in_place()
522
580
        branch.repository.leave_lock_in_place()
523
581
        branch.unlock()
524
 
        response = request.execute(backing.local_abspath(''),
 
582
        response = request.execute('',
525
583
                                   branch_token, repo_token)
526
584
        self.assertEqual(
527
585
            SmartServerResponse(('ok',)), response)
536
594
        request = smart.branch.SmartServerBranchRequestUnlock(backing)
537
595
        branch = self.make_branch('.', format='knit')
538
596
        response = request.execute(
539
 
            backing.local_abspath(''), 'branch token', 'repo token')
 
597
            '', 'branch token', 'repo token')
540
598
        self.assertEqual(
541
599
            SmartServerResponse(('TokenMismatch',)), response)
542
600
 
551
609
        # Issue branch lock_write request on the unlocked branch (with locked
552
610
        # repo).
553
611
        response = request.execute(
554
 
            backing.local_abspath(''), 'branch token', repo_token)
 
612
            '', 'branch token', repo_token)
555
613
        self.assertEqual(
556
614
            SmartServerResponse(('TokenMismatch',)), response)
557
615
 
558
616
 
559
 
class TestSmartServerRepositoryRequest(tests.TestCaseWithTransport):
 
617
class TestSmartServerRepositoryRequest(tests.TestCaseWithMemoryTransport):
560
618
 
561
619
    def test_no_repository(self):
562
620
        """Raise NoRepositoryPresent when there is a bzrdir and no repo."""
569
627
        self.make_repository('.', shared=True)
570
628
        self.make_bzrdir('subdir')
571
629
        self.assertRaises(errors.NoRepositoryPresent,
572
 
            request.execute, backing.local_abspath('subdir'))
 
630
            request.execute, 'subdir')
573
631
 
574
632
 
575
633
class TestSmartServerRepositoryGetParentMap(tests.TestCaseWithTransport):
581
639
        tree = self.make_branch_and_memory_tree('.')
582
640
 
583
641
        self.assertEqual(None,
584
 
            request.execute(backing.local_abspath(''), 'missing-id'))
 
642
            request.execute('', 'missing-id'))
585
643
        # Note that it returns a body (of '' bzipped).
586
644
        self.assertEqual(
587
645
            SuccessfulSmartServerResponse(('ok', ), bz2.compress('')),
588
646
            request.do_body('\n\n0\n'))
589
647
 
590
648
 
591
 
class TestSmartServerRepositoryGetRevisionGraph(tests.TestCaseWithTransport):
 
649
class TestSmartServerRepositoryGetRevisionGraph(tests.TestCaseWithMemoryTransport):
592
650
 
593
651
    def test_none_argument(self):
594
652
        backing = self.get_transport()
603
661
        # the lines of revision_id->revision_parent_list has no guaranteed
604
662
        # order coming out of a dict, so sort both our test and response
605
663
        lines = sorted([' '.join([r2, r1]), r1])
606
 
        response = request.execute(backing.local_abspath(''), '')
 
664
        response = request.execute('', '')
607
665
        response.body = '\n'.join(sorted(response.body.split('\n')))
608
666
 
609
667
        self.assertEqual(
621
679
        tree.unlock()
622
680
 
623
681
        self.assertEqual(SmartServerResponse(('ok', ), rev_id_utf8),
624
 
            request.execute(backing.local_abspath(''), rev_id_utf8))
 
682
            request.execute('', rev_id_utf8))
625
683
    
626
684
    def test_no_such_revision(self):
627
685
        backing = self.get_transport()
635
693
        # Note that it still returns body (of zero bytes).
636
694
        self.assertEqual(
637
695
            SmartServerResponse(('nosuchrevision', 'missingrevision', ), ''),
638
 
            request.execute(backing.local_abspath(''), 'missingrevision'))
639
 
 
640
 
 
641
 
class TestSmartServerRequestHasRevision(tests.TestCaseWithTransport):
 
696
            request.execute('', 'missingrevision'))
 
697
 
 
698
 
 
699
class TestSmartServerRequestHasRevision(tests.TestCaseWithMemoryTransport):
642
700
 
643
701
    def test_missing_revision(self):
644
702
        """For a missing revision, ('no', ) is returned."""
646
704
        request = smart.repository.SmartServerRequestHasRevision(backing)
647
705
        self.make_repository('.')
648
706
        self.assertEqual(SmartServerResponse(('no', )),
649
 
            request.execute(backing.local_abspath(''), 'revid'))
 
707
            request.execute('', 'revid'))
650
708
 
651
709
    def test_present_revision(self):
652
710
        """For a present revision, ('yes', ) is returned."""
660
718
        tree.unlock()
661
719
        self.assertTrue(tree.branch.repository.has_revision(rev_id_utf8))
662
720
        self.assertEqual(SmartServerResponse(('yes', )),
663
 
            request.execute(backing.local_abspath(''), rev_id_utf8))
664
 
 
665
 
 
666
 
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithTransport):
 
721
            request.execute('', rev_id_utf8))
 
722
 
 
723
 
 
724
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithMemoryTransport):
667
725
 
668
726
    def test_empty_revid(self):
669
727
        """With an empty revid, we get only size an number and revisions"""
674
732
        size = stats['size']
675
733
        expected_body = 'revisions: 0\nsize: %d\n' % size
676
734
        self.assertEqual(SmartServerResponse(('ok', ), expected_body),
677
 
                         request.execute(backing.local_abspath(''), '', 'no'))
 
735
                         request.execute('', '', 'no'))
678
736
 
679
737
    def test_revid_with_committers(self):
680
738
        """For a revid we get more infos."""
697
755
                         'revisions: 2\n'
698
756
                         'size: %d\n' % size)
699
757
        self.assertEqual(SmartServerResponse(('ok', ), expected_body),
700
 
                         request.execute(backing.local_abspath(''),
 
758
                         request.execute('',
701
759
                                         rev_id_utf8, 'no'))
702
760
 
703
761
    def test_not_empty_repository_with_committers(self):
723
781
                         'revisions: 2\n'
724
782
                         'size: %d\n' % size)
725
783
        self.assertEqual(SmartServerResponse(('ok', ), expected_body),
726
 
                         request.execute(backing.local_abspath(''),
 
784
                         request.execute('',
727
785
                                         rev_id_utf8, 'yes'))
728
786
 
729
787
 
730
 
class TestSmartServerRepositoryIsShared(tests.TestCaseWithTransport):
 
788
class TestSmartServerRepositoryIsShared(tests.TestCaseWithMemoryTransport):
731
789
 
732
790
    def test_is_shared(self):
733
791
        """For a shared repository, ('yes', ) is returned."""
735
793
        request = smart.repository.SmartServerRepositoryIsShared(backing)
736
794
        self.make_repository('.', shared=True)
737
795
        self.assertEqual(SmartServerResponse(('yes', )),
738
 
            request.execute(backing.local_abspath(''), ))
 
796
            request.execute('', ))
739
797
 
740
798
    def test_is_not_shared(self):
741
799
        """For a shared repository, ('no', ) is returned."""
743
801
        request = smart.repository.SmartServerRepositoryIsShared(backing)
744
802
        self.make_repository('.', shared=False)
745
803
        self.assertEqual(SmartServerResponse(('no', )),
746
 
            request.execute(backing.local_abspath(''), ))
747
 
 
748
 
 
749
 
class TestSmartServerRepositoryLockWrite(tests.TestCaseWithTransport):
 
804
            request.execute('', ))
 
805
 
 
806
 
 
807
class TestSmartServerRepositoryLockWrite(tests.TestCaseWithMemoryTransport):
750
808
 
751
809
    def setUp(self):
752
 
        tests.TestCaseWithTransport.setUp(self)
 
810
        tests.TestCaseWithMemoryTransport.setUp(self)
753
811
 
754
812
    def test_lock_write_on_unlocked_repo(self):
755
813
        backing = self.get_transport()
756
814
        request = smart.repository.SmartServerRepositoryLockWrite(backing)
757
815
        repository = self.make_repository('.', format='knit')
758
 
        response = request.execute(backing.local_abspath(''))
 
816
        response = request.execute('')
759
817
        nonce = repository.control_files._lock.peek().get('nonce')
760
818
        self.assertEqual(SmartServerResponse(('ok', nonce)), response)
761
819
        # The repository is now locked.  Verify that with a new repository
770
828
        repository.lock_write()
771
829
        repository.leave_lock_in_place()
772
830
        repository.unlock()
773
 
        response = request.execute(backing.local_abspath(''))
 
831
        response = request.execute('')
774
832
        self.assertEqual(
775
833
            SmartServerResponse(('LockContention',)), response)
776
834
 
783
841
        self.assertEqual('LockFailed', response.args[0])
784
842
 
785
843
 
786
 
class TestSmartServerRepositoryUnlock(tests.TestCaseWithTransport):
 
844
class TestSmartServerRepositoryUnlock(tests.TestCaseWithMemoryTransport):
787
845
 
788
846
    def setUp(self):
789
 
        tests.TestCaseWithTransport.setUp(self)
 
847
        tests.TestCaseWithMemoryTransport.setUp(self)
790
848
 
791
849
    def test_unlock_on_locked_repo(self):
792
850
        backing = self.get_transport()
795
853
        token = repository.lock_write()
796
854
        repository.leave_lock_in_place()
797
855
        repository.unlock()
798
 
        response = request.execute(backing.local_abspath(''), token)
 
856
        response = request.execute('', token)
799
857
        self.assertEqual(
800
858
            SmartServerResponse(('ok',)), response)
801
859
        # The repository is now unlocked.  Verify that with a new repository
808
866
        backing = self.get_transport()
809
867
        request = smart.repository.SmartServerRepositoryUnlock(backing)
810
868
        repository = self.make_repository('.', format='knit')
811
 
        response = request.execute(backing.local_abspath(''), 'some token')
 
869
        response = request.execute('', 'some token')
812
870
        self.assertEqual(
813
871
            SmartServerResponse(('TokenMismatch',)), response)
814
872
 
822
880
        # make some extraneous junk in the repository directory which should
823
881
        # not be copied
824
882
        self.build_tree(['.bzr/repository/extra-junk'])
825
 
        response = request.execute(backing.local_abspath(''), 'bz2')
 
883
        response = request.execute('', 'bz2')
826
884
        self.assertEqual(('ok',), response.args)
827
885
        # body should be a tbz2
828
886
        body_file = StringIO(response.body)
837
895
            "extraneous file present in tar file")
838
896
 
839
897
 
840
 
class TestSmartServerRepositoryStreamKnitData(tests.TestCaseWithTransport):
 
898
class TestSmartServerRepositoryStreamKnitData(tests.TestCaseWithMemoryTransport):
841
899
 
842
900
    def test_fetch_revisions(self):
843
901
        backing = self.get_transport()
851
909
        r1 = tree.commit('2nd commit', rev_id=rev_id2_utf8)
852
910
        tree.unlock()
853
911
 
854
 
        response = request.execute(backing.local_abspath(''), rev_id2_utf8)
 
912
        response = request.execute('', rev_id2_utf8)
855
913
        self.assertEqual(('ok',), response.args)
856
 
        from cStringIO import StringIO
857
914
        unpacker = pack.ContainerReader(StringIO(response.body))
858
915
        names = []
859
916
        for [name], read_bytes in unpacker.iter_records():
869
926
        request = smart.repository.SmartServerRepositoryStreamKnitDataForRevisions(backing)
870
927
        repo = self.make_repository('.')
871
928
        rev_id1_utf8 = u'\xc8'.encode('utf-8')
872
 
        response = request.execute(backing.local_abspath(''), rev_id1_utf8)
 
929
        response = request.execute('', rev_id1_utf8)
873
930
        self.assertEqual(
874
931
            SmartServerResponse(('NoSuchRevision', rev_id1_utf8)),
875
932
            response)
876
933
 
877
934
 
878
 
class TestSmartServerRepositoryStreamRevisionsChunked(tests.TestCaseWithTransport):
 
935
class TestSmartServerRepositoryStreamRevisionsChunked(tests.TestCaseWithMemoryTransport):
879
936
 
880
937
    def test_fetch_revisions(self):
881
938
        backing = self.get_transport()
890
947
        tree.commit('2nd commit', rev_id=rev_id2_utf8)
891
948
        tree.unlock()
892
949
 
893
 
        response = request.execute(backing.local_abspath(''))
 
950
        response = request.execute('')
894
951
        self.assertEqual(None, response)
895
952
        response = request.do_body("%s\n%s\n1" % (rev_id2_utf8, rev_id1_utf8))
896
953
        self.assertEqual(('ok',), response.args)
897
 
        from cStringIO import StringIO
898
954
        parser = pack.ContainerPushParser()
899
955
        names = []
900
956
        for stream_bytes in response.body_stream:
912
968
            backing)
913
969
        repo = self.make_repository('.')
914
970
        rev_id1_utf8 = u'\xc8'.encode('utf-8')
915
 
        response = request.execute(backing.local_abspath(''))
 
971
        response = request.execute('')
916
972
        self.assertEqual(None, response)
917
973
        response = request.do_body("%s\n\n1" % (rev_id1_utf8,))
918
974
        self.assertEqual(
920
976
            response)
921
977
 
922
978
 
923
 
class TestSmartServerIsReadonly(tests.TestCaseWithTransport):
 
979
class TestSmartServerIsReadonly(tests.TestCaseWithMemoryTransport):
924
980
 
925
981
    def test_is_readonly_no(self):
926
982
        backing = self.get_transport()