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

« back to all changes in this revision

Viewing changes to .pc/01_test_isolation.diff/tracbzr/tests/test_repository.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2011-05-01 05:20:09 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20110501052009-s192c1t33hx9f7n4
Tags: 0.4.2+bzr117-1
* New upstream snapshot.
 + Drop 01_test_isolation.diff: Applied upstream.
* Add build dependency on python-bzrlib.tests, required for newer
  versions of bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: iso-8859-1 -*-
2
 
#
3
 
# Copyright (C) 2006 Panoramic Feedback <abentley@panoramicfeedback.com>
4
 
# All rights reserved.
5
 
#
6
 
# This software may be used and distributed according to the terms
7
 
# of the GNU General Public License, incorporated herein by reference.
8
 
 
9
 
 
10
 
import urllib
11
 
 
12
 
from bzrlib import (
13
 
    bzrdir,
14
 
    osutils,
15
 
    )
16
 
from bzrlib.revision import (
17
 
    CURRENT_REVISION,
18
 
    NULL_REVISION,
19
 
    )
20
 
from bzrlib.tests import treeshape
21
 
 
22
 
from trac import versioncontrol
23
 
 
24
 
from tracbzr import tests
25
 
 
26
 
class TestRepository(tests.MultiBranchTracTestCase):
27
 
 
28
 
    def test_get_changeset(self):
29
 
        self.assertRaises(versioncontrol.NoSuchChangeset, 
30
 
                          self.trac_repo().get_changeset, 'tree,foo')
31
 
        self.assertRaises(versioncontrol.NoSuchChangeset, 
32
 
                          self.trac_repo().get_changeset, 'treo,foo')
33
 
        self.assertRaises(versioncontrol.NoSuchChangeset, 
34
 
                          self.trac_repo().get_changeset, 'foo')
35
 
        self.assertRaises(versioncontrol.NoSuchChangeset, 
36
 
                          self.trac_repo().get_changeset, ',foo')
37
 
        revision_id = self.commit_foo_bar()
38
 
        assert revision_id is not None
39
 
        changeset = self.trac_repo().get_changeset('tree,%s' %
40
 
                                                   urllib.quote(revision_id))
41
 
        self.assertRaises(versioncontrol.NoSuchChangeset, 
42
 
                          self.trac_repo().get_changeset, 'tree/../,%s' %
43
 
                                                   urllib.quote(revision_id))
44
 
        self.assertRaises(versioncontrol.NoSuchChangeset, 
45
 
                          self.trac_repo().get_changeset, 'tree,23')
46
 
 
47
 
    def commit_foo_bar(self):
48
 
        """Create a simple revision"""
49
 
        treeshape.build_tree_contents([('repo/tree/a/',), ('repo/tree/a/b', 
50
 
                                        'contents of b')])
51
 
        self.tree.add(['a', 'a/b'])
52
 
        return self.tree.commit('tree contents', rev_id='foo%bar')
53
 
 
54
 
    def commit_foo_bar_baz(self):
55
 
        """Create a repo with two branches.
56
 
 
57
 
        - tree:
58
 
          1       foo%bar
59
 
            1.1.1 baz
60
 
          2       qux
61
 
 
62
 
        - other:
63
 
          1       foo%bar
64
 
          2       baz
65
 
        """
66
 
        self.commit_foo_bar()
67
 
        other = self.tree.bzrdir.sprout('repo/other').open_workingtree()
68
 
        treeshape.build_tree_contents([
69
 
            ('repo/other/a/b', 'new contents of b'),
70
 
            ('repo/other/a/c', 'contents of c')])
71
 
        other.add(['a/c'])
72
 
        other.commit('added c, changed b', rev_id='baz')
73
 
        self.tree.merge_from_branch(other.branch)
74
 
        return self.tree.commit('merged from other', rev_id='qux')
75
 
 
76
 
    def test_has_node(self):
77
 
        self.commit_foo_bar()
78
 
        self.assertTrue(self.trac_repo().has_node('tree/a', 'tree,foo%25bar'))
79
 
        self.trac_repo().has_node('b', 'tree,foo%25bar')
80
 
        self.trac_repo().has_node('b', 'tree,foo%25bar')
81
 
        self.assertFalse(self.trac_repo().has_node('b', 'tree,foo%25bar'))
82
 
        self.assertFalse(self.trac_repo().has_node('tree/b', 'tree,foo%25bar'))
83
 
        self.assertTrue(self.trac_repo().has_node('tree/a/b', 
84
 
                                                  'tree,foo%25bar'))
85
 
        self.assertRaises(versioncontrol.NoSuchChangeset, 
86
 
                          self.trac_repo().has_node, 'tree/a/b', 
87
 
                          'tree,foo%25baa')
88
 
        self.assertRaises(versioncontrol.NoSuchChangeset, 
89
 
                          self.trac_repo().has_node, 'a/b', 'treo,foo%25bar')
90
 
        self.assertRaises(versioncontrol.NoSuchChangeset, 
91
 
                          self.trac_repo().has_node, 'a/b', 'tree,23')
92
 
        self.assertRaises(versioncontrol.NoSuchChangeset, 
93
 
                          self.trac_repo().has_node, 'a/b', 'treo,23')
94
 
 
95
 
    def test_get_node(self):
96
 
        self.commit_foo_bar()
97
 
        a_node = self.trac_repo().get_node('tree/a', 'tree,foo%25bar')
98
 
        self.assertTrue(a_node.isdir)
99
 
        self.assertFalse(a_node.isfile)
