~ubuntu-branches/debian/sid/trac-bzr/sid

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# -*- coding: iso-8859-1 -*-
#
# Copyright (C) 2006 Panoramic Feedback <abentley@panoramicfeedback.com>
# All rights reserved.
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.


import urllib

from bzrlib import (
    bzrdir,
    osutils,
    )
from bzrlib.revision import (
    CURRENT_REVISION,
    NULL_REVISION,
    )
from bzrlib.tests import treeshape

from trac import versioncontrol

from tracbzr import tests

class TestRepository(tests.MultiBranchTracTestCase):

    def test_get_changeset(self):
        self.assertRaises(versioncontrol.NoSuchChangeset, 
                          self.trac_repo().get_changeset, 'tree,foo')
        self.assertRaises(versioncontrol.NoSuchChangeset, 
                          self.trac_repo().get_changeset, 'treo,foo')
        self.assertRaises(versioncontrol.NoSuchChangeset, 
                          self.trac_repo().get_changeset, 'foo')
        self.assertRaises(versioncontrol.NoSuchChangeset, 
                          self.trac_repo().get_changeset, ',foo')
        revision_id = self.commit_foo_bar()
        assert revision_id is not None
        changeset = self.trac_repo().get_changeset('tree,%s' %
                                                   urllib.quote(revision_id))
        self.assertRaises(versioncontrol.NoSuchChangeset, 
                          self.trac_repo().get_changeset, 'tree/../,%s' %
                                                   urllib.quote(revision_id))
        self.assertRaises(versioncontrol.NoSuchChangeset, 
                          self.trac_repo().get_changeset, 'tree,23')

    def commit_foo_bar(self):
        """Create a simple revision"""
        treeshape.build_tree_contents([('repo/tree/a/',), ('repo/tree/a/b', 
                                        'contents of b')])
        self.tree.add(['a', 'a/b'])
        return self.tree.commit('tree contents', rev_id='foo%bar')

    def commit_foo_bar_baz(self):
        """Create a repo with two branches.

        - tree:
          1       foo%bar
            1.1.1 baz
          2       qux

        - other:
          1       foo%bar
          2       baz
        """
        self.commit_foo_bar()
        other = self.tree.bzrdir.sprout('repo/other').open_workingtree()
        treeshape.build_tree_contents([
            ('repo/other/a/b', 'new contents of b'),
            ('repo/other/a/c', 'contents of c')])
        other.add(['a/c'])
        other.commit('added c, changed b', rev_id='baz')
        self.tree.merge_from_branch(other.branch)
        return self.tree.commit('merged from other', rev_id='qux')

    def test_has_node(self):
        self.commit_foo_bar()
        self.assertTrue(self.trac_repo().has_node('tree/a', 'tree,foo%25bar'))
        self.trac_repo().has_node('b', 'tree,foo%25bar')
        self.trac_repo().has_node('b', 'tree,foo%25bar')
        self.assertFalse(self.trac_repo().has_node('b', 'tree,foo%25bar'))
        self.assertFalse(self.trac_repo().has_node('tree/b', 'tree,foo%25bar'))
        self.assertTrue(self.trac_repo().has_node('tree/a/b', 
                                                  'tree,foo%25bar'))
        self.assertRaises(versioncontrol.NoSuchChangeset, 
                          self.trac_repo().has_node, 'tree/a/b', 
                          'tree,foo%25baa')
        self.assertRaises(versioncontrol.NoSuchChangeset, 
                          self.trac_repo().has_node, 'a/b', 'treo,foo%25bar')
        self.assertRaises(versioncontrol.NoSuchChangeset, 
                          self.trac_repo().has_node, 'a/b', 'tree,23')
        self.assertRaises(versioncontrol.NoSuchChangeset, 
                          self.trac_repo().has_node, 'a/b', 'treo,23')

    def test_get_node(self):
        self.commit_foo_bar()
        a_node = self.trac_repo().get_node('tree/a', 'tree,foo%25bar')
        self.assertTrue(a_node.isdir)
        self.assertFalse(a_node.isfile)
        self.assertTrue(a_node.get_content() is None)
        self.assertEqual(list('tree/a/b'), 
                         list(a_node.get_entries().next().path))
        self.assertRaises(versioncontrol.NoSuchNode, 
                          self.trac_repo().get_node, 'tree/b', 
                          'tree,foo%25bar')
        b_node = self.trac_repo().get_node('tree/a/b', 'tree,foo%25bar')
        self.assertFalse(b_node.isdir)
        self.assertTrue(b_node.isfile)
        self.assertEqual('contents of b', b_node.get_content().read())
        self.assertRaises(versioncontrol.NoSuchChangeset, 
                          self.trac_repo().get_node, 'tree/a/b', 
                          'tree,foo%25baa')
        self.assertRaises(versioncontrol.NoSuchChangeset, 
                          self.trac_repo().get_node, 'a/b', 'treo,foo%25bar')
        self.assertRaises(versioncontrol.NoSuchChangeset, 
                          self.trac_repo().get_node, 'a/b', 'tree,23')
        self.assertRaises(versioncontrol.NoSuchChangeset, 
                          self.trac_repo().get_node, 'a/b', 'treo,23')

    def test_rev(self):
        self.commit_foo_bar()
        self.assertEqual(CURRENT_REVISION, self.trac_repo().get_youngest_rev())
        self.assertEqual('tree,1', self.trac_repo().get_oldest_rev())
        oldest = self.tree.commit('again')
        repo = self.trac_repo()
        self.assertEqual(CURRENT_REVISION, self.trac_repo().get_youngest_rev())
        self.assertEqual('tree,1', self.trac_repo().get_oldest_rev())

    def test_previous_rev(self):
        self.commit_foo_bar_baz()
        repo = self.trac_repo()
        self.assertEqual('tree,1', repo.previous_rev('tree,2'))
        self.assertEqual('other,1', repo.previous_rev('other,2'))
        self.assertEqual('tree,0', repo.previous_rev('tree,1'))
        self.assertEqual(None, repo.previous_rev(NULL_REVISION))

    def test_next_rev(self):
        self.commit_foo_bar_baz()
        repo = self.trac_repo()
        self.assertEqual('tree,2', repo.next_rev('tree,1', 'tree'))
        self.assertEqual(None, repo.next_rev('tree,2'))
        self.assertRaises(versioncontrol.NoSuchChangeset, repo.next_rev, 
                          'tree,255')
        self.assertRaises(versioncontrol.NoSuchChangeset, repo.next_rev, 
                          'tree,3')

    def test_get_path_history(self):
        self.commit_foo_bar()
        repo = self.trac_repo()
        self.assertRaises(versioncontrol.NoSuchNode, 
                          repo.get_path_history, 'b')
        self.assertEqual([(u'tree/a/b', 'tree,1', 'add')], 
                         list(repo.get_path_history('tree/a/b')))

    def test_normalize_path(self):
        repo = self.trac_repo()
        self.assertEqual('', repo.normalize_path(None))
        self.assertEqual('foo', repo.normalize_path('foo'))
        self.assertEqual('foo', repo.normalize_path('/foo/'))

    def test_normalize_rev(self):
        self.commit_foo_bar()
        rev1 = self.tree.commit('again')
        repo = self.trac_repo()
        self.assertEqual(CURRENT_REVISION, repo.normalize_rev(None))
        self.assertEqual('tree,1', repo.normalize_rev('tree,foo%25bar'))
        self.assertRaises(versioncontrol.NoSuchChangeset, repo.normalize_rev, 
                          'garbage,foo%25bar')

    def test_short_rev(self):
        self.commit_foo_bar_baz()
        repo = self.trac_repo()
        self.assertEqual('1', repo.short_rev('tree,1'))
        self.assertEqual('2', repo.short_rev('tree,qux'))
        self.assertEqual('1.1.1', repo.short_rev('tree,baz'))

    def test_string_rev(self):
        self.tree.commit('Commit with comma in revid', rev_id='hi,there')
        self.assertEqual('tree,hi%2Cthere', 
                         self.trac_repo()._string_rev_revid('tree', 
                         'hi,there'))

    def test_branch_path(self):
        branch = self.tree.branch
        self.assertEqual('tree', self.trac_repo().branch_path(branch))

    def test_parse_rev(self):
        repository = self.trac_repo()
        branch, revid = repository._parse_rev('tree,hi%2Cthere')
        self.assertEqual('tree', repository.branch_path(branch))
        self.assertEqual('hi,there', revid)

    def test_sync(self):
        self.trac_repo().sync()