1 # Copyright (C) 2006 Jelmer Vernooij <jelmer@samba.org>
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.
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.
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
17 from tests import TestCaseWithSubversionRepository
18 from bzrlib.bzrdir import BzrDir
19 from bzrlib.errors import NotBranchError, NoSuchFile, FileExists
20 from transport import SvnRaTransport, bzr_to_svn_url
21 from unittest import TestCase
25 class SvnRaTest(TestCaseWithSubversionRepository):
26 def test_open_nonexisting(self):
27 self.assertRaises(NotBranchError, SvnRaTransport, "svn+nonexisting://foo/bar")
29 def test_create(self):
30 repos_url = self.make_client('a', 'ac')
31 t = SvnRaTransport("svn+%s" % repos_url)
32 self.assertIsInstance(t, SvnRaTransport)
33 self.assertEqual(t.base, "svn+%s" % repos_url)
35 def test_create_direct(self):
36 repos_url = self.make_client('a', 'ac')
37 t = SvnRaTransport(repos_url)
38 self.assertIsInstance(t, SvnRaTransport)
39 self.assertEqual(t.base, repos_url)
41 def test_reparent(self):
42 repos_url = self.make_client('d', 'dc')
43 t = SvnRaTransport(repos_url)
45 t.reparent("%s/foo" % repos_url)
46 self.assertEqual("%s/foo" % repos_url, t.base)
48 def test_listable(self):
49 repos_url = self.make_client('d', 'dc')
50 t = SvnRaTransport(repos_url)
51 self.assertTrue(t.listable())
53 def test_list_dir(self):
54 repos_url = self.make_client('d', 'dc')
55 t = SvnRaTransport(repos_url)
56 self.assertEqual([], t.list_dir("."))
58 self.assertEqual(["foo"], t.list_dir("."))
59 self.assertEqual([], t.list_dir("foo"))
61 self.assertEqual(["bar"], t.list_dir("foo"))
63 def test_list_dir_file(self):
64 repos_url = self.make_client('d', 'dc')
65 self.build_tree({"dc/file": "data"})
66 self.client_add("dc/file")
67 self.client_commit("dc", "Bla")
69 t = SvnRaTransport(repos_url)
70 self.assertEqual(["file"], t.list_dir("."))
71 self.assertRaises(NoSuchFile, t.list_dir, "file")
74 repos_url = self.make_client('d', 'dc')
75 self.build_tree({"dc/dir": None, "dc/bl": "data"})
76 self.client_add("dc/dir")
77 self.client_add("dc/bl")
78 self.client_commit("dc", "Bla")
80 t = SvnRaTransport(repos_url)
81 self.assertEqual("%s/dir" % repos_url, t.clone('dir').base)
84 repos_url = self.make_client('d', 'dc')
85 t = SvnRaTransport(repos_url)
87 self.client_update("dc")
88 self.assertTrue(os.path.isdir("dc/bla"))
90 self.client_update("dc")
91 self.assertTrue(os.path.isdir("dc/bla/subdir"))
93 def test_mkdir_missing_parent(self):
94 repos_url = self.make_client('d', 'dc')
95 t = SvnRaTransport(repos_url)
96 self.assertRaises(NoSuchFile, t.mkdir, "bla/subdir")
97 self.client_update("dc")
98 self.assertFalse(os.path.isdir("dc/bla/subdir"))
100 def test_mkdir_twice(self):
101 repos_url = self.make_client('d', 'dc')
102 t = SvnRaTransport(repos_url)
104 self.assertRaises(FileExists, t.mkdir, "bla")
106 def test_clone(self):
107 repos_url = self.make_client('d', 'dc')
108 self.build_tree({"dc/dir": None, "dc/bl": "data"})
109 self.client_add("dc/dir")
110 self.client_add("dc/bl")
111 self.client_commit("dc", "Bla")
113 t = SvnRaTransport(repos_url)
114 self.assertEqual("%s/dir" % repos_url, t.clone('dir').base)
116 def test_get_root(self):
117 repos_url = self.make_client('d', 'dc')
118 self.build_tree({"dc/dir": None, "dc/bl": "data"})
119 self.client_add("dc/dir")
120 self.client_add("dc/bl")
121 self.client_commit("dc", "Bla")
123 t = SvnRaTransport("%s/dir" % repos_url)
125 self.assertEqual(repos_url, root.base)
128 class UrlConversionTest(TestCase):
129 def test_bzr_to_svn_url(self):
130 self.assertEqual("svn://host/location",
131 bzr_to_svn_url("svn://host/location"))
132 self.assertEqual("svn+ssh://host/location",
133 bzr_to_svn_url("svn+ssh://host/location"))
134 self.assertEqual("http://host/location",
135 bzr_to_svn_url("http://host/location"))
136 self.assertEqual("http://host/location",
137 bzr_to_svn_url("svn+http://host/location"))