~bzr-pqm/bzr/bzr.dev

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
# Copyright (C) 2006 by Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

"""Revision store tests."""


import bzrlib.errors as errors
from bzrlib.revision import Revision
from bzrlib.store.revision import RevisionStore
from bzrlib.tests import TestCaseWithTransport
from bzrlib.transactions import PassThroughTransaction
from bzrlib.tree import EmptyTree


class TestFactory(TestCaseWithTransport):

    def test_factory_keeps_smoke_in(self):
        s = self.store_factory.create(self.get_url('.'))
        self.assertTrue(isinstance(s, RevisionStore))


class TestAll(TestCaseWithTransport):

    def setUp(self):
        super(TestAll, self).setUp()
        self.store = self.store_factory.create(self.get_url('.'))
        self.transaction = PassThroughTransaction()

    def test_add_has_get(self):
        rev = self.add_sample_rev()
        self.assertTrue(self.store.has_revision_id('A', self.transaction))
        rev2 = self.store.get_revision('A', self.transaction)
        self.assertEqual(rev, rev2)

    def add_sample_rev(self):
        rev = Revision(timestamp=0,
                       timezone=None,
                       committer="Foo Bar <foo@example.com>",
                       message="Message",
                       inventory_sha1='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
                       revision_id='A')
        self.store.add_revision(rev, self.transaction)
        return rev

    def test_has_missing(self):
        # has of a non present id -> False
        self.assertFalse(self.store.has_revision_id('missing', self.transaction))

    def test_has_None(self):
        # has of None -> True
        self.assertTrue(self.store.has_revision_id(None, self.transaction))

    def test_get_revision_none(self):
        # get_revision(None) -> raises NoSuchRevision
        self.assertRaises(errors.NoSuchRevision,
                          self.store.get_revision,
                          'B',
                          self.transaction)

    def test_add_signature_text_missing(self):
        # add of a text signature for a missing revision -> NoSuchRevision
        self.assertRaises(errors.NoSuchRevision,
                          self.store.add_revision_signature_text,
                          'B',
                          'foo\nbar',
                          self.transaction)

    def test_total_size(self):
        # we get a revision count and a numeric size figure from total_size().
        count, bytes = self.store.total_size(self.transaction)
        self.assertEqual(0, count)
        self.assertEqual(0, bytes)
        self.add_sample_rev()
        count, bytes = self.store.total_size(self.transaction)
        self.assertEqual(1, count)
        self.assertNotEqual(0, bytes)