~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Martin Packman
  • Date: 2011-12-08 19:00:14 UTC
  • mto: This revision was merged to the branch mainline in revision 6359.
  • Revision ID: martin.packman@canonical.com-20111208190014-mi8jm6v7jygmhb0r
Use --include-duplicates for make update-pot which already combines multiple msgid strings prettily

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
28
28
import zlib
29
29
 
30
30
from bzrlib import (
31
 
    bencode,
32
31
    branch as _mod_branch,
33
32
    bzrdir,
34
33
    errors,
35
34
    gpg,
36
 
    inventory_delta,
37
35
    tests,
38
36
    transport,
39
37
    urlutils,
226
224
        self.assertEqual(expected, request.execute('', 'False'))
227
225
 
228
226
 
229
 
class TestSmartServerBzrDirRequestCloningMetaDir(
230
 
    tests.TestCaseWithMemoryTransport):
231
 
    """Tests for BzrDir.checkout_metadir."""
232
 
 
233
 
    def test_checkout_metadir(self):
234
 
        backing = self.get_transport()
235
 
        request = smart_dir.SmartServerBzrDirRequestCheckoutMetaDir(
236
 
            backing)
237
 
        branch = self.make_branch('.', format='2a')
238
 
        response = request.execute('')
239
 
        self.assertEqual(
240
 
            smart_req.SmartServerResponse(
241
 
                ('Bazaar-NG meta directory, format 1\n',
242
 
                 'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
243
 
                 'Bazaar Branch Format 7 (needs bzr 1.6)\n')),
244
 
            response)
245
 
 
246
 
 
247
227
class TestSmartServerBzrDirRequestDestroyBranch(
248
228
    tests.TestCaseWithMemoryTransport):
249
229
    """Tests for BzrDir.destroy_branch."""
419
399
        backing = self.get_transport()
420
400
        request = self._request_class(backing)
421
401
        result = self._make_repository_and_result(
422
 
            format='development-subtree')
 
402
            format='dirstate-with-subtree')
423
403
        # check the test will be valid
424
404
        self.assertEqual('yes', result.args[2])
425
405
        self.assertEqual('yes', result.args[3])
430
410
        backing = self.get_transport()
431
411
        request = self._request_class(backing)
432
412
        result = self._make_repository_and_result(
433
 
            format='development-subtree')
 
413
            format='dirstate-with-subtree')
434
414
        # check the test will be valid
435
 
        self.assertEqual('yes', result.args[4])
 
415
        self.assertEqual('no', result.args[4])
436
416
        self.assertEqual(result, request.execute(''))
437
417
 
438
418
 
459
439
        self.assertEqual(expected, request.execute(''))
460
440
 
461
441
 
462
 
class TestSmartServerBzrDirRequestGetBranches(
463
 
    tests.TestCaseWithMemoryTransport):
464
 
    """Tests for BzrDir.get_branches."""
465
 
 
466
 
    def test_simple(self):
467
 
        backing = self.get_transport()
468
 
        branch = self.make_branch('.')
469
 
        request_class = smart_dir.SmartServerBzrDirRequestGetBranches
470
 
        request = request_class(backing)
471
 
        local_result = bencode.bencode(
472
 
            {"": ("branch", branch._format.network_name())})
473
 
        expected = smart_req.SuccessfulSmartServerResponse(
474
 
            ("success", ), local_result)
475
 
        self.assertEqual(expected, request.execute(''))
476
 
 
477
 
    def test_empty(self):
478
 
        backing = self.get_transport()
479
 
        dir = self.make_bzrdir('.')
480
 
        request_class = smart_dir.SmartServerBzrDirRequestGetBranches
481
 
        request = request_class(backing)
482
 
        local_result = bencode.bencode({})
483
 
        expected = smart_req.SuccessfulSmartServerResponse(
484
 
            ('success',), local_result)
485
 
        self.assertEqual(expected, request.execute(''))
486
 
 
487
 
 
488
442
class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithMemoryTransport):
489
443
 
490
444
    def test_empty_dir(self):
512
466
        backing = self.get_transport()
513
467
        request = smart_dir.SmartServerRequestInitializeBzrDir(backing)
514
468
        self.make_bzrdir('subdir')
515
 
        self.assertRaises(errors.AlreadyControlDirError,
 
469
        self.assertRaises(errors.FileExists,
516
470
            request.execute, 'subdir')
517
471
 
518
472
 
1323
1277
        finally:
1324
1278
            branch.unlock()
1325
1279
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
1326
 
        # Refresh branch as SetParentLocation modified it
1327
 
        branch = branch.bzrdir.open_branch()
1328
1280
        self.assertEqual(None, branch.get_parent())
1329
1281
 
1330
1282
    def test_set_parent_something(self):
1334
1286
        branch_token, repo_token = self.get_lock_tokens(branch)
1335
1287
        try:
1336
1288
            response = request.execute('base', branch_token, repo_token,
1337
 
                                       'http://bar/')
 
1289
            'http://bar/')
1338
1290
        finally:
1339
1291
            branch.unlock()
1340
1292
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
1341
 
        refreshed = _mod_branch.Branch.open(branch.base)
1342
 
        self.assertEqual('http://bar/', refreshed.get_parent())
 
1293
        self.assertEqual('http://bar/', branch.get_parent())
1343
1294
 
1344
1295
 
1345
1296
class TestSmartServerBranchRequestGetTagsBytes(
2257
2208
            request.execute('', ))
2258
2209
 
2259
2210
 
2260
 
class TestSmartServerRepositoryReconcile(tests.TestCaseWithTransport):
2261
 
 
2262
 
    def test_reconcile(self):
2263
 
        backing = self.get_transport()
2264
 
        repo = self.make_repository('.')
