1
# Copyright (C) 2019 Breezy Developers
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.
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.
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
19
from ..propose import (
28
propose as _mod_propose,
38
class SampleMergeProposal(MergeProposal):
39
"""Sample merge proposal."""
42
class SampleHoster(Hoster):
47
def _add_location(cls, url):
48
cls._locations.append(url)
51
def probe_from_url(cls, url, possible_transports=None):
52
for b in cls._locations:
55
raise UnsupportedHoster(url)
57
def hosts(self, branch):
58
for b in self._locations:
59
if branch.user_url.startswith(b):
64
def iter_instances(cls):
67
def get_proposal_by_url(self, url):
68
for b in self._locations:
70
return MergeProposal()
71
raise UnsupportedHoster(url)
74
class SampleHosterTestCase(tests.TestCaseWithTransport):
77
super(SampleHosterTestCase, self).setUp()
78
self._old_hosters = _mod_propose.hosters
79
_mod_propose.hosters = registry.Registry()
80
self.hoster = SampleHoster()
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)
87
super(SampleHosterTestCase, self).tearDown()
88
_mod_propose.hosters = self._old_hosters
89
SampleHoster._locations = []
92
class TestGetHosterTests(SampleHosterTestCase):
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)
99
tree = self.make_branch_and_tree('blah')
100
self.assertRaises(UnsupportedHoster, get_hoster, tree.branch)
103
class TestGetProposal(SampleHosterTestCase):
105
def test_get_proposal_by_url(self):
106
self.assertRaises(UnsupportedHoster, get_proposal_by_url, 'blah')
108
url = urlutils.local_path_to_url(os.path.join(self.test_dir, 'hosted', 'proposal'))
109
self.assertIsInstance(get_proposal_by_url(url), MergeProposal)
112
class DetermineTitleTests(tests.TestCase):
114
def test_determine_title(self):
115
self.assertEqual('Make some change', determine_title("""\
118
And here are some more details.