~gagern/bzr-svn/bug242321

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

"""Remote access tests."""

from bzrlib import osutils
from bzrlib.branch import Branch
from bzrlib.bzrdir import BzrDir, format_registry
from bzrlib.errors import (NoRepositoryPresent, NotBranchError, NotLocalUrl,
                           NoWorkingTree, AlreadyBranchError)

import svn

from format import SvnRemoteFormat
from tests import TestCaseWithSubversionRepository
from transport import SvnRaTransport

class TestRemoteAccess(TestCaseWithSubversionRepository):
    def test_clone(self):
        repos_url = self.make_client("d", "dc")
        self.build_tree({"dc/foo": None})
        self.client_add("dc/foo")
        self.client_commit("dc", "msg")
        x = self.open_checkout_bzrdir("dc")
        self.assertRaises(NotImplementedError, x.clone, "dir")

    def test_open_workingtree(self):
        repos_url = self.make_client("d", "dc")
        x = BzrDir.open(repos_url)
        self.assertRaises(NoWorkingTree, x.open_workingtree)

    def test_open_workingtree_recommend_arg(self):
        repos_url = self.make_client("d", "dc")
        x = BzrDir.open(repos_url)
        self.assertRaises(NoWorkingTree, lambda: x.open_workingtree(recommend_upgrade=True))

    def test_create_workingtree(self):
        repos_url = self.make_client("d", "dc")
        x = BzrDir.open(repos_url)
        self.assertRaises(NotLocalUrl, x.create_workingtree)

    def test_create_branch_top(self):
        repos_url = self.make_client("d", "dc")
        x = BzrDir.open(repos_url)
        b = x.create_branch()
        self.assertEquals(repos_url, b.base)

    def test_create_branch_top_already_branch(self):
        repos_url = self.make_client("d", "dc")
        self.build_tree({'dc/bla': 'contents'})
        self.client_add("dc/bla")
        self.client_commit("dc", "message")
        x = BzrDir.open(repos_url)
        self.assertRaises(AlreadyBranchError, x.create_branch)

    def test_create_branch_nested(self):
        repos_url = self.make_client("d", "dc")
        x = BzrDir.open(repos_url+"/trunk")
        b = x.create_branch()
        self.assertEquals(repos_url+"/trunk", b.base)
        transport = SvnRaTransport(repos_url)
        self.assertEquals(svn.core.svn_node_dir, 
                transport.check_path("trunk", 1))

    def test_bad_dir(self):
        repos_url = self.make_client("d", "dc")
        self.build_tree({"dc/foo": None})
        self.client_add("dc/foo")
        self.client_commit("dc", "msg")
        BzrDir.open(repos_url+"/foo")

    def test_create(self):
        repos_url = self.make_client("d", "dc")
        x = BzrDir.open(repos_url)
        self.assertTrue(hasattr(x, 'svn_root_url'))

    def test_import_branch(self):
        repos_url = self.make_client("d", "dc")
        x = BzrDir.open(repos_url+"/trunk")
        origb = BzrDir.create_standalone_workingtree("origb")
        self.build_tree({'origb/twin': 'bla', 'origb/peaks': 'bloe'})
        origb.add(["twin", "peaks"])
        origb.commit("Message")
        b = x.import_branch(source=origb.branch)
        self.assertEquals(origb.branch.revision_history(), b.revision_history())
        self.assertEquals(origb.branch.revision_history(), 
                Branch.open(repos_url+"/trunk").revision_history())

    def test_open_repos_root(self):
        repos_url = self.make_client("d", "dc")
        x = BzrDir.open(repos_url)
        repos = x.open_repository()
        self.assertTrue(hasattr(repos, 'uuid'))

    def test_find_repos_nonroot(self):
        repos_url = self.make_client("d", "dc")
        self.build_tree({'dc/trunk': None})
        self.client_add("dc/trunk")
        self.client_commit("dc", "data")
        x = BzrDir.open(repos_url+"/trunk")
        repos = x.find_repository()
        self.assertTrue(hasattr(repos, 'uuid'))

    def test_find_repos_root(self):
        repos_url = self.make_client("d", "dc")
        x = BzrDir.open(repos_url)
        repos = x.find_repository()
        self.assertTrue(hasattr(repos, 'uuid'))

    def test_open_repos_nonroot(self):
        repos_url = self.make_client("d", "dc")
        self.build_tree({'dc/trunk': None})
        self.client_add("dc/trunk")
        self.client_commit("dc", "data")
        x = BzrDir.open(repos_url+"/trunk")
        self.assertRaises(NoRepositoryPresent, x.open_repository)

    def test_needs_format_upgrade_other(self):
        repos_url = self.make_client("d", "dc")
        x = BzrDir.open(repos_url+"/trunk")
        self.assertTrue(x.needs_format_conversion(format_registry.make_bzrdir("rich-root")))

    def test_needs_format_upgrade_default(self):
        repos_url = self.make_client("d", "dc")
        x = BzrDir.open(repos_url+"/trunk")
        self.assertTrue(x.needs_format_conversion())

    def test_needs_format_upgrade_self(self):
        repos_url = self.make_client("d", "dc")
        x = BzrDir.open(repos_url+"/trunk")
        self.assertTrue(x.needs_format_conversion(SvnRemoteFormat()))

    def test_find_repository_not_found(self):
        repos_url = self.make_client('d', 'dc')
        osutils.rmtree("d")
        self.assertRaises(NoRepositoryPresent, 
                lambda: BzrDir.open("dc").find_repository())