Fix bug in revid caching.
[jelmer/subvertpy.git] / tests / test_branchprops.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 """Branch property access tests."""
18
19 from bzrlib.errors import NoSuchRevision
20
21 from tests import TestCaseWithSubversionRepository
22 from branchprops import BranchPropertyList
23 from logwalker import LogWalker
24 from transport import SvnRaTransport
25
26 try:
27     import sqlite3
28 except ImportError:
29     from pysqlite2 import dbapi2 as sqlite3
30
31 class TestBranchProps(TestCaseWithSubversionRepository):
32     def setUp(self):
33         super(TestBranchProps, self).setUp()
34         self.db = sqlite3.connect(":memory:")
35
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")
40
41         logwalk = LogWalker(transport=SvnRaTransport(repos_url))
42
43         bp = BranchPropertyList(logwalk, self.db)
44         self.assertEqual("data", bp.get_property("", 1, "myprop"))
45
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")
50
51         logwalk = LogWalker(transport=SvnRaTransport(repos_url))
52
53         bp = BranchPropertyList(logwalk, self.db)
54         self.assertRaises(NoSuchRevision, bp.get_property, "", 10, "myprop")
55
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")
63
64         logwalk = LogWalker(transport=SvnRaTransport(repos_url))
65
66         bp = BranchPropertyList(logwalk, self.db)
67         self.assertEqual("data", bp.get_property("", 2, "myprop"))
68
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")
73
74         logwalk = LogWalker(transport=SvnRaTransport(repos_url))
75
76         bp = BranchPropertyList(logwalk, self.db)
77         self.assertEqual(None, bp.get_property("", 1, "otherprop"))
78
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")
83
84         transport = SvnRaTransport(repos_url)
85         logwalk = LogWalker(transport=transport)
86
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)
94
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")
101
102         logwalk = LogWalker(transport=SvnRaTransport(repos_url))
103
104         bp = BranchPropertyList(logwalk, self.db)
105         self.assertEqual("data2\n", bp.get_property_diff("", 2, "myprop"))
106
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")
113
114         logwalk = LogWalker(transport=SvnRaTransport(repos_url))
115
116         bp = BranchPropertyList(logwalk, self.db)
117         self.assertEqual("", bp.get_property_diff("", 2, "myprop"))