/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2010-04-13 04:33:55 UTC
  • mfrom: (5147 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5149.
  • Revision ID: andrew.bennetts@canonical.com-20100413043355-lg3id0uwtju0k3zs
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for selection of the right Launchpad service by environment"""
18
18
 
19
19
import os
 
20
import xmlrpclib
20
21
 
 
22
from bzrlib import errors
 
23
from bzrlib.plugins.launchpad.lp_registration import (
 
24
    InvalidLaunchpadInstance, LaunchpadService, NotLaunchpadBranch)
 
25
from bzrlib.plugins.launchpad.test_lp_directory import FakeResolveFactory
21
26
from bzrlib.tests import TestCase
22
 
from bzrlib.plugins.launchpad.lp_registration import (
23
 
    InvalidLaunchpadInstance, LaunchpadService)
24
27
 
25
28
 
26
29
class LaunchpadServiceTests(TestCase):
58
61
 
59
62
    def test_dev_service(self):
60
63
        service = LaunchpadService(lp_instance='dev')
61
 
        self.assertEqual('http://xmlrpc.launchpad.dev/bazaar/',
 
64
        self.assertEqual('https://xmlrpc.launchpad.dev/bazaar/',
62
65
                         service.service_url)
63
66
 
64
67
    def test_demo_service(self):
84
87
        service = LaunchpadService(lp_instance='staging')
85
88
        self.assertEqual('http://example.com/',
86
89
                         service.service_url)
 
90
 
 
91
 
 
92
class TestURLInference(TestCase):
 
93
    """Test the way we infer Launchpad web pages from branch URLs."""
 
94
 
 
95
    def test_default_bzr_ssh_url(self):
 
96
        service = LaunchpadService()
 
97
        web_url = service.get_web_url_from_branch_url(
 
98
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
 
99
        self.assertEqual(
 
100
            'https://code.edge.launchpad.net/~foo/bar/baz', web_url)
 
101
 
 
102
    def test_product_bzr_ssh_url(self):
 
103
        service = LaunchpadService(lp_instance='production')
 
104
        web_url = service.get_web_url_from_branch_url(
 
105
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
 
106
        self.assertEqual(
 
107
            'https://code.launchpad.net/~foo/bar/baz', web_url)
 
108
 
 
109
    def test_sftp_branch_url(self):
 
110
        service = LaunchpadService(lp_instance='production')
 
111
        web_url = service.get_web_url_from_branch_url(
 
112
            'sftp://bazaar.launchpad.net/~foo/bar/baz')
 
113
        self.assertEqual(
 
114
            'https://code.launchpad.net/~foo/bar/baz', web_url)
 
115
 
 
116
    def test_staging_branch_url(self):
 
117
        service = LaunchpadService(lp_instance='production')
 
118
        web_url = service.get_web_url_from_branch_url(
 
119
            'bzr+ssh://bazaar.staging.launchpad.net/~foo/bar/baz')
 
120
        self.assertEqual(
 
121
            'https://code.launchpad.net/~foo/bar/baz', web_url)
 
122
 
 
123
    def test_non_launchpad_url(self):
 
124
        service = LaunchpadService()
 
125
        error = self.assertRaises(
 
126
            NotLaunchpadBranch, service.get_web_url_from_branch_url,
 
127
            'bzr+ssh://example.com/~foo/bar/baz')
 
128
        self.assertEqual(
 
129
            'bzr+ssh://example.com/~foo/bar/baz is not registered on Launchpad.',
 
130
            str(error))
 
131
 
 
132
    def test_dodgy_launchpad_url(self):
 
133
        service = LaunchpadService()
 
134
        self.assertRaises(
 
135
            NotLaunchpadBranch, service.get_web_url_from_branch_url,
 
136
            'bzr+ssh://launchpad.net/~foo/bar/baz')
 
137
 
 
138
    def test_lp_branch_url(self):
 
139
        service = LaunchpadService(lp_instance='production')
 
140
        factory = FakeResolveFactory(
 
141
            self, '~foo/bar/baz',
 
142
            dict(urls=['http://bazaar.launchpad.net/~foo/bar/baz']))
 
143
        web_url = service.get_web_url_from_branch_url(
 
144
            'lp:~foo/bar/baz', factory)
 
145
        self.assertEqual(
 
146
            'https://code.launchpad.net/~foo/bar/baz', web_url)
 
147
 
 
148
    def test_lp_branch_shortcut(self):
 
149
        service = LaunchpadService()
 
150
        factory = FakeResolveFactory(
 
151
            self, 'foo',
 
152
            dict(urls=['http://bazaar.launchpad.net/~foo/bar/baz']))
 
153
        web_url = service.get_web_url_from_branch_url('lp:foo', factory)
 
154
        self.assertEqual(
 
155
            'https://code.edge.launchpad.net/~foo/bar/baz', web_url)
 
156
 
 
157
    def test_lp_branch_fault(self):
 
158
        service = LaunchpadService()
 
159
        factory = FakeResolveFactory(self, 'foo', None)
 
160
        def submit(service):
 
161
            raise xmlrpclib.Fault(42, 'something went wrong')
 
162
        factory.submit = submit
 
163
        self.assertRaises(
 
164
            errors.InvalidURL, service.get_web_url_from_branch_url, 'lp:foo',
 
165
            factory)
 
166
 
 
167
    def test_staging_url(self):
 
168
        service = LaunchpadService(lp_instance='staging')
 
169
        web_url = service.get_web_url_from_branch_url(
 
170
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
 
171
        self.assertEqual(
 
172
            'https://code.staging.launchpad.net/~foo/bar/baz', web_url)
 
173
 
 
174
    def test_edge_url(self):
 
175
        service = LaunchpadService(lp_instance='edge')
 
176
        web_url = service.get_web_url_from_branch_url(
 
177
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
 
178
        self.assertEqual(
 
179
            'https://code.edge.launchpad.net/~foo/bar/baz', web_url)
 
180
 
 
181
    def test_dev_url(self):
 
182
        service = LaunchpadService(lp_instance='dev')
 
183
        web_url = service.get_web_url_from_branch_url(
 
184
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
 
185
        self.assertEqual(
 
186
            'https://code.launchpad.dev/~foo/bar/baz', web_url)
 
187
 
 
188
    def test_demo_url(self):
 
189
        service = LaunchpadService(lp_instance='demo')
 
190
        web_url = service.get_web_url_from_branch_url(
 
191
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
 
192
        self.assertEqual(
 
193
            'https://code.demo.launchpad.net/~foo/bar/baz', web_url)