100
 
        self.assertTrue(a_node.get_content() is None)
101
 
        self.assertEqual(list('tree/a/b'), 
102
 
                         list(a_node.get_entries().next().path))
103
 
        self.assertRaises(versioncontrol.NoSuchNode, 
104
 
                          self.trac_repo().get_node, 'tree/b', 
105
 
                          'tree,foo%25bar')
106
 
        b_node = self.trac_repo().get_node('tree/a/b', 'tree,foo%25bar')
107
 
        self.assertFalse(b_node.isdir)
108
 
        self.assertTrue(b_node.isfile)
109
 
        self.assertEqual('contents of b', b_node.get_content().read())
110
 
        self.assertRaises(versioncontrol.NoSuchChangeset, 
111
 
                          self.trac_repo().get_node, 'tree/a/b', 
112
 
                          'tree,foo%25baa')
113
 
        self.assertRaises(versioncontrol.NoSuchChangeset, 
114
 
                          self.trac_repo().get_node, 'a/b', 'treo,foo%25bar')
115
 
        self.assertRaises(versioncontrol.NoSuchChangeset, 
116
 
                          self.trac_repo().get_node, 'a/b', 'tree,23')
117
 
        self.assertRaises(versioncontrol.NoSuchChangeset, 
118
 
                          self.trac_repo().get_node, 'a/b', 'treo,23')
119
 
 
120
 
    def test_rev(self):
121
 
        self.commit_foo_bar()
122
 
        self.assertEqual(CURRENT_REVISION, self.trac_repo().get_youngest_rev())
123
 
        self.assertEqual('tree,1', self.trac_repo().get_oldest_rev())
124
 
        oldest = self.tree.commit('again')
125
 
        repo = self.trac_repo()
126
 
        self.assertEqual(CURRENT_REVISION, self.trac_repo().get_youngest_rev())
127
 
        self.assertEqual('tree,1', self.trac_repo().get_oldest_rev())
128
 
 
129
 
    def test_previous_rev(self):
130
 
        self.commit_foo_bar_baz()
131
 
        repo = self.trac_repo()
132
 
        self.assertEqual('tree,1', repo.previous_rev('tree,2'))
133
 
        self.assertEqual('other,1', repo.previous_rev('other,2'))
134
 
        self.assertEqual('tree,0', repo.previous_rev('tree,1'))
135
 
        self.assertEqual(None, repo.previous_rev(NULL_REVISION))
136
 
 
137
 
    def test_next_rev(self):
138
 
        self.commit_foo_bar_baz()
139
 
        repo = self.trac_repo()
140
 
        self.assertEqual('tree,2', repo.next_rev('tree,1', 'tree'))
141
 
        self.assertEqual(None, repo.next_rev('tree,2'))
142
 
        self.assertRaises(versioncontrol.NoSuchChangeset, repo.next_rev, 
143
 
                          'tree,255')
144
 
        self.assertRaises(versioncontrol.NoSuchChangeset, repo.next_rev, 
145
 
                          'tree,3')
146
 
 
147
 
    def test_get_path_history(self):
148
 
        self.commit_foo_bar()
149
 
        repo = self.trac_repo()
150
 
        self.assertRaises(versioncontrol.NoSuchNode, 
151
 
                          repo.get_path_history, 'b')
152
 
        self.assertEqual([(u'tree/a/b', 'tree,1', 'add')], 
153
 
                         list(repo.get_path_history('tree/a/b')))
154
 
 
155
 
    def test_normalize_path(self):
156
 
        repo = self.trac_repo()
157
 
        self.assertEqual('', repo.normalize_path(None))
158
 
        self.assertEqual('foo', repo.normalize_path('foo'))
159
 
        self.assertEqual('foo', repo.normalize_path('/foo/'))
160
 
 
161
 
    def test_normalize_rev(self):
162
 
        self.commit_foo_bar()
163
 
        rev1 = self.tree.commit('again')
164
 
        repo = self.trac_repo()
165
 
        self.assertEqual(CURRENT_REVISION, repo.normalize_rev(None))
166
 
        self.assertEqual('tree,1', repo.normalize_rev('tree,foo%25bar'))
167
 
        self.assertRaises(versioncontrol.NoSuchChangeset, repo.normalize_rev, 
168
 
                          'garbage,foo%25bar')
169
 
 
170
 
    def test_short_rev(self):
171
 
        self.commit_foo_bar_baz()
172
 
        repo = self.trac_repo()
173
 
        self.assertEqual('1', repo.short_rev('tree,1'))
174
 
        self.assertEqual('2', repo.short_rev('tree,qux'))
175
 
        self.assertEqual('1.1.1', repo.short_rev('tree,baz'))
176
 
 
177
 
    def test_string_rev(self):
178
 
        self.tree.commit('Commit with comma in revid', rev_id='hi,there')
179
 
        self.assertEqual('tree,hi%2Cthere', 
180
 
                         self.trac_repo()._string_rev_revid('tree', 
181
 
                         'hi,there'))
182
 
 
183
 
    def test_branch_path(self):
184
 
        branch = self.tree.branch
185
 
        self.assertEqual('tree', self.trac_repo().branch_path(branch))
186
 
 
187
 
    def test_parse_rev(self):
188
 
        repository = self.trac_repo()
189
 
        branch, revid = repository._parse_rev('tree,hi%2Cthere')
190
 
        self.assertEqual('tree', repository.branch_path(branch))
191
 
        self.assertEqual('hi,there', revid)
192
 
 
193
 
    def test_sync(self):
194
 
        self.trac_repo().sync()