/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
1
#!/usr/bin/env python
2
# vim: expandtab
3
4
# Copyright (C) 2011 Jelmer Vernooij <jelmer@apache.org>
5
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
20
from cStringIO import StringIO
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
21
import os
22
0.200.1586 by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper.
23
from dulwich.repo import Repo
24
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
25
from ....tests import (
0.200.1582 by Jelmer Vernooij
Print error when bzr-fastimport is not installed.
26
    TestCaseWithTransport,
27
    TestSkipped,
28
    )
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
29
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
30
from ..object_store import get_object_store
31
from ..git_remote_helper import (
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
32
    RemoteHelper,
33
    open_local_dir,
0.200.1582 by Jelmer Vernooij
Print error when bzr-fastimport is not installed.
34
    fastexporter,
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
35
    fetch,
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
36
    )
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
37
38
0.200.1586 by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper.
39
def map_to_git_sha1(dir, bzr_revid):
40
    object_store = get_object_store(dir.open_repository())
0.200.1788 by Jelmer Vernooij
Use context managers.
41
    with object_store.lock_read():
0.200.1586 by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper.
42
        return object_store._lookup_revision_sha1(bzr_revid)
43
44
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
45
class OpenLocalDirTests(TestCaseWithTransport):
46
47
    def test_from_env_dir(self):
48
        self.make_branch_and_tree('bla', format='git')
49
        self.overrideEnv('GIT_DIR', os.path.join(self.test_dir, 'bla', '.git'))
50
        open_local_dir()
51
52
    def test_from_dir(self):
53
        self.make_branch_and_tree('.', format='git')
54
        open_local_dir()
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
55
56
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
57
class FetchTests(TestCaseWithTransport):
58
59
    def setUp(self):
60
        super(FetchTests, self).setUp()
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
61
        self.local_dir = self.make_branch_and_tree('local', format='git').controldir
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
62
        self.remote_tree = self.make_branch_and_tree('remote')
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
63
        self.remote_dir = self.remote_tree.controldir
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
64
        self.shortname = 'bzr'
65
66
    def fetch(self, wants):
67
        outf = StringIO()
68
        fetch(outf, wants, self.shortname, self.remote_dir, self.local_dir)
69
        return outf.getvalue()
70
71
    def test_no_wants(self):
72
        r = self.fetch([])
73
        self.assertEquals("\n", r)
74
0.200.1586 by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper.
75
    def test_simple(self):
76
        self.build_tree(['remote/foo'])
77
        self.remote_tree.add("foo")
78
        revid = self.remote_tree.commit("msg")
79
        git_sha1 = map_to_git_sha1(self.remote_dir, revid)
80
        out = self.fetch([(git_sha1, 'HEAD')])
81
        self.assertEquals(out, "\n")
82
        r = Repo('local')
83
        self.assertTrue(git_sha1 in r.object_store)
0.310.9 by Jelmer Vernooij
Some controldir fixes.
84
        self.assertEquals({
85
            }, r.get_refs())
0.200.1586 by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper.
86
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
87
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
88
class RemoteHelperTests(TestCaseWithTransport):
89
90
    def setUp(self):
91
        super(RemoteHelperTests, self).setUp()
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
92
        self.local_dir = self.make_branch_and_tree('local', format='git').controldir
0.200.1581 by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests.
93
        self.remote_tree = self.make_branch_and_tree('remote')
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
94
        self.remote_dir = self.remote_tree.controldir
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
95
        self.shortname = 'bzr'
96
        self.helper = RemoteHelper(self.local_dir, self.shortname, self.remote_dir)
97
98
    def test_capabilities(self):
99
        f = StringIO()
100
        self.helper.cmd_capabilities(f, [])
101
        capabs = f.getvalue()
102
        base = "fetch\noption\npush\n"
103
        self.assertTrue(capabs in (base+"\n", base+"import\n\n"), capabs)
0.200.1517 by Jelmer Vernooij
Add test for option command in git-remote-helper.
104
105
    def test_option(self):
106
        f = StringIO()
107
        self.helper.cmd_option(f, [])
108
        self.assertEquals("unsupported\n", f.getvalue())
109
0.200.1518 by Jelmer Vernooij
Add basic test for list command.
110
    def test_list_basic(self):
111
        f = StringIO()
112
        self.helper.cmd_list(f, [])
113
        self.assertEquals(
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
114
            '0000000000000000000000000000000000000000 HEAD\n\n',
0.200.1518 by Jelmer Vernooij
Add basic test for list command.
115
            f.getvalue())
0.200.1581 by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests.
116
117
    def test_import(self):
0.200.1582 by Jelmer Vernooij
Print error when bzr-fastimport is not installed.
118
        if fastexporter is None:
119
            raise TestSkipped("bzr-fastimport not available")
0.200.1581 by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests.
120
        self.build_tree_contents([("remote/afile", "somecontent")])
121
        self.remote_tree.add(["afile"])
122
        self.remote_tree.commit("A commit message", timestamp=1330445983,
123
            timezone=0, committer='Somebody <jrandom@example.com>')
124
        f = StringIO()
125
        self.helper.cmd_import(f, ["import", "refs/heads/master"])
126
        self.assertEquals(
127
            'commit refs/heads/master\n'
128
            'mark :1\n'
129
            'committer Somebody <jrandom@example.com> 1330445983 +0000\n'
130
            'data 16\n'
131
            'A commit message\n'
132
            'M 644 inline afile\n'
133
            'data 11\n'
134
            'somecontent\n',
135
            f.getvalue())