Merge dev tree.
[jelmer/subvertpy.git] / tests / test_transport.py
1 # Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
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 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
22
23 import os
24
25 class SvnRaTest(TestCaseWithSubversionRepository):
26     def test_open_nonexisting(self):
27         self.assertRaises(NotBranchError, SvnRaTransport, "svn+nonexisting://foo/bar")
28
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)
34
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)
40
41     def test_reparent(self):
42         repos_url = self.make_client('d', 'dc')
43         t = SvnRaTransport(repos_url)
44         t.mkdir("foo")
45         t.reparent("%s/foo" % repos_url)
46         self.assertEqual("%s/foo" % repos_url, t.base)
47
48     def test_listable(self):
49         repos_url = self.make_client('d', 'dc')
50         t = SvnRaTransport(repos_url)
51         self.assertTrue(t.listable())
52
53     def test_get_dir_rev(self):
54         repos_url = self.make_client('d', 'dc')
55         self.build_tree({'dc/foo/bar': 'Data'})
56         self.client_add("dc/foo")
57         self.client_commit("dc", "MSG")
58         self.client_delete("dc/foo")
59         self.client_commit("dc", "MSG2")
60         t = SvnRaTransport(repos_url)
61         lists = t.get_dir("foo", 1, 0)
62         self.assertTrue("bar" in lists[0])
63
64     def test_list_dir(self):
65         repos_url = self.make_client('d', 'dc')
66         t = SvnRaTransport(repos_url)
67         self.assertEqual([], t.list_dir("."))
68         t.mkdir("foo")
69         self.assertEqual(["foo"], t.list_dir("."))
70         self.assertEqual([], t.list_dir("foo"))
71         t.mkdir("foo/bar")
72         self.assertEqual(["bar"], t.list_dir("foo"))
73
74     def test_list_dir_file(self):
75         repos_url = self.make_client('d', 'dc')
76         self.build_tree({"dc/file": "data"})
77         self.client_add("dc/file")
78         self.client_commit("dc", "Bla")
79
80         t = SvnRaTransport(repos_url)
81         self.assertEqual(["file"], t.list_dir("."))
82         self.assertRaises(NoSuchFile, t.list_dir, "file")
83
84     def test_clone(self):
85         repos_url = self.make_client('d', 'dc')
86         self.build_tree({"dc/dir": None, "dc/bl": "data"})
87         self.client_add("dc/dir")
88         self.client_add("dc/bl")
89         self.client_commit("dc", "Bla")
90
91         t = SvnRaTransport(repos_url)
92         self.assertEqual("%s/dir" % repos_url, t.clone('dir').base)
93
94     def test_clone_none(self):
95         repos_url = self.make_client('d', 'dc')
96         self.build_tree({"dc/dir": None, "dc/bl": "data"})
97         self.client_add("dc/dir")
98         self.client_add("dc/bl")
99         self.client_commit("dc", "Bla")
100
101         t = SvnRaTransport(repos_url)
102         tt = t.clone()
103         self.assertEqual(tt.base, t.base)
104         tt.reparent(os.path.join(t.base, "dir"))
105         self.assertNotEqual(tt.base, t.base)
106
107     def test_mkdir(self):
108         repos_url = self.make_client('d', 'dc')
109         t = SvnRaTransport(repos_url)
110         t.mkdir("bla")
111         self.client_update("dc")
112         self.assertTrue(os.path.isdir("dc/bla"))
113         t.mkdir("bla/subdir")
114         self.client_update("dc")
115         self.assertTrue(os.path.isdir("dc/bla/subdir"))
116
117     def test_has_dot(self):
118         t = SvnRaTransport(self.make_client('d', 'dc'))
119         self.assertEqual(False, t.has("."))
120
121     def test_has_nonexistent(self):
122         t = SvnRaTransport(self.make_client('d', 'dc'))
123         self.assertEqual(False, t.has("bar"))
124
125     def test_mkdir_missing_parent(self):
126         repos_url = self.make_client('d', 'dc')
127         t = SvnRaTransport(repos_url)
128         self.assertRaises(NoSuchFile, t.mkdir, "bla/subdir")
129         self.client_update("dc")
130         self.assertFalse(os.path.isdir("dc/bla/subdir"))
131
132     def test_mkdir_twice(self):
133         repos_url = self.make_client('d', 'dc')
134         t = SvnRaTransport(repos_url)
135         t.mkdir("bla")
136         self.assertRaises(FileExists, t.mkdir, "bla")
137
138     def test_clone(self):
139         repos_url = self.make_client('d', 'dc')
140         self.build_tree({"dc/dir": None, "dc/bl": "data"})
141         self.client_add("dc/dir")
142         self.client_add("dc/bl")
143         self.client_commit("dc", "Bla")
144
145         t = SvnRaTransport(repos_url)
146         self.assertEqual("%s/dir" % repos_url, t.clone('dir').base)
147
148     def test_get_root(self):
149         repos_url = self.make_client('d', 'dc')
150         self.build_tree({"dc/dir": None, "dc/bl": "data"})
151         self.client_add("dc/dir")
152         self.client_add("dc/bl")
153         self.client_commit("dc", "Bla")
154
155         t = SvnRaTransport("%s/dir" % repos_url)
156         root = t.get_repos_root()
157         self.assertEqual(repos_url, root)
158  
159
160 class UrlConversionTest(TestCase):
161     def test_bzr_to_svn_url(self):
162         self.assertEqual("svn://host/location", 
163                          bzr_to_svn_url("svn://host/location"))
164         self.assertEqual("svn+ssh://host/location", 
165                          bzr_to_svn_url("svn+ssh://host/location"))
166         self.assertEqual("http://host/location", 
167                          bzr_to_svn_url("http://host/location"))
168         self.assertEqual("http://host/location", 
169                          bzr_to_svn_url("svn+http://host/location"))