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