1
# Copyright (C) 2008 Canonical Ltd
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Tests for selection of the right Launchpad service by environment"""
21
from bzrlib.tests import TestCase
22
from bzrlib.plugins.launchpad.lp_registration import (
23
InvalidLaunchpadInstance, LaunchpadService)
26
class LaunchpadServiceTests(TestCase):
27
"""Test that the correct Launchpad instance is chosen."""
30
super(LaunchpadServiceTests, self).setUp()
31
# make sure we have a reproducible standard environment
32
self._captureVar('BZR_LP_XMLRPC_URL', None)
34
def test_default_service(self):
35
service = LaunchpadService()
36
self.assertEqual('https://xmlrpc.launchpad.net/bazaar/',
39
def test_alter_default_service_url(self):
40
LaunchpadService.DEFAULT_SERVICE_URL = 'http://example.com/'
42
service = LaunchpadService()
43
self.assertEqual('http://example.com/',
46
LaunchpadService.DEFAULT_SERVICE_URL = \
47
LaunchpadService.LAUNCHPAD_INSTANCE['production']
49
def test_staging_service(self):
50
service = LaunchpadService(lp_instance='staging')
51
self.assertEqual('https://xmlrpc.staging.launchpad.net/bazaar/',
54
def test_edge_service(self):
55
service = LaunchpadService(lp_instance='edge')
56
self.assertEqual('https://xmlrpc.edge.launchpad.net/bazaar/',
59
def test_dev_service(self):
60
service = LaunchpadService(lp_instance='dev')
61
self.assertEqual('http://xmlrpc.launchpad.dev/bazaar/',
64
def test_demo_service(self):
65
service = LaunchpadService(lp_instance='demo')
66
self.assertEqual('https://xmlrpc.demo.launchpad.net/bazaar/',
69
def test_unknown_service(self):
70
error = self.assertRaises(InvalidLaunchpadInstance,
73
self.assertEqual('fubar is not a valid Launchpad instance.',
76
def test_environment_overrides_default(self):
77
os.environ['BZR_LP_XMLRPC_URL'] = 'http://example.com/'
78
service = LaunchpadService()
79
self.assertEqual('http://example.com/',
82
def test_environment_overrides_specified_service(self):
83
os.environ['BZR_LP_XMLRPC_URL'] = 'http://example.com/'
84
service = LaunchpadService(lp_instance='staging')
85
self.assertEqual('http://example.com/',