~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2008-09-08 12:59:00 UTC
  • mfrom: (3695 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3756.
  • Revision ID: andrew.bennetts@canonical.com-20080908125900-8ywtsr7jqyyatjz0
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

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