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 (
27
propose as _mod_propose,
37
class SampleMergeProposal(MergeProposal):
38
"""Sample merge proposal."""
41
class SampleHoster(Hoster):
46
def _add_location(cls, url):
47
cls._locations.append(url)
50
def probe_from_url(cls, url, possible_transports=None):
51
for b in cls._locations:
54
raise UnsupportedHoster(url)
56
def hosts(self, branch):
57
for b in self._locations:
58
if branch.user_url.startswith(b):
63
def iter_instances(cls):
66
def get_proposal_by_url(self, url):
67
for b in self._locations:
69
return MergeProposal()
70
raise UnsupportedHoster(url)
73
class SampleHosterTestCase(tests.TestCaseWithTransport):
76
super(SampleHosterTestCase, self).setUp()
77
self._old_hosters = _mod_propose.hosters
78
_mod_propose.hosters = registry.Registry()
79
self.hoster = SampleHoster()
81
SampleHoster._add_location(
82
urlutils.local_path_to_url(os.path.join(self.test_dir, 'hosted')))
83
_mod_propose.hosters.register('sample', self.hoster)
86
super(SampleHosterTestCase, self).tearDown()
87
_mod_propose.hosters = self._old_hosters
88
SampleHoster._locations = []
91
class TestGetHosterTests(SampleHosterTestCase):
93
def test_get_hoster(self):
94
tree = self.make_branch_and_tree('hosted/branch')
95
self.assertIs(self.hoster, get_hoster(tree.branch, [self.hoster]))
96
self.assertIsInstance(get_hoster(tree.branch), SampleHoster)
98
tree = self.make_branch_and_tree('blah')
99
self.assertRaises(UnsupportedHoster, get_hoster, tree.branch)
102
class TestGetProposal(SampleHosterTestCase):
104
def test_get_proposal_by_url(self):
105
self.assertRaises(UnsupportedHoster, get_proposal_by_url, 'blah')
107
url = urlutils.local_path_to_url(os.path.join(self.test_dir, 'hosted', 'proposal'))
108
self.assertIsInstance(get_proposal_by_url(url), MergeProposal)