/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3221.4.2 by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance
1
# Copyright (C) 2008 Canonical Ltd
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for selection of the right Launchpad service by environment"""
18
19
import os
20
3955.3.4 by Jonathan Lange
Some error cases, plus a docstring.
21
from bzrlib import errors
3221.4.2 by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance
22
from bzrlib.tests import TestCase
23
from bzrlib.plugins.launchpad.lp_registration import (
3955.3.5 by Jonathan Lange
Add an untested plugin, make the error handling a little nicer.
24
    InvalidLaunchpadInstance, LaunchpadService, NotLaunchpadBranch)
3221.4.2 by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance
25
26
27
class LaunchpadServiceTests(TestCase):
28
    """Test that the correct Launchpad instance is chosen."""
29
30
    def setUp(self):
31
        super(LaunchpadServiceTests, self).setUp()
32
        # make sure we have a reproducible standard environment
33
        self._captureVar('BZR_LP_XMLRPC_URL', None)
34
35
    def test_default_service(self):
36
        service = LaunchpadService()
37
        self.assertEqual('https://xmlrpc.launchpad.net/bazaar/',
38
                         service.service_url)
39
40
    def test_alter_default_service_url(self):
41
        LaunchpadService.DEFAULT_SERVICE_URL = 'http://example.com/'
42
        try:
43
            service = LaunchpadService()
44
            self.assertEqual('http://example.com/',
45
                             service.service_url)
46
        finally:
47
            LaunchpadService.DEFAULT_SERVICE_URL = \
48
                LaunchpadService.LAUNCHPAD_INSTANCE['production']
49
50
    def test_staging_service(self):
51
        service = LaunchpadService(lp_instance='staging')
52
        self.assertEqual('https://xmlrpc.staging.launchpad.net/bazaar/',
53
                         service.service_url)
54
55
    def test_edge_service(self):
56
        service = LaunchpadService(lp_instance='edge')
57
        self.assertEqual('https://xmlrpc.edge.launchpad.net/bazaar/',
58
                         service.service_url)
59
60
    def test_dev_service(self):
61
        service = LaunchpadService(lp_instance='dev')
3955.3.2 by Jonathan Lange
Tighten up the code a little, changing the dev service to use https,
62
        self.assertEqual('https://xmlrpc.launchpad.dev/bazaar/',
3221.4.2 by Martin Pool
Add in thumpers tests for selection of the right Launchpad instance
63
                         service.service_url)
64
65
    def test_demo_service(self):
66
        service = LaunchpadService(lp_instance='demo')
67
        self.assertEqual('https://xmlrpc.demo.launchpad.net/bazaar/',
68
                         service.service_url)
69
70
    def test_unknown_service(self):
71
        error = self.assertRaises(InvalidLaunchpadInstance,
72
                                  LaunchpadService,
73
                                  lp_instance='fubar')
74
        self.assertEqual('fubar is not a valid Launchpad instance.',
75
                         str(error))
76
77
    def test_environment_overrides_default(self):
78
        os.environ['BZR_LP_XMLRPC_URL'] = 'http://example.com/'
79
        service = LaunchpadService()
80
        self.assertEqual('http://example.com/',
81
                         service.service_url)
82
83
    def test_environment_overrides_specified_service(self):
84
        os.environ['BZR_LP_XMLRPC_URL'] = 'http://example.com/'
85
        service = LaunchpadService(lp_instance='staging')
86
        self.assertEqual('http://example.com/',
87
                         service.service_url)
3955.3.1 by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService,
88
89
90
class TestURLInference(TestCase):
91
    """Test the way we infer Launchpad web pages from branch URLs."""
92
93
    def test_default_bzr_ssh_url(self):
94
        service = LaunchpadService()
95
        web_url = service.get_web_url_from_branch_url(
96
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
97
        self.assertEqual(
98
            'http://code.edge.launchpad.net/~foo/bar/baz', web_url)
99
100
    def test_product_bzr_ssh_url(self):
101
        service = LaunchpadService(lp_instance='production')
102
        web_url = service.get_web_url_from_branch_url(
103
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
104
        self.assertEqual(
105
            'http://code.launchpad.net/~foo/bar/baz', web_url)
106
3955.3.3 by Jonathan Lange
Test a couple more cases.
107
    def test_sftp_branch_url(self):
108
        service = LaunchpadService(lp_instance='production')
109
        web_url = service.get_web_url_from_branch_url(
110
            'sftp://bazaar.launchpad.net/~foo/bar/baz')
111
        self.assertEqual(
112
            'http://code.launchpad.net/~foo/bar/baz', web_url)
113
114
    def test_staging_branch_url(self):
115
        service = LaunchpadService(lp_instance='production')
116
        web_url = service.get_web_url_from_branch_url(
117
            'bzr+ssh://bazaar.staging.launchpad.net/~foo/bar/baz')
118
        self.assertEqual(
119
            'http://code.launchpad.net/~foo/bar/baz', web_url)
120
3955.3.4 by Jonathan Lange
Some error cases, plus a docstring.
121
    def test_non_launchpad_url(self):
122
        service = LaunchpadService()
3955.3.5 by Jonathan Lange
Add an untested plugin, make the error handling a little nicer.
123
        error = self.assertRaises(
124
            NotLaunchpadBranch, service.get_web_url_from_branch_url,
3955.3.4 by Jonathan Lange
Some error cases, plus a docstring.
125
            'bzr+ssh://example.com/~foo/bar/baz')
3955.3.5 by Jonathan Lange
Add an untested plugin, make the error handling a little nicer.
126
        self.assertEqual(
127
            'bzr+ssh://example.com/~foo/bar/baz is not hosted on Launchpad.',
128
            str(error))
3955.3.4 by Jonathan Lange
Some error cases, plus a docstring.
129
130
    def test_dodgy_launchpad_url(self):
131
        service = LaunchpadService()
132
        self.assertRaises(
3955.3.5 by Jonathan Lange
Add an untested plugin, make the error handling a little nicer.
133
            NotLaunchpadBranch, service.get_web_url_from_branch_url,
3955.3.4 by Jonathan Lange
Some error cases, plus a docstring.
134
            'bzr+ssh://launchpad.net/~foo/bar/baz')
135
3955.3.5 by Jonathan Lange
Add an untested plugin, make the error handling a little nicer.
136
    def test_lp_branch_url(self):
137
        service = LaunchpadService(lp_instance='production')
138
        web_url = service.get_web_url_from_branch_url('lp:~foo/bar/baz')
139
        self.assertEqual(
140
            'http://code.launchpad.net/~foo/bar/baz', web_url)
141
3955.3.1 by Jonathan Lange
Start doing URL stuff, extracting the domain bit out of LaunchpadService,
142
    def test_staging_url(self):
143
        service = LaunchpadService(lp_instance='staging')
144
        web_url = service.get_web_url_from_branch_url(
145
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
146
        self.assertEqual(
147
            'http://code.staging.launchpad.net/~foo/bar/baz', web_url)
148
149
    def test_edge_url(self):
150
        service = LaunchpadService(lp_instance='edge')
151
        web_url = service.get_web_url_from_branch_url(
152
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
153
        self.assertEqual(
154
            'http://code.edge.launchpad.net/~foo/bar/baz', web_url)
155
156
    def test_dev_url(self):
157
        service = LaunchpadService(lp_instance='dev')
158
        web_url = service.get_web_url_from_branch_url(
159
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
160
        self.assertEqual(
161
            'http://code.launchpad.dev/~foo/bar/baz', web_url)
162
163
    def test_demo_url(self):
164
        service = LaunchpadService(lp_instance='demo')
165
        web_url = service.get_web_url_from_branch_url(
166
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
167
        self.assertEqual(
168
            'http://code.demo.launchpad.net/~foo/bar/baz', web_url)