~bzr-pqm/bzr/bzr.dev

3955.3.10 by Jonathan Lange
Blackbox tests, forgot to add these earlier.
1
# Copyright (C) 2009 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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3955.3.10 by Jonathan Lange
Blackbox tests, forgot to add these earlier.
16
17
"""Tests for the launchpad-open command."""
18
19
from bzrlib.tests import TestCaseWithTransport
20
21
22
class TestLaunchpadOpen(TestCaseWithTransport):
23
24
    def run_open(self, location, retcode=0):
25
        out, err = self.run_bzr(
26
            ['launchpad-open', '--dry-run', location], retcode=retcode)
27
        return err.splitlines()
28
29
    def test_non_branch(self):
4031.2.4 by Jonathan Lange
Improve some comments.
30
        # If given a branch with no public or push locations, lp-open will try
31
        # to guess the Launchpad page for the given URL / path. If it cannot
32
        # find one, it will raise an error.
3955.3.10 by Jonathan Lange
Blackbox tests, forgot to add these earlier.
33
        self.assertEqual(
4031.2.8 by Jonathan Lange
Say "registered on", not "hosted on".
34
            ['bzr: ERROR: . is not registered on Launchpad.'],
3955.3.10 by Jonathan Lange
Blackbox tests, forgot to add these earlier.
35
            self.run_open('.', retcode=3))
36
4031.2.1 by Jonathan Lange
Rename tests in anticipation of adding more.
37
    def test_no_public_location_no_push_location(self):
3955.3.10 by Jonathan Lange
Blackbox tests, forgot to add these earlier.
38
        self.make_branch('not-public')
39
        self.assertEqual(
4031.2.8 by Jonathan Lange
Say "registered on", not "hosted on".
40
            ['bzr: ERROR: not-public is not registered on Launchpad.'],
3955.3.10 by Jonathan Lange
Blackbox tests, forgot to add these earlier.
41
            self.run_open('not-public', retcode=3))
42
43
    def test_non_launchpad_branch(self):
44
        branch = self.make_branch('non-lp')
45
        url = 'http://example.com/non-lp'
46
        branch.set_public_branch(url)
47
        self.assertEqual(
4031.2.8 by Jonathan Lange
Say "registered on", not "hosted on".
48
            ['bzr: ERROR: %s is not registered on Launchpad.' % url],
3955.3.10 by Jonathan Lange
Blackbox tests, forgot to add these earlier.
49
            self.run_open('non-lp', retcode=3))
50
4031.2.1 by Jonathan Lange
Rename tests in anticipation of adding more.
51
    def test_launchpad_branch_with_public_location(self):
3955.3.10 by Jonathan Lange
Blackbox tests, forgot to add these earlier.
52
        branch = self.make_branch('lp')
53
        branch.set_public_branch(
54
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
55
        self.assertEqual(
56
            ['Opening https://code.edge.launchpad.net/~foo/bar/baz in web '
57
             'browser'],
58
            self.run_open('lp'))
4031.2.2 by Jonathan Lange
Fall-back to push location.
59
4031.2.10 by Jonathan Lange
Add one precedence test.
60
    def test_launchpad_branch_with_public_and_push_location(self):
61
        branch = self.make_branch('lp')
62
        branch.set_public_branch(
63
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/public')
64
        branch.set_push_location(
65
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/push')
66
        self.assertEqual(
67
            ['Opening https://code.edge.launchpad.net/~foo/bar/public in web '
68
             'browser'],
69
            self.run_open('lp'))
70
4031.2.2 by Jonathan Lange
Fall-back to push location.
71
    def test_launchpad_branch_with_no_public_but_with_push(self):
72
        # lp-open falls back to the push location if it cannot find a public
73
        # location.
74
        branch = self.make_branch('lp')
75
        branch.set_push_location(
76
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
77
        self.assertEqual(
78
            ['Opening https://code.edge.launchpad.net/~foo/bar/baz in web '
79
             'browser'],
80
            self.run_open('lp'))
4031.2.3 by Jonathan Lange
Try to open the page for the branch location on the command line if
81
82
    def test_launchpad_branch_with_no_public_no_push(self):
83
        # If lp-open is given a branch URL and that branch has no public
84
        # location and no push location, then just try to look up the
85
        # Launchpad page for that URL.
86
        self.assertEqual(
87
            ['Opening https://code.edge.launchpad.net/~foo/bar/baz in web '
88
             'browser'],
89
            self.run_open('bzr+ssh://bazaar.launchpad.net/~foo/bar/baz'))