/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2008-2011 Canonical Ltd
3221.4.2 by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance
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.4.2 by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance
16
17
"""Tests for selection of the right Launchpad service by environment"""
18
19
import os
6973.12.9 by Jelmer Vernooij
More fixes.
20
try:
21
    from xmlrpc.client import Fault
22
except ImportError:  # python < 3
23
    from xmlrpclib import Fault
3221.4.2 by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance
24
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
25
from ... import errors
26
from .lp_registration import (
6729.6.1 by Jelmer Vernooij
Move urlutils errors.
27
    InvalidURL,
28
    InvalidLaunchpadInstance,
29
    LaunchpadService,
30
    NotLaunchpadBranch,
31
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
32
from .test_lp_directory import FakeResolveFactory
33
from ...tests import TestCase
3221.4.2 by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance
34
35
36
class LaunchpadServiceTests(TestCase):
37
    """Test that the correct Launchpad instance is chosen."""
38
39
    def setUp(self):
40
        super(LaunchpadServiceTests, self).setUp()
41
        # make sure we have a reproducible standard environment
6622.1.28 by Jelmer Vernooij
More renames; commands in output, environment variables.
42
        self.overrideEnv('BRZ_LP_XMLRPC_URL', None)
3221.4.2 by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance
43
44
    def test_default_service(self):
45
        service = LaunchpadService()
46
        self.assertEqual('https://xmlrpc.launchpad.net/bazaar/',
47
                         service.service_url)
48
49
    def test_alter_default_service_url(self):
50
        LaunchpadService.DEFAULT_SERVICE_URL = 'http://example.com/'
51
        try:
52
            service = LaunchpadService()
53
            self.assertEqual('http://example.com/',
54
                             service.service_url)
55
        finally:
56
            LaunchpadService.DEFAULT_SERVICE_URL = \
57
                LaunchpadService.LAUNCHPAD_INSTANCE['production']
58
59
    def test_staging_service(self):
60
        service = LaunchpadService(lp_instance='staging')
61
        self.assertEqual('https://xmlrpc.staging.launchpad.net/bazaar/',
62
                         service.service_url)
63
64
    def test_dev_service(self):
65
        service = LaunchpadService(lp_instance='dev')
3955.3.2 by Jonathan Lange
Tighten up the code a little, changing the dev service to use https,
66
        self.assertEqual('https://xmlrpc.launchpad.dev/bazaar/',
3221.4.2 by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance
67
                         service.service_url)
68
69
    def test_demo_service(self):
70
        service = LaunchpadService(lp_instance='demo')
71
        self.assertEqual('https://xmlrpc.demo.launchpad.net/bazaar/',
72
                         service.service_url)
73
74
    def test_unknown_service(self):
75
        error = self.assertRaises(InvalidLaunchpadInstance,
76
                                  LaunchpadService,
77
                                  lp_instance='fubar')
78
        self.assertEqual('fubar is not a valid Launchpad instance.',
79
                         str(error))
80
81
    def test_environment_overrides_default(self):
6622.1.28 by Jelmer Vernooij
More renames; commands in output, environment variables.
82
        os.environ['BRZ_LP_XMLRPC_URL'] = 'http://example.com/'
3221.4.2 by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance
83
        service = LaunchpadService()
84
        self.assertEqual('http://example.com/',
85
                         service.service_url)
86
87
    def test_environment_overrides_specified_service(self):
6622.1.28 by Jelmer Vernooij
More renames; commands in output, environment variables.
88
        os.environ['BRZ_LP_XMLRPC_URL'] = 'http://example.com/'
3221.4.2 by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance
89
        service = LaunchpadService(lp_instance='staging')
90
        self.assertEqual('http://example.com/',
91
                         service.service_url)
3955.3.1 by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService,
92
93
94
class TestURLInference(TestCase):
95
    """Test the way we infer Launchpad web pages from branch URLs."""
96
97
    def test_default_bzr_ssh_url(self):
98
        service = LaunchpadService()
99
        web_url = service.get_web_url_from_branch_url(
100
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
101
        self.assertEqual(
5243.1.1 by Martin
Use the production server in the launchpad plugin rather than edge
102
            'https://code.launchpad.net/~foo/bar/baz', web_url)
3955.3.1 by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService,
103
104
    def test_product_bzr_ssh_url(self):
105
        service = LaunchpadService(lp_instance='production')
106
        web_url = service.get_web_url_from_branch_url(
107
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
108
        self.assertEqual(
3955.3.7 by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs.
109
            'https://code.launchpad.net/~foo/bar/baz', web_url)
3955.3.1 by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService,
110
3955.3.3 by Jonathan Lange
Test a couple more cases.
111
    def test_sftp_branch_url(self):
112
        service = LaunchpadService(lp_instance='production')
113
        web_url = service.get_web_url_from_branch_url(
114
            'sftp://bazaar.launchpad.net/~foo/bar/baz')
115
        self.assertEqual(
3955.3.7 by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs.
116
            'https://code.launchpad.net/~foo/bar/baz', web_url)
3955.3.3 by Jonathan Lange
Test a couple more cases.
117
118
    def test_staging_branch_url(self):
119
        service = LaunchpadService(lp_instance='production')
120
        web_url = service.get_web_url_from_branch_url(
121
            'bzr+ssh://bazaar.staging.launchpad.net/~foo/bar/baz')
122
        self.assertEqual(
3955.3.7 by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs.
123
            'https://code.launchpad.net/~foo/bar/baz', web_url)
3955.3.3 by Jonathan Lange
Test a couple more cases.
124
3955.3.4 by Jonathan Lange
Some error cases, plus a docstring.
125
    def test_non_launchpad_url(self):
126
        service = LaunchpadService()
3955.3.5 by Jonathan Lange
Add an untested plugin, make the error handling a little nicer.
127
        error = self.assertRaises(
128
            NotLaunchpadBranch, service.get_web_url_from_branch_url,
3955.3.4 by Jonathan Lange
Some error cases, plus a docstring.
129
            'bzr+ssh://example.com/~foo/bar/baz')
3955.3.5 by Jonathan Lange
Add an untested plugin, make the error handling a little nicer.
130
        self.assertEqual(
4031.2.11 by John Arbash Meinel
Turn a bunch of imports into lazy imports.
131
            'bzr+ssh://example.com/~foo/bar/baz is not registered on Launchpad.',
3955.3.5 by Jonathan Lange
Add an untested plugin, make the error handling a little nicer.
132
            str(error))
3955.3.4 by Jonathan Lange
Some error cases, plus a docstring.
133
134
    def test_dodgy_launchpad_url(self):
135
        service = LaunchpadService()
136
        self.assertRaises(
3955.3.5 by Jonathan Lange
Add an untested plugin, make the error handling a little nicer.
137
            NotLaunchpadBranch, service.get_web_url_from_branch_url,
3955.3.4 by Jonathan Lange
Some error cases, plus a docstring.
138
            'bzr+ssh://launchpad.net/~foo/bar/baz')
139
3955.3.5 by Jonathan Lange
Add an untested plugin, make the error handling a little nicer.
140
    def test_lp_branch_url(self):
141
        service = LaunchpadService(lp_instance='production')
3955.3.8 by Jonathan Lange
Support lp URL shortcuts.
142
        factory = FakeResolveFactory(
143
            self, '~foo/bar/baz',
144
            dict(urls=['http://bazaar.launchpad.net/~foo/bar/baz']))
145
        web_url = service.get_web_url_from_branch_url(
146
            'lp:~foo/bar/baz', factory)
3955.3.5 by Jonathan Lange
Add an untested plugin, make the error handling a little nicer.
147
        self.assertEqual(
3955.3.7 by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs.
148
            'https://code.launchpad.net/~foo/bar/baz', web_url)
3955.3.5 by Jonathan Lange
Add an untested plugin, make the error handling a little nicer.
149
3955.3.8 by Jonathan Lange
Support lp URL shortcuts.
150
    def test_lp_branch_shortcut(self):
151
        service = LaunchpadService()
152
        factory = FakeResolveFactory(
153
            self, 'foo',
154
            dict(urls=['http://bazaar.launchpad.net/~foo/bar/baz']))
155
        web_url = service.get_web_url_from_branch_url('lp:foo', factory)
156
        self.assertEqual(
5243.1.1 by Martin
Use the production server in the launchpad plugin rather than edge
157
            'https://code.launchpad.net/~foo/bar/baz', web_url)
3955.3.8 by Jonathan Lange
Support lp URL shortcuts.
158
3955.3.9 by Jonathan Lange
Catch errors.
159
    def test_lp_branch_fault(self):
160
        service = LaunchpadService()
161
        factory = FakeResolveFactory(self, 'foo', None)
162
        def submit(service):
6973.12.9 by Jelmer Vernooij
More fixes.
163
            raise Fault(42, 'something went wrong')
3955.3.9 by Jonathan Lange
Catch errors.
164
        factory.submit = submit
165
        self.assertRaises(
6729.6.1 by Jelmer Vernooij
Move urlutils errors.
166
            InvalidURL, service.get_web_url_from_branch_url, 'lp:foo',
3955.3.9 by Jonathan Lange
Catch errors.
167
            factory)
168
3955.3.1 by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService,
169
    def test_staging_url(self):
170
        service = LaunchpadService(lp_instance='staging')
171
        web_url = service.get_web_url_from_branch_url(
172
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
173
        self.assertEqual(
3955.3.7 by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs.
174
            'https://code.staging.launchpad.net/~foo/bar/baz', web_url)
3955.3.1 by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService,
175
176
    def test_dev_url(self):
177
        service = LaunchpadService(lp_instance='dev')
178
        web_url = service.get_web_url_from_branch_url(
179
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
180
        self.assertEqual(
3955.3.7 by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs.
181
            'https://code.launchpad.dev/~foo/bar/baz', web_url)
3955.3.1 by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService,
182
183
    def test_demo_url(self):
184
        service = LaunchpadService(lp_instance='demo')
185
        web_url = service.get_web_url_from_branch_url(
186
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
187
        self.assertEqual(
3955.3.7 by Jonathan Lange
Test the launchpad-open command. Fix up some minor bugs.
188
            'https://code.demo.launchpad.net/~foo/bar/baz', web_url)