2265
 
        token = repo.lock_write().repository_token
2266
 
        self.addCleanup(repo.unlock)
2267
 
        request_class = smart_repo.SmartServerRepositoryReconcile
2268
 
        request = request_class(backing)
2269
 
        self.assertEqual(smart_req.SuccessfulSmartServerResponse(
2270
 
            ('ok', ),
2271
 
             'garbage_inventories: 0\n'
2272
 
             'inconsistent_parents: 0\n'),
2273
 
            request.execute('', token))
2274
 
 
2275
 
 
2276
2211
class TestSmartServerIsReadonly(tests.TestCaseWithMemoryTransport):
2277
2212
 
2278
2213
    def test_is_readonly_no(self):
2526
2461
            smart_dir.SmartServerRequestInitializeBzrDir)
2527
2462
        self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
2528
2463
            smart_dir.SmartServerRequestBzrDirInitializeEx)
2529
 
        self.assertHandlerEqual('BzrDir.checkout_metadir',
2530
 
            smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
2531
2464
        self.assertHandlerEqual('BzrDir.cloning_metadir',
2532
2465
            smart_dir.SmartServerBzrDirRequestCloningMetaDir)
2533
 
        self.assertHandlerEqual('BzrDir.get_branches',
2534
 
            smart_dir.SmartServerBzrDirRequestGetBranches)
2535
2466
        self.assertHandlerEqual('BzrDir.get_config_file',
2536
2467
            smart_dir.SmartServerBzrDirRequestConfigFile)
2537
2468
        self.assertHandlerEqual('BzrDir.open_branch',
2582
2513
            smart_repo.SmartServerRepositoryMakeWorkingTrees)
2583
2514
        self.assertHandlerEqual('Repository.pack',
2584
2515
            smart_repo.SmartServerRepositoryPack)
2585
 
        self.assertHandlerEqual('Repository.reconcile',
2586
 
            smart_repo.SmartServerRepositoryReconcile)
2587
2516
        self.assertHandlerEqual('Repository.tarball',
2588
2517
            smart_repo.SmartServerRepositoryTarball)
2589
2518
        self.assertHandlerEqual('Repository.unlock',
2598
2527
            smart_repo.SmartServerRepositoryAbortWriteGroup)
2599
2528
        self.assertHandlerEqual('VersionedFileRepository.get_serializer_format',
2600
2529
            smart_repo.SmartServerRepositoryGetSerializerFormat)
2601
 
        self.assertHandlerEqual('VersionedFileRepository.get_inventories',
2602
 
            smart_repo.SmartServerRepositoryGetInventories)
2603
2530
        self.assertHandlerEqual('Transport.is_readonly',
2604
2531
            smart_req.SmartServerIsReadonly)
2605
2532
 
2665
2592
            smart_req.SuccessfulSmartServerResponse(('ok', ), ),
2666
2593
            request.do_body(''))
2667
2594
 
2668
 
 
2669
 
class TestSmartServerRepositoryGetInventories(tests.TestCaseWithTransport):
2670
 
 
2671
 
    def _get_serialized_inventory_delta(self, repository, base_revid, revid):
2672
 
        base_inv = repository.revision_tree(base_revid).root_inventory
2673
 
        inv = repository.revision_tree(revid).root_inventory
2674
 
        inv_delta = inv._make_delta(base_inv)
2675
 
        serializer = inventory_delta.InventoryDeltaSerializer(True, False)
2676
 
        return "".join(serializer.delta_to_lines(base_revid, revid, inv_delta))
2677
 
 
2678
 
    def test_single(self):
2679
 
        backing = self.get_transport()
2680
 
        request = smart_repo.SmartServerRepositoryGetInventories(backing)
2681
 
        t = self.make_branch_and_tree('.', format='2a')
2682
 
        self.addCleanup(t.lock_write().unlock)
2683
 
        self.build_tree_contents([("file", "somecontents")])
2684
 
        t.add(["file"], ["thefileid"])
2685
 
        t.commit(rev_id='somerev', message="add file")
2686
 
        self.assertIs(None, request.execute('', 'unordered'))
2687
 
        response = request.do_body("somerev\n")
2688
 
        self.assertTrue(response.is_successful())
2689
 
        self.assertEquals(response.args, ("ok", ))
2690
 
        stream = [('inventory-deltas', [
2691
 
            versionedfile.FulltextContentFactory('somerev', None, None,
2692
 
                self._get_serialized_inventory_delta(
2693
 
                    t.branch.repository, 'null:', 'somerev'))])]
2694
 
        fmt = bzrdir.format_registry.get('2a')().repository_format
2695
 
        self.assertEquals(
2696
 
            "".join(response.body_stream),
2697
 
            "".join(smart_repo._stream_to_byte_stream(stream, fmt)))
2698
 
 
2699
 
    def test_empty(self):
2700
 
        backing = self.get_transport()
2701
 
        request = smart_repo.SmartServerRepositoryGetInventories(backing)
2702
 
        t = self.make_branch_and_tree('.', format='2a')
2703
 
        self.addCleanup(t.lock_write().unlock)
2704
 
        self.build_tree_contents([("file", "somecontents")])
2705
 
        t.add(["file"], ["thefileid"])
2706
 
        t.commit(rev_id='somerev', message="add file")
2707
 
        self.assertIs(None, request.execute('', 'unordered'))
2708
 
        response = request.do_body("")
2709
 
        self.assertTrue(response.is_successful())
2710
 
        self.assertEquals(response.args, ("ok", ))
2711
 
        self.assertEquals("".join(response.body_stream),
2712
 
            "Bazaar pack format 1 (introduced in 0.18)\nB54\n\nBazaar repository format 2a (needs bzr 1.16 or later)\nE")