/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1551.12.2 by Aaron Bentley
Got directives round-tripping, with bundles and everything
1
from bzrlib import (
2
    errors,
1551.12.16 by Aaron Bentley
Enable signing merge directives
3
    gpg,
1551.12.2 by Aaron Bentley
Got directives round-tripping, with bundles and everything
4
    merge_directive,
5
    tests,
6
    )
7
1551.12.4 by Aaron Bentley
Add failing test
8
1551.12.2 by Aaron Bentley
Got directives round-tripping, with bundles and everything
9
class TestMergeDirective(tests.TestCase):
10
11
    def test_init(self):
1551.12.3 by Aaron Bentley
Add timestamps to merge directives
12
        time = 500.0
13
        timezone = 5
14
        self.assertRaises(errors.NoMergeSource, merge_directive.MergeDirective,
15
            'example:', 'sha', time, timezone, 'http://example.com')
16
        self.assertRaises(errors.NoMergeSource, merge_directive.MergeDirective,
17
            'example:', 'sha', time, timezone, 'http://example.com',
18
            patch_type='diff')
19
        md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
1551.12.13 by Aaron Bentley
Rename fields
20
            'http://example.com', source_branch='http://example.org')
1551.12.2 by Aaron Bentley
Got directives round-tripping, with bundles and everything
21
        self.assertRaises(errors.PatchMissing, merge_directive.MergeDirective,
1551.12.3 by Aaron Bentley
Add timestamps to merge directives
22
            'example:', 'sha', time, timezone, 'http://example.com',
23
            patch_type='bundle')
24
        md = merge_directive.MergeDirective('null:', 'sha', time, timezone,
1551.12.2 by Aaron Bentley
Got directives round-tripping, with bundles and everything
25
            'http://example.com', patch='blah', patch_type='bundle')
26
        self.assertRaises(errors.PatchMissing, merge_directive.MergeDirective,
1551.12.6 by Aaron Bentley
Force times to be floats
27
            'example:', 'sha', time, timezone, 'http://example.com',
1551.12.13 by Aaron Bentley
Rename fields
28
            source_branch="http://example.org", patch_type='diff')
1551.12.3 by Aaron Bentley
Add timestamps to merge directives
29
        md = merge_directive.MergeDirective('example:', 'sha1', time, timezone,
1551.12.13 by Aaron Bentley
Rename fields
30
            'http://example.com', source_branch="http://example.org",
1551.12.2 by Aaron Bentley
Got directives round-tripping, with bundles and everything
31
            patch='', patch_type='diff')
32
33
    def test_serialization(self):
1551.12.3 by Aaron Bentley
Add timestamps to merge directives
34
        time = 500.23
35
        timezone = 60
36
        md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
1551.12.13 by Aaron Bentley
Rename fields
37
            'http://example.com', source_branch="http://example.org",
1551.12.2 by Aaron Bentley
Got directives round-tripping, with bundles and everything
38
            patch='booga', patch_type='diff')
39
        md2 = merge_directive.MergeDirective.from_lines(md.to_lines())
1551.12.5 by Aaron Bentley
Get MergeDirective.from_objects working
40
        self.assertEqual('example:', md2.revision_id)
1551.12.2 by Aaron Bentley
Got directives round-tripping, with bundles and everything
41
        self.assertEqual('sha', md2.testament_sha1)
1551.12.13 by Aaron Bentley
Rename fields
42
        self.assertEqual('http://example.com', md2.target_branch)
43
        self.assertEqual('http://example.org', md2.source_branch)
1551.12.3 by Aaron Bentley
Add timestamps to merge directives
44
        self.assertEqual(time, md2.time)
45
        self.assertEqual(timezone, md2.timezone)
1551.12.2 by Aaron Bentley
Got directives round-tripping, with bundles and everything
46
        self.assertEqual('diff', md2.patch_type)
47
        self.assertEqual('booga', md2.patch)
48
        md.patch = "# Bazaar revision bundle v0.9\n#\n"
49
        md3 = merge_directive.MergeDirective.from_lines(md.to_lines())
50
        self.assertEqual("# Bazaar revision bundle v0.9\n#\n", md3.patch)
