/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())
41
    object_store.lock_read()
42
    try:
43
        return object_store._lookup_revision_sha1(bzr_revid)
44
    finally:
45
        object_store.unlock()
46
47
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
48
class OpenLocalDirTests(TestCaseWithTransport):
49
50
    def test_from_env(self):
51
        self.make_branch_and_tree('bla', format='git')
52
        self.overrideEnv('GIT_DIR', os.path.join(self.test_dir, 'bla'))
53
        open_local_dir()
54
55
    def test_from_env_dir(self):
56
        self.make_branch_and_tree('bla', format='git')
57
        self.overrideEnv('GIT_DIR', os.path.join(self.test_dir, 'bla', '.git'))
58
        open_local_dir()
59
60
    def test_from_dir(self):
61
        self.make_branch_and_tree('.', format='git')
62
        open_local_dir()
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
63
64
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
65
class FetchTests(TestCaseWithTransport):
66
67
    def setUp(self):
68
        super(FetchTests, self).setUp()
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
69
        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.
70
        self.remote_tree = self.make_branch_and_tree('remote')
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
71
        self.remote_dir = self.remote_tree.controldir
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
72
        self.shortname = 'bzr'
73
74
    def fetch(self, wants):
75
        outf = StringIO()
76
        fetch(outf, wants, self.shortname, self.remote_dir, self.local_dir)
77
        return outf.getvalue()
78
79
    def test_no_wants(self):
80
        r = self.fetch([])
81
        self.assertEquals("\n", r)
82
0.200.1586 by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper.
83
    def test_simple(self):
84
        self.build_tree(['remote/foo'])
85
        self.remote_tree.add("foo")
86
        revid = self.remote_tree.commit("msg")
87
        git_sha1 = map_to_git_sha1(self.remote_dir, revid)
88
        out = self.fetch([(git_sha1, 'HEAD')])
89
        self.assertEquals(out, "\n")
90
        r = Repo('local')
91
        self.assertTrue(git_sha1 in r.object_store)
92
        self.assertEquals({'HEAD': '0000000000000000000000000000000000000000'}, r.get_refs())
93
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
94
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
95
class RemoteHelperTests(TestCaseWithTransport):
96
97
    def setUp(self):
98
        super(RemoteHelperTests, self).setUp()
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
99
        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.
100
        self.remote_tree = self.make_branch_and_tree('remote')
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
101
        self.remote_dir = self.remote_tree.controldir
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
102
        self.shortname = 'bzr'
103
        self.helper = RemoteHelper(self.local_dir, self.shortname, self.remote_dir)
104
105
    def test_capabilities(self):
106
        f = StringIO()
107
        self.helper.cmd_capabilities(f, [])
108
        capabs = f.getvalue()
109
        base = "fetch\noption\npush\n"
110
        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.
111
112
    def test_option(self):
113
        f = StringIO()
114
        self.helper.cmd_option(f, [])
115
        self.assertEquals("unsupported\n", f.getvalue())
116
0.200.1518 by Jelmer Vernooij
Add basic test for list command.
117
    def test_list_basic(self):
118
        f = StringIO()
119
        self.helper.cmd_list(f, [])
120
        self.assertEquals(
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
121
            '0000000000000000000000000000000000000000 HEAD\n\n',
0.200.1518 by Jelmer Vernooij
Add basic test for list command.
122
            f.getvalue())
0.200.1581 by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests.
123
124
    def test_import(self):
0.200.1582 by Jelmer Vernooij
Print error when bzr-fastimport is not installed.
125
        if fastexporter is None:
126
            raise TestSkipped("bzr-fastimport not available")
0.200.1581 by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests.
127
        self.build_tree_contents([("remote/afile", "somecontent")])
128
        self.remote_tree.add(["afile"])
129
        self.remote_tree.commit("A commit message", timestamp=1330445983,
130
            timezone=0, committer='Somebody <jrandom@example.com>')
131
        f = StringIO()
132
        self.helper.cmd_import(f, ["import", "refs/heads/master"])
133
        self.assertEquals(
134
            'commit refs/heads/master\n'
135
            'mark :1\n'
136
            'committer Somebody <jrandom@example.com> 1330445983 +0000\n'
137
            'data 16\n'
138
            'A commit message\n'
139
            'M 644 inline afile\n'
140
            'data 11\n'
141
            'somecontent\n',
142
            f.getvalue())