~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/launchpad/test_lp_service.py

  • Committer: Andrew Bennetts
  • Date: 2008-03-27 06:10:18 UTC
  • mfrom: (3309 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3320.
  • Revision ID: andrew.bennetts@canonical.com-20080327061018-dxztpxyv6yoeg3am
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
21
from bzrlib.tests import TestCase
 
22
from bzrlib.plugins.launchpad.lp_registration import (
 
23
    InvalidLaunchpadInstance, LaunchpadService)
 
24
 
 
25
 
 
26
class LaunchpadServiceTests(TestCase):
 
27
    """Test that the correct Launchpad instance is chosen."""
 
28
 
 
29
    def setUp(self):
 
30
        super(LaunchpadServiceTests, self).setUp()
 
31
        # make sure we have a reproducible standard environment
 
32
        self._captureVar('BZR_LP_XMLRPC_URL', None)
 
33
 
 
34
    def test_default_service(self):
 
35
        service = LaunchpadService()
 
36
        self.assertEqual('https://xmlrpc.launchpad.net/bazaar/',
 
37
                         service.service_url)
 
38
 
 
39
    def test_alter_default_service_url(self):
 
40
        LaunchpadService.DEFAULT_SERVICE_URL = 'http://example.com/'
 
41
        try:
 
42
            service = LaunchpadService()
 
43
            self.assertEqual('http://example.com/',
 
44
                             service.service_url)
 
45
        finally:
 
46
            LaunchpadService.DEFAULT_SERVICE_URL = \
 
47
                LaunchpadService.LAUNCHPAD_INSTANCE['production']
 
48
 
 
49
    def test_staging_service(self):
 
50
        service = LaunchpadService(lp_instance='staging')
 
51
        self.assertEqual('https://xmlrpc.staging.launchpad.net/bazaar/',
 
52
                         service.service_url)
 
53
 
 
54
    def test_edge_service(self):
 
55
        service = LaunchpadService(lp_instance='edge')
 
56
        self.assertEqual('https://xmlrpc.edge.launchpad.net/bazaar/',
 
57
                         service.service_url)
 
58
 
 
59
    def test_dev_service(self):
 
60
        service = LaunchpadService(lp_instance='dev')
 
61
        self.assertEqual('http://xmlrpc.launchpad.dev/bazaar/',
 
62
                         service.service_url)
 
63
 
 
64
    def test_demo_service(self):
 
65
        service = LaunchpadService(lp_instance='demo')
 
66
        self.assertEqual('https://xmlrpc.demo.launchpad.net/bazaar/',
 
67
                         service.service_url)
 
68
 
 
69
    def test_unknown_service(self):
 
70
        error = self.assertRaises(InvalidLaunchpadInstance,
 
71
                                  LaunchpadService,
 
72
                                  lp_instance='fubar')
 
73
        self.assertEqual('fubar is not a valid Launchpad instance.',
 
74
                         str(error))
 
75
 
 
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/',
 
80
                         service.service_url)
 
81
 
 
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/',
 
86
                         service.service_url)