51
        self.assertEqual("bundle", md3.patch_type)
1551.12.12 by Aaron Bentley
Add format header
52
        self.assertContainsRe(md3.to_lines()[0],
53
            '^# Bazaar merge directive format ')
1551.12.4 by Aaron Bentley
Add failing test
54
55
56
class TestMergeDirectiveBranch(tests.TestCaseWithTransport):
57
58
    def test_generate(self):
59
        tree_a = self.make_branch_and_tree('tree_a')
60
        self.build_tree_contents([('tree_a/file', 'content_a\ncontent_b\n')])
61
        tree_a.add('file')
62
        tree_a.commit('message', rev_id='rev1')
63
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
1551.12.5 by Aaron Bentley
Get MergeDirective.from_objects working
64
        branch_c = tree_a.bzrdir.sprout('branch_c').open_branch()
1551.12.4 by Aaron Bentley
Add failing test
65
        tree_b.commit('message', rev_id='rev2b')
66
        self.build_tree_contents([('tree_a/file', 'content_a\ncontent_c\n')])
67
        tree_a.commit('message', rev_id='rev2a')
1551.12.5 by Aaron Bentley
Get MergeDirective.from_objects working
68
        self.assertRaises(errors.PublicBranchOutOfDate,
69
            merge_directive.MergeDirective.from_objects,
70
            tree_a.branch.repository, 'rev2a', 500, 120, tree_b.branch.base,
71
            public_branch=branch_c)
72
        md1 = merge_directive.MergeDirective.from_objects(
1551.12.6 by Aaron Bentley
Force times to be floats
73
            tree_a.branch.repository, 'rev2a', 500.0, 120, tree_b.branch.base)
1551.12.5 by Aaron Bentley
Get MergeDirective.from_objects working
74
        self.assertContainsRe(md1.patch, 'Bazaar revision bundle')
75
        self.assertContainsRe(md1.patch, '\\+content_c')
76
        self.assertNotContainsRe(md1.patch, '\\+content_a')
77
        branch_c.pull(tree_a.branch)
78
        md2 = merge_directive.MergeDirective.from_objects(
1551.12.6 by Aaron Bentley
Force times to be floats
79
            tree_a.branch.repository, 'rev2a', 500.0, 120, tree_b.branch.base,
1551.12.5 by Aaron Bentley
Get MergeDirective.from_objects working
80
            patch_type='diff', public_branch=branch_c)
81
        self.assertNotContainsRe(md2.patch, 'Bazaar revision bundle')
82
        self.assertContainsRe(md1.patch, '\\+content_c')
83
        self.assertNotContainsRe(md1.patch, '\\+content_a')
84
        md3 = merge_directive.MergeDirective.from_objects(
1551.12.6 by Aaron Bentley
Force times to be floats
85
            tree_a.branch.repository, 'rev2a', 500.0, 120, tree_b.branch.base,
1551.12.5 by Aaron Bentley
Get MergeDirective.from_objects working
86
            patch_type=None, public_branch=branch_c)
1551.12.7 by Aaron Bentley
Fix use of public location/branch
87
        md3.to_lines()
1551.12.5 by Aaron Bentley
Get MergeDirective.from_objects working
88
        self.assertIs(None, md3.patch)
1551.12.16 by Aaron Bentley
Enable signing merge directives
89
90
    def test_signing(self):
91
        time = 500.23
92
        timezone = 60
93
        class FakeBranch(object):
94
            def get_config(self):
95
                return self
96
            def gpg_signing_command(self):
97
                return 'loopback'
98
        md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
99
            'http://example.com', source_branch="http://example.org",
100
            patch='booga', patch_type='diff')
101
        old_strategy = gpg.GPGStrategy
102
        gpg.GPGStrategy = gpg.LoopbackGPGStrategy
103
        try:
104
            signed = md.to_signed(FakeBranch())
105
        finally:
106
            gpg.GPGStrategy = old_strategy
107
        self.assertContainsRe(signed, '^-----BEGIN PSEUDO-SIGNED CONTENT')
108
        self.assertContainsRe(signed, 'example.org')
109
        self.assertContainsRe(signed, 'booga')