/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4379.2.1 by John Arbash Meinel
Change the fallback repository code to only lock/unlock on transition.
1
# Copyright (C) 2009 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
4379.2.2 by John Arbash Meinel
Change the Repository.add_fallback_repository() contract slightly.
17
"""Tests for locking/unlocking a repository with external references."""
4379.2.1 by John Arbash Meinel
Change the fallback repository code to only lock/unlock on transition.
18
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
19
from breezy import (
4379.2.1 by John Arbash Meinel
Change the fallback repository code to only lock/unlock on transition.
20
    branch,
21
    errors,
22
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
23
from breezy.tests.per_repository_reference import (
4379.2.1 by John Arbash Meinel
Change the fallback repository code to only lock/unlock on transition.
24
    TestCaseWithExternalReferenceRepository,
25
    )
26
27
28
class TestUnlock(TestCaseWithExternalReferenceRepository):
29
30
    def create_stacked_branch(self):
31
        builder = self.make_branch_builder('source',
32
                                           format=self.bzrdir_format)
33
        builder.start_series()
34
        repo = builder.get_branch().repository
35
        if not repo._format.supports_external_lookups:
36
            raise tests.TestNotApplicable('format does not support stacking')
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
37
        builder.build_snapshot(None, [
6973.6.2 by Jelmer Vernooij
Fix more tests.
38
            ('add', ('', b'root-id', 'directory', None)),
39
            ('add', ('file', b'file-id', 'file', b'contents\n'))],
6973.5.2 by Jelmer Vernooij
Add more bees.
40
            revision_id=b'A-id')
6973.6.2 by Jelmer Vernooij
Fix more tests.
41
        builder.build_snapshot([b'A-id'], [
42
            ('modify', ('file', b'new-content\n'))],
6973.5.2 by Jelmer Vernooij
Add more bees.
43
            revision_id=b'B-id')
6973.6.2 by Jelmer Vernooij
Fix more tests.
44
        builder.build_snapshot([b'B-id'], [
45
            ('modify', ('file', b'yet more content\n'))],
6973.5.2 by Jelmer Vernooij
Add more bees.
46
            revision_id=b'C-id')
4379.2.1 by John Arbash Meinel
Change the fallback repository code to only lock/unlock on transition.
47
        builder.finish_series()
48
        source_b = builder.get_branch()
49
        source_b.lock_read()
50
        self.addCleanup(source_b.unlock)
51
        base = self.make_branch('base')
6973.6.2 by Jelmer Vernooij
Fix more tests.
52
        base.pull(source_b, stop_revision=b'B-id')
4379.2.1 by John Arbash Meinel
Change the fallback repository code to only lock/unlock on transition.
53
        stacked = self.make_branch('stacked')
54
        stacked.set_stacked_on_url('../base')
6973.6.2 by Jelmer Vernooij
Fix more tests.
55
        stacked.pull(source_b, stop_revision=b'C-id')
4379.2.1 by John Arbash Meinel
Change the fallback repository code to only lock/unlock on transition.
56
57
        return base, stacked
58
59
    def test_unlock_unlocks_fallback(self):
60
        base = self.make_branch('base')
61
        stacked = self.make_branch('stacked')
62
        repo = stacked.repository
63
        stacked.set_stacked_on_url('../base')
64
        self.assertEqual(1, len(repo._fallback_repositories))
65
        fallback_repo = repo._fallback_repositories[0]
66
        self.assertFalse(repo.is_locked())
67
        self.assertFalse(fallback_repo.is_locked())
68
        repo.lock_read()
69
        self.assertTrue(repo.is_locked())
70
        self.assertTrue(fallback_repo.is_locked())
71
        repo.unlock()
72
        self.assertFalse(repo.is_locked())
73
        self.assertFalse(fallback_repo.is_locked())
74
        repo.lock_write()
75
        self.assertTrue(repo.is_locked())
76
        self.assertTrue(fallback_repo.is_locked())
77
        repo.unlock()
78
        self.assertFalse(repo.is_locked())
79
        self.assertFalse(fallback_repo.is_locked())