1 # Copyright (C) 2006-2007 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 """Branch property access tests."""
19 from bzrlib.errors import NoSuchRevision
21 from tests import TestCaseWithSubversionRepository
22 from branchprops import BranchPropertyList
23 from logwalker import LogWalker
24 from transport import SvnRaTransport
29 from pysqlite2 import dbapi2 as sqlite3
31 class TestBranchProps(TestCaseWithSubversionRepository):
33 super(TestBranchProps, self).setUp()
34 self.db = sqlite3.connect(":memory:")
36 def test_get_property(self):
37 repos_url = self.make_client('d', 'dc')
38 self.client_set_prop("dc", "myprop", "data")
39 self.client_commit("dc", "My Message")
41 logwalk = LogWalker(transport=SvnRaTransport(repos_url))
43 bp = BranchPropertyList(logwalk, self.db)
44 self.assertEqual("data", bp.get_property("", 1, "myprop"))
46 def test_get_property_norev(self):
47 repos_url = self.make_client('d', 'dc')
48 self.client_set_prop("dc", "myprop", "data")
49 self.client_commit("dc", "My Message")
51 logwalk = LogWalker(transport=SvnRaTransport(repos_url))
53 bp = BranchPropertyList(logwalk, self.db)
54 self.assertRaises(NoSuchRevision, bp.get_property, "", 10, "myprop")
56 def test_get_old_property(self):
57 repos_url = self.make_client('d', 'dc')
58 self.client_set_prop("dc", "myprop", "data")
59 self.client_commit("dc", "My Message")
60 self.build_tree({'dc/foo': "bla"})
61 self.client_add("dc/foo")
62 self.client_commit("dc", "My Message")
64 logwalk = LogWalker(transport=SvnRaTransport(repos_url))
66 bp = BranchPropertyList(logwalk, self.db)
67 self.assertEqual("data", bp.get_property("", 2, "myprop"))
69 def test_get_nonexistent_property(self):
70 repos_url = self.make_client('d', 'dc')
71 self.client_set_prop("dc", "myprop", "data")
72 self.client_commit("dc", "My Message")
74 logwalk = LogWalker(transport=SvnRaTransport(repos_url))
76 bp = BranchPropertyList(logwalk, self.db)
77 self.assertEqual(None, bp.get_property("", 1, "otherprop"))
79 def test_get_properties(self):
80 repos_url = self.make_client('d', 'dc')
81 self.client_set_prop("dc", "myprop", "data")
82 self.client_commit("dc", "My Message")
84 transport = SvnRaTransport(repos_url)
85 logwalk = LogWalker(transport=transport)
87 bp = BranchPropertyList(logwalk, self.db)
88 props = bp.get_properties("", 1)
89 self.assertEqual("data", props["myprop"])
90 self.assertEqual(transport.get_uuid(), props["svn:entry:uuid"])
91 self.assertEqual('1', props["svn:entry:committed-rev"])
92 self.assertTrue("svn:entry:last-author" in props)
93 self.assertTrue("svn:entry:committed-date" in props)
95 def test_get_property_diff(self):
96 repos_url = self.make_client('d', 'dc')
97 self.client_set_prop("dc", "myprop", "data\n")
98 self.client_commit("dc", "My Message")
99 self.client_set_prop("dc", "myprop", "data\ndata2\n")
100 self.client_commit("dc", "My Message")
102 logwalk = LogWalker(transport=SvnRaTransport(repos_url))
104 bp = BranchPropertyList(logwalk, self.db)
105 self.assertEqual("data2\n", bp.get_property_diff("", 2, "myprop"))
107 def test_get_property_diff_ignore_origchange(self):
108 repos_url = self.make_client('d', 'dc')
109 self.client_set_prop("dc", "myprop", "foodata\n")
110 self.client_commit("dc", "My Message")
111 self.client_set_prop("dc", "myprop", "data\ndata2\n")
112 self.client_commit("dc", "My Message")
114 logwalk = LogWalker(transport=SvnRaTransport(repos_url))
116 bp = BranchPropertyList(logwalk, self.db)
117 self.assertEqual("", bp.get_property_diff("", 2, "myprop"))