~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/revisionstore_implementations/test_all.py

Merge in knit repository use of knits - still not a stable format, but can be experimented with.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Canonical Ltd
 
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
"""Revision store tests."""
 
18
 
 
19
 
 
20
import bzrlib.errors as errors
 
21
from bzrlib.revision import Revision
 
22
from bzrlib.store.revision import RevisionStore
 
23
from bzrlib.tests import TestCaseWithTransport
 
24
from bzrlib.transactions import PassThroughTransaction
 
25
from bzrlib.tree import EmptyTree
 
26
 
 
27
 
 
28
class TestFactory(TestCaseWithTransport):
 
29
 
 
30
    def test_factory_keeps_smoke_in(self):
 
31
        s = self.store_factory.create(self.get_url('.'))
 
32
        self.assertTrue(isinstance(s, RevisionStore))
 
33
 
 
34
 
 
35
class TestAll(TestCaseWithTransport):
 
36
 
 
37
    def setUp(self):
 
38
        super(TestAll, self).setUp()
 
39
        self.store = self.store_factory.create(self.get_url('.'))
 
40
        self.transaction = PassThroughTransaction()
 
41
 
 
42
    def test_add_has_get(self):
 
43
        rev = self.add_sample_rev()
 
44
        self.assertTrue(self.store.has_revision_id('A', self.transaction))
 
45
        rev2 = self.store.get_revision('A', self.transaction)
 
46
        self.assertEqual(rev, rev2)
 
47
 
 
48
    def add_sample_rev(self):
 
49
        rev = Revision(timestamp=0,
 
50
                       timezone=None,
 
51
                       committer="Foo Bar <foo@example.com>",
 
52
                       message="Message",
 
53
                       inventory_sha1='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
 
54
                       revision_id='A')
 
55
        self.store.add_revision(rev, self.transaction)
 
56
        return rev
 
57
 
 
58
    def test_has_missing(self):
 
59
        # has of a non present id -> False
 
60
        self.assertFalse(self.store.has_revision_id('missing', self.transaction))
 
61
 
 
62
    def test_has_None(self):
 
63
        # has of None -> True
 
64
        self.assertTrue(self.store.has_revision_id(None, self.transaction))
 
65
 
 
66
    def test_get_revision_none(self):
 
67
        # get_revision(None) -> raises NoSuchRevision
 
68
        self.assertRaises(errors.NoSuchRevision,
 
69
                          self.store.get_revision,
 
70
                          'B',
 
71
                          self.transaction)
 
72
 
 
73
    def test_add_signature_text_missing(self):
 
74
        # add of a text signature for a missing revision must work, to allow
 
75
        # revisions to be added after the signature.
 
76
        self.store.add_revision_signature_text('A', 'foo\nbar', self.transaction)
 
77
        # but must not be visible
 
78
        self.assertRaises(errors.NoSuchRevision,
 
79
                          self.store.has_signature,
 
80
                          'A',
 
81
                          self.transaction)
 
82
        # at all
 
83
        self.assertRaises(errors.NoSuchRevision,
 
84
                          self.store.get_signature_text,
 
85
                          'A',
 
86
                          self.transaction)
 
87
        # until the revision is added
 
88
        self.add_sample_rev()
 
89
        self.assertTrue(self.store.has_signature('A', self.transaction))
 
90
        self.assertEqual('foo\nbar',
 
91
                         self.store.get_signature_text('A', self.transaction))
 
92
    
 
93
    def test_add_signature_text(self):
 
94
        # add a signature to a existing revision works.
 
95
        self.add_sample_rev()
 
96
        self.assertFalse(self.store.has_signature('A', self.transaction))
 
97
        self.assertRaises(errors.NoSuchRevision,
 
98
                          self.store.get_signature_text,
 
99
                          'A',
 
100
                          self.transaction)
 
101
        self.store.add_revision_signature_text('A', 'foo\nbar', self.transaction)
 
102
        self.assertTrue(self.store.has_signature('A', self.transaction))
 
103
        self.assertEqual('foo\nbar',
 
104
                         self.store.get_signature_text('A', self.transaction))
 
105
 
 
106
    def test_total_size(self):
 
107
        # we get a revision count and a numeric size figure from total_size().
 
108
        count, bytes = self.store.total_size(self.transaction)
 
109
        self.assertEqual(0, count)
 
110
        self.assertEqual(0, bytes)
 
111
        self.add_sample_rev()
 
112
        count, bytes = self.store.total_size(self.transaction)
 
113
        self.assertEqual(1, count)
 
114
        self.assertNotEqual(0, bytes)
 
115
        
 
116
    def test_all_revision_ids(self):
 
117
        self.assertEqual([], self.store.all_revision_ids(self.transaction))
 
118
        self.add_sample_rev()
 
119
        self.assertEqual(['A'], self.store.all_revision_ids(self.transaction))