~abentley/bzrtools/bzrtools.dev

711 by Aaron Bentley
Implement create-mirror command
1
from bzrlib import revision, transform
2
from bzrlib.tests import TestCaseWithTransport
3
4
from bzrlib.plugins.bzrtools.mirror import create_mirror
5
6
class TestMirror(TestCaseWithTransport):
7
8
    def commit_transform(self, branch, tt):
9
        base_revno, base_revision = branch.last_revision_info()
10
        if base_revision == revision.NULL_REVISION:
11
            parents = []
12
        else:
13
            parents = [base_revision]
14
        preview = tt.get_preview_tree()
15
        preview.set_parent_ids(parents)
16
        changes = tt.iter_changes()
17
        builder = branch.get_commit_builder(parents)
18
        try:
19
            list(builder.record_iter_changes(preview, base_revision, changes))
20
            builder.finish_inventory()
21
            revision_id = builder.commit('message')
22
        except:
23
            builder.abort()
24
            raise
25
        branch.set_last_revision_info(base_revno + 1, revision_id)
26
27
    def make_transform(self, branch):
28
        base = branch.basis_tree()
29
        tt = transform.TransformPreview(base)
30
        self.addCleanup(tt.finalize)
31
        root = tt.new_directory('', transform.ROOT_PARENT, 'root-id')
32
        tt._new_root = root
33
        return tt
34
35
    def test_create_mirror(self):
36
        source = self.make_branch('source')
37
        source.lock_write()
38
        self.addCleanup(source.unlock)
39
        source.nick = 'my special nick'
712 by Aaron Bentley
Copy submit branch in create_mirror.
40
        source.set_submit_branch(':submit:')
711 by Aaron Bentley
Implement create-mirror command
41
        self.commit_transform(source, self.make_transform(source))
42
        mirror = create_mirror(source, 'target', [])
43
        self.assertEqual(source.last_revision(), mirror.last_revision())
44
        self.assertEqual(source.base, mirror.get_public_branch())
45
        self.assertEqual(source.base, mirror.get_parent())
46
        self.assertEqual('my special nick', mirror.nick)
712 by Aaron Bentley
Copy submit branch in create_mirror.
47
        self.assertEqual(':submit:', mirror.get_submit_branch())
711 by Aaron Bentley
Implement create-mirror command
48
49
    def test_nonexplict_nick(self):
50
        source = self.make_branch('source')
51
        mirror = create_mirror(source, 'target', [])
52
        self.assertEqual('target', mirror.nick)