/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
1
# Copyright (C) 2007 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for fetch between repositories of the same type."""
18
19
from bzrlib import (
20
    bzrdir,
21
    errors,
2696.3.10 by Martin Pool
Add missing import
22
    gpg,
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
23
    )
24
from bzrlib.tests import TestSkipped
25
from bzrlib.tests.repository_implementations import TestCaseWithRepository
26
from bzrlib.transport import get_transport
27
28
29
class TestFetchSameRepository(TestCaseWithRepository):
30
31
    def test_fetch(self):
32
        # smoke test fetch to ensure that the convenience function works.
33
        # it is defined as a convenience function with the underlying 
34
        # functionality provided by an InterRepository
35
        tree_a = self.make_branch_and_tree('a')
36
        self.build_tree(['a/foo'])
37
        tree_a.add('foo', 'file1')
38
        tree_a.commit('rev1', rev_id='rev1')
39
        # fetch with a default limit (grab everything)
2711.2.6 by Martin Pool
Fix up conversion of create_repository to make_repository in test_fetch
40
        repo = self.make_repository('b')
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
41
        if (tree_a.branch.repository.supports_rich_root() and not
42
            repo.supports_rich_root()):
43
            raise TestSkipped('Cannot fetch from model2 to model1')
44
        repo.fetch(tree_a.branch.repository,
45
                   revision_id=None)
46
                   ## pb=bzrlib.progress.DummyProgress())
47
48
    def test_fetch_knit3(self):
49
        # create a repository of the sort we are testing.
50
        tree_a = self.make_branch_and_tree('a', '')
51
        self.build_tree(['a/foo'])
52
        tree_a.add('foo', 'file1')
53
        tree_a.commit('rev1', rev_id='rev1')
54
        # create a knit-3 based format to fetch into
55
        f = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
56
        try:
57
            format = tree_a.branch.repository._format
58
            format.check_conversion_target(f.repository_format)
59
            # if we cannot convert data to knit3, skip the test.
60
        except errors.BadConversionTarget, e:
61
            raise TestSkipped(str(e))
62
        self.get_transport().mkdir('b')
63
        b_bzrdir = f.initialize(self.get_url('b'))
64
        knit3_repo = b_bzrdir.create_repository()
65
        # fetch with a default limit (grab everything)
66
        knit3_repo.fetch(tree_a.branch.repository, revision_id=None)
67
        rev1_tree = knit3_repo.revision_tree('rev1')
68
        lines = rev1_tree.get_file_lines(rev1_tree.inventory.root.file_id)
69
        self.assertEqual([], lines)
70
        b_branch = b_bzrdir.create_branch()
71
        b_branch.pull(tree_a.branch)
72
        try:
73
            tree_b = b_bzrdir.create_workingtree()
74
        except errors.NotLocalUrl:
75
            raise TestSkipped("cannot make working tree with transport %r"
76
                              % b_bzrdir.transport)
77
        tree_b.commit('no change', rev_id='rev2')
78
        rev2_tree = knit3_repo.revision_tree('rev2')
79
        self.assertEqual('rev1', rev2_tree.inventory.root.revision)
2696.3.9 by Martin Pool
merge trunk
80
81
    def makeARepoWithSignatures(self):
82
        wt = self.make_branch_and_tree('a-repo-with-sigs')
83
        wt.commit('rev1', allow_pointless=True, rev_id='rev1')
84
        repo = wt.branch.repository
2696.3.10 by Martin Pool
Add missing import
85
        repo.sign_revision('rev1', gpg.LoopbackGPGStrategy(None))
2696.3.9 by Martin Pool
merge trunk
86
        return repo
87
88
    def test_fetch_copies_signatures(self):
89
        source_repo = self.makeARepoWithSignatures()
90
        target_repo = self.make_repository('target')
91
        target_repo.fetch(source_repo, revision_id=None)
92
        self.assertEqual(
93
            source_repo.get_signature_text('rev1'),
94
            target_repo.get_signature_text('rev1'))