Use existing transports and wrap them rather than registering new transports.
[jelmer/subvertpy.git] / tests / test_logwalker.py
1 # Copyright (C) 2006 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 bzrlib.bzrdir import BzrDir
18 from bzrlib.errors import NoSuchRevision
19 from bzrlib.inventory import Inventory
20
21 import os
22 import logwalker
23 from scheme import NoBranchingScheme, TrunkBranchingScheme
24 from tests import TestCaseWithSubversionRepository
25 from transport import SvnRaTransport
26
27 class TestLogWalker(TestCaseWithSubversionRepository):
28     def setUp(self):
29         super(TestLogWalker, self).setUp()
30
31         logwalker.cache_dir = os.path.join(self.test_dir, "cache-dir")
32
33     def test_create(self):
34         repos_url = self.make_client("a", "ac")
35         logwalker.LogWalker(NoBranchingScheme(), transport=SvnRaTransport(repos_url))
36
37     def test_get_branch_log(self):
38         repos_url = self.make_client("a", "dc")
39         self.build_tree({'dc/foo': "data"})
40         self.client_add("dc/foo")
41         self.client_commit("dc", "My Message")
42
43         walker = logwalker.LogWalker(NoBranchingScheme(), 
44                                      transport=SvnRaTransport(repos_url))
45
46         self.assertEqual(1, len(list(walker.follow_history("", 1))))
47
48     def test_get_branch_invalid_revision(self):
49         repos_url = self.make_client("a", "dc")
50         walker = logwalker.LogWalker(NoBranchingScheme(), 
51                                      transport=SvnRaTransport(repos_url))
52         self.assertRaises(NoSuchRevision, list, 
53                           walker.follow_history("/", 20))
54
55     def test_invalid_branch_path(self):
56         repos_url = self.make_client("a", "dc")
57         walker = logwalker.LogWalker(NoBranchingScheme(), 
58                                      transport=SvnRaTransport(repos_url))
59
60         self.assertRaises(logwalker.NotSvnBranchPath, list, 
61                           walker.follow_history("foobar", 0))
62
63     def test_branch_log_all(self):
64         repos_url = self.make_client("a", "dc")
65         self.build_tree({'dc/trunk/file': "data", "dc/foo/file":"data"})
66         self.client_add("dc/trunk")
67         self.client_add("dc/foo")
68         self.client_commit("dc", "My Message")
69
70         walker = logwalker.LogWalker(TrunkBranchingScheme(), 
71                                      transport=SvnRaTransport(repos_url))
72
73         self.assertEqual(1, len(list(walker.follow_history(None, 1))))
74
75     def test_branch_log_specific(self):
76         repos_url = self.make_client("a", "dc")
77         self.build_tree({
78             'dc/branches': None,
79             'dc/branches/brancha': None,
80             'dc/branches/branchab': None,
81             'dc/branches/brancha/data': "data", 
82             "dc/branches/branchab/data":"data"})
83         self.client_add("dc/branches")
84         self.client_commit("dc", "My Message")
85
86         walker = logwalker.LogWalker(TrunkBranchingScheme(), 
87                                      transport=SvnRaTransport(repos_url))
88
89         self.assertEqual(1, len(list(walker.follow_history("branches/brancha",
90             1))))
91
92     def test_follow_history(self):
93         repos_url = self.make_client("a", "dc")
94         walker = logwalker.LogWalker(NoBranchingScheme(), 
95                                      transport=SvnRaTransport(repos_url))
96
97         self.build_tree({'dc/foo': "data"})
98         self.client_add("dc/foo")
99         self.client_commit("dc", "My Message")
100
101         for (branch, paths, rev) in walker.follow_history("", 1):
102            self.assertEqual(branch, "")
103            self.assertTrue(paths.has_key("foo"))
104            self.assertEqual(rev, 1)
105
106     def test_later_update(self):
107         repos_url = self.make_client("a", "dc")
108
109         walker = logwalker.LogWalker(NoBranchingScheme(), 
110                                      transport=SvnRaTransport(repos_url))
111
112         self.build_tree({'dc/foo': "data"})
113         self.client_add("dc/foo")
114         self.client_commit("dc", "My Message")
115
116         for (branch, paths, rev) in walker.follow_history("", 1):
117            self.assertEqual(branch, "")
118            self.assertTrue(paths.has_key("foo"))
119            self.assertEqual(rev, 1)
120
121         iter = walker.follow_history("", 2)
122         self.assertRaises(NoSuchRevision, list, iter)
123
124     def test_get_branch_log_follow(self):
125         repos_url = self.make_client("a", "dc")
126         self.build_tree({'dc/trunk/afile': "data", "dc/branches": None})
127         self.client_add("dc/trunk")
128         self.client_add("dc/branches")
129         self.client_commit("dc", "My Message")
130
131         self.client_copy("dc/trunk", "dc/branches/abranch")
132         self.client_commit("dc", "Create branch")
133
134         walker = logwalker.LogWalker(TrunkBranchingScheme(), 
135                                      transport=SvnRaTransport(repos_url))
136
137         items = list(walker.follow_history("branches/abranch", 2))
138         self.assertEqual(2, len(items))
139
140