/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_propose.py

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2019 Breezy Developers
 
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
 
 
17
import os
 
18
 
 
19
from ..propose import (
 
20
    determine_title,
 
21
    get_proposal_by_url,
 
22
    get_hoster,
 
23
    Hoster,
 
24
    MergeProposal,
 
25
    UnsupportedHoster,
 
26
    )
 
27
from .. import (
 
28
    propose as _mod_propose,
 
29
    registry,
 
30
    urlutils,
 
31
    )
 
32
 
 
33
from .. import (
 
34
    tests,
 
35
    )
 
36
 
 
37
 
 
38
class SampleMergeProposal(MergeProposal):
 
39
    """Sample merge proposal."""
 
40
 
 
41
 
 
42
class SampleHoster(Hoster):
 
43
 
 
44
    _locations = []
 
45
 
 
46
    @classmethod
 
47
    def _add_location(cls, url):
 
48
        cls._locations.append(url)
 
49
 
 
50
    @classmethod
 
51
    def probe_from_url(cls, url, possible_transports=None):
 
52
        for b in cls._locations:
 
53
            if url.startswith(b):
 
54
                return cls()
 
55
        raise UnsupportedHoster(url)
 
56
 
 
57
    def hosts(self, branch):
 
58
        for b in self._locations:
 
59
            if branch.user_url.startswith(b):
 
60
                return True
 
61
        return False
 
62
 
 
63
    @classmethod
 
64
    def iter_instances(cls):
 
65
        return iter([cls()])
 
66
 
 
67
    def get_proposal_by_url(self, url):
 
68
        for b in self._locations:
 
69
            if url.startswith(b):
 
70
                return MergeProposal()
 
71
        raise UnsupportedHoster(url)
 
72
 
 
73
 
 
74
class SampleHosterTestCase(tests.TestCaseWithTransport):
 
75
 
 
76
    def setUp(self):
 
77
        super(SampleHosterTestCase, self).setUp()
 
78
        self._old_hosters = _mod_propose.hosters
 
79
        _mod_propose.hosters = registry.Registry()
 
80
        self.hoster = SampleHoster()
 
81
        os.mkdir('hosted')
 
82
        SampleHoster._add_location(
 
83
            urlutils.local_path_to_url(os.path.join(self.test_dir, 'hosted')))
 
84
        _mod_propose.hosters.register('sample', self.hoster)
 
85
 
 
86
    def tearDown(self):
 
87
        super(SampleHosterTestCase, self).tearDown()
 
88
        _mod_propose.hosters = self._old_hosters
 
89
        SampleHoster._locations = []
 
90
 
 
91
 
 
92
class TestGetHosterTests(SampleHosterTestCase):
 
93
 
 
94
    def test_get_hoster(self):
 
95
        tree = self.make_branch_and_tree('hosted/branch')
 
96
        self.assertIs(self.hoster, get_hoster(tree.branch, [self.hoster]))
 
97
        self.assertIsInstance(get_hoster(tree.branch), SampleHoster)
 
98
 
 
99
        tree = self.make_branch_and_tree('blah')
 
100
        self.assertRaises(UnsupportedHoster, get_hoster, tree.branch)
 
101
 
 
102
 
 
103
class TestGetProposal(SampleHosterTestCase):
 
104
 
 
105
    def test_get_proposal_by_url(self):
 
106
        self.assertRaises(UnsupportedHoster, get_proposal_by_url, 'blah')
 
107
 
 
108
        url = urlutils.local_path_to_url(os.path.join(self.test_dir, 'hosted', 'proposal'))
 
109
        self.assertIsInstance(get_proposal_by_url(url), MergeProposal)
 
110
 
 
111
 
 
112
class DetermineTitleTests(tests.TestCase):
 
113
 
 
114
    def test_determine_title(self):
 
115
        self.assertEqual('Make some change', determine_title("""\
 
116
Make some change.
 
117
 
 
118
And here are some more details.
 
119
"""))