~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/repository_implementations/test_commit_builder.py

  • Committer: Martin Pool
  • Date: 2006-06-20 07:55:43 UTC
  • mfrom: (1798 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1799.
  • Revision ID: mbp@sourcefrog.net-20060620075543-b10f6575d4a4fa32
[merge] bzr.dev

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
"""Tests for repository commit builder."""
 
18
 
 
19
from bzrlib.errors import UnsupportedOperation
 
20
from bzrlib.repository import CommitBuilder
 
21
from bzrlib.tests.repository_implementations.test_repository import TestCaseWithRepository
 
22
 
 
23
 
 
24
class TestCommitBuilder(TestCaseWithRepository):
 
25
 
 
26
    def test_get_commit_builder(self):
 
27
        tree = self.make_branch_and_tree(".")
 
28
        builder = tree.branch.get_commit_builder([])
 
29
        self.assertIsInstance(builder, CommitBuilder)
 
30
 
 
31
    def test_finish_inventory(self):
 
32
        tree = self.make_branch_and_tree(".")
 
33
        builder = tree.branch.get_commit_builder([])
 
34
        builder.finish_inventory()
 
35
 
 
36
    def test_commit_message(self):
 
37
        tree = self.make_branch_and_tree(".")
 
38
        builder = tree.branch.get_commit_builder([])
 
39
        builder.finish_inventory()
 
40
        rev_id = builder.commit('foo bar blah')
 
41
        rev = tree.branch.repository.get_revision(rev_id)
 
42
        self.assertEqual('foo bar blah', rev.message)
 
43
 
 
44
    def test_commit_with_revision_id(self):
 
45
        tree = self.make_branch_and_tree(".")
 
46
        try:
 
47
            builder = tree.branch.get_commit_builder([], revision_id="foo")
 
48
        except UnsupportedOperation:
 
49
            # This format doesn't support supplied revision ids
 
50
            return
 
51
        builder.finish_inventory()
 
52
        self.assertEqual("foo", builder.commit('foo bar'))
 
53
        self.assertTrue(tree.branch.repository.has_revision("foo"))
 
54
        # the revision id must be set on the inventory when saving it. This does not
 
55
        # precisely test that - a repository that wants to can add it on deserialisation,
 
56
        # but thats all the current contract guarantees anyway.
 
57
        self.assertEqual('foo', tree.branch.repository.get_inventory('foo').revision_id)
 
58
 
 
59
    def test_commit(self):
 
60
        tree = self.make_branch_and_tree(".")
 
61
        builder = tree.branch.get_commit_builder([])
 
62
        builder.finish_inventory()
 
63
        rev_id = builder.commit('foo bar')
 
64
        self.assertNotEqual(None, rev_id)
 
65
        self.assertTrue(tree.branch.repository.has_revision(rev_id))
 
66
        # the revision id must be set on the inventory when saving it. This does not
 
67
        # precisely test that - a repository that wants to can add it on deserialisation,
 
68
        # but thats all the current contract guarantees anyway.
 
69
        self.assertEqual(rev_id, tree.branch.repository.get_inventory(rev_id).revision_id)