~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-06 22:44:57 UTC
  • mfrom: (6436 +trunk)
  • mto: (6437.3.11 2.5)
  • mto: This revision was merged to the branch mainline in revision 6444.
  • Revision ID: jelmer@samba.org-20120106224457-re0pcy0fz31xob77
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    bzrdir,
33
33
    errors,
34
34
    gpg,
 
35
    inventory_delta,
35
36
    tests,
36
37
    transport,
37
38
    urlutils,
224
225
        self.assertEqual(expected, request.execute('', 'False'))
225
226
 
226
227
 
 
228
class TestSmartServerBzrDirRequestCloningMetaDir(
 
229
    tests.TestCaseWithMemoryTransport):
 
230
    """Tests for BzrDir.checkout_metadir."""
 
231
 
 
232
    def test_checkout_metadir(self):
 
233
        backing = self.get_transport()
 
234
        request = smart_dir.SmartServerBzrDirRequestCheckoutMetaDir(
 
235
            backing)
 
236
        branch = self.make_branch('.', format='2a')
 
237
        response = request.execute('')
 
238
        self.assertEqual(
 
239
            smart_req.SmartServerResponse(
 
240
                ('Bazaar-NG meta directory, format 1\n',
 
241
                 'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
 
242
                 'Bazaar Branch Format 7 (needs bzr 1.6)\n')),
 
243
            response)
 
244
 
 
245
 
227
246
class TestSmartServerBzrDirRequestDestroyBranch(
228
247
    tests.TestCaseWithMemoryTransport):
229
248
    """Tests for BzrDir.destroy_branch."""
2477
2496
            smart_dir.SmartServerRequestInitializeBzrDir)
2478
2497
        self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
2479
2498
            smart_dir.SmartServerRequestBzrDirInitializeEx)
 
2499
        self.assertHandlerEqual('BzrDir.checkout_metadir',
 
2500
            smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
2480
2501
        self.assertHandlerEqual('BzrDir.cloning_metadir',
2481
2502
            smart_dir.SmartServerBzrDirRequestCloningMetaDir)
2482
2503
        self.assertHandlerEqual('BzrDir.get_config_file',
2545
2566
            smart_repo.SmartServerRepositoryAbortWriteGroup)
2546
2567
        self.assertHandlerEqual('VersionedFileRepository.get_serializer_format',
2547
2568
            smart_repo.SmartServerRepositoryGetSerializerFormat)
 
2569
        self.assertHandlerEqual('VersionedFileRepository.get_inventories',
 
2570
            smart_repo.SmartServerRepositoryGetInventories)
2548
2571
        self.assertHandlerEqual('Transport.is_readonly',
2549
2572
            smart_req.SmartServerIsReadonly)
2550
2573
 
2610
2633
            smart_req.SuccessfulSmartServerResponse(('ok', ), ),
2611
2634
            request.do_body(''))
2612
2635
 
 
2636
 
 
2637
class TestSmartServerRepositoryGetInventories(tests.TestCaseWithTransport):
 
2638
 
 
2639
    def _get_serialized_inventory_delta(self, repository, base_revid, revid):
 
2640
        base_inv = repository.revision_tree(base_revid).inventory
 
2641
        inv = repository.revision_tree(revid).inventory
 
2642
        inv_delta = inv._make_delta(base_inv)
 
2643
        serializer = inventory_delta.InventoryDeltaSerializer(True, False)
 
2644
        return "".join(serializer.delta_to_lines(base_revid, revid, inv_delta))
 
2645
 
 
2646
    def test_single(self):
 
2647
        backing = self.get_transport()
 
2648
        request = smart_repo.SmartServerRepositoryGetInventories(backing)
 
2649
        t = self.make_branch_and_tree('.', format='2a')
 
2650
        self.addCleanup(t.lock_write().unlock)
 
2651
        self.build_tree_contents([("file", "somecontents")])
 
2652
        t.add(["file"], ["thefileid"])
 
2653
        t.commit(rev_id='somerev', message="add file")
 
2654
        self.assertIs(None, request.execute('', 'unordered'))
 
2655
        response = request.do_body("somerev\n")
 
2656
        self.assertTrue(response.is_successful())
 
2657
        self.assertEquals(response.args, ("ok", ))
 
2658
        stream = [('inventory-deltas', [
 
2659
            versionedfile.FulltextContentFactory('somerev', None, None,
 
2660
                self._get_serialized_inventory_delta(
 
2661
                    t.branch.repository, 'null:', 'somerev'))])]
 
2662
        fmt = bzrdir.format_registry.get('2a')().repository_format
 
2663
        self.assertEquals(
 
2664
            "".join(response.body_stream),
 
2665
            "".join(smart_repo._stream_to_byte_stream(stream, fmt)))
 
2666
 
 
2667
    def test_empty(self):
 
2668
        backing = self.get_transport()
 
2669
        request = smart_repo.SmartServerRepositoryGetInventories(backing)
 
2670
        t = self.make_branch_and_tree('.', format='2a')
 
2671
        self.addCleanup(t.lock_write().unlock)
 
2672
        self.build_tree_contents([("file", "somecontents")])
 
2673
        t.add(["file"], ["thefileid"])
 
2674
        t.commit(rev_id='somerev', message="add file")
 
2675
        self.assertIs(None, request.execute('', 'unordered'))
 
2676
        response = request.do_body("")
 
2677
        self.assertTrue(response.is_successful())
 
2678
        self.assertEquals(response.args, ("ok", ))
 
2679
        self.assertEquals("".join(response.body_stream),
 
2680
            "Bazaar pack format 1 (introduced in 0.18)\nB54\n\nBazaar repository format 2a (needs bzr 1.16 or later)\nE")