~bzr-pqm/bzr/bzr.dev

3221.10.2 by Robert Collins
More external reference tests.
1
# Copyright (C) 2008 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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3221.10.2 by Robert Collins
More external reference tests.
16
17
"""Tests for add_revision on a repository with external references."""
18
19
from bzrlib import errors
3474.2.1 by Martin Pool
Merge and cleanup pre-external-reference-repository tests
20
from bzrlib.tests.per_repository_reference import (
3221.10.2 by Robert Collins
More external reference tests.
21
    TestCaseWithExternalReferenceRepository,
22
    )
23
24
25
class TestAddRevision(TestCaseWithExternalReferenceRepository):
26
27
    def test_add_revision_goes_to_repo(self):
28
        # adding a revision only writes to the repository add_revision is
29
        # called on.
30
        tree = self.make_branch_and_tree('sample')
31
        revid = tree.commit('one')
32
        inv = tree.branch.repository.get_inventory(revid)
4245.1.1 by Ian Clatworthy
minor test clean-ups & _reconcile_pack API
33
        tree.lock_read()
34
        self.addCleanup(tree.unlock)
3221.10.2 by Robert Collins
More external reference tests.
35
        rev = tree.branch.repository.get_revision(revid)
36
        base = self.make_repository('base')
6182.1.5 by Jelmer Vernooij
Fix more tests.
37
        repo = self.make_referring('referring', base)
3221.10.2 by Robert Collins
More external reference tests.
38
        repo.lock_write()
39
        try:
40
            repo.start_write_group()
41
            try:
42
                rev = tree.branch.repository.get_revision(revid)
4634.35.17 by Andrew Bennetts
Fix more test fallout.
43
                repo.texts.add_lines((inv.root.file_id, revid), [], [])
3221.10.2 by Robert Collins
More external reference tests.
44
                repo.add_revision(revid, rev, inv=inv)
45
            except:
46
                repo.abort_write_group()
47
                raise
48
            else:
49
                repo.commit_write_group()
50
        finally:
51
            repo.unlock()
52
        rev2 = repo.get_revision(revid)
53
        self.assertEqual(rev, rev2)
54
        self.assertRaises(errors.NoSuchRevision, base.get_revision, revid)