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