~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2010-01-12 03:53:21 UTC
  • mfrom: (4948 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4964.
  • Revision ID: andrew.bennetts@canonical.com-20100112035321-hofpz5p10224ryj3
Merge lp:bzr, resolving conflicts.

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 the launchpad-open command."""
18
18
 
19
 
from bzrlib.osutils import abspath
20
 
 
21
19
from bzrlib.tests import TestCaseWithTransport
22
20
 
23
21
 
24
22
class TestLaunchpadOpen(TestCaseWithTransport):
25
23
 
26
 
    def run_open(self, location, retcode=0):
27
 
        out, err = self.run_bzr(
28
 
            ['launchpad-open', '--dry-run', location], retcode=retcode)
 
24
    def run_open(self, location, retcode=0, working_dir='.'):
 
25
        out, err = self.run_bzr(['launchpad-open', '--dry-run', location],
 
26
                                retcode=retcode,
 
27
                                working_dir=working_dir)
29
28
        return err.splitlines()
30
29
 
31
30
    def test_non_branch(self):
32
 
        # Running lp-open on a non-branch prints a simple error.
 
31
        # If given a branch with no public or push locations, lp-open will try
 
32
        # to guess the Launchpad page for the given URL / path. If it cannot
 
33
        # find one, it will raise an error.
33
34
        self.assertEqual(
34
 
            ['bzr: ERROR: Not a branch: "%s/".' % abspath('.')],
 
35
            ['bzr: ERROR: . is not registered on Launchpad.'],
35
36
            self.run_open('.', retcode=3))
36
37
 
37
 
    def test_no_public_location(self):
 
38
    def test_no_public_location_no_push_location(self):
38
39
        self.make_branch('not-public')
39
40
        self.assertEqual(
40
 
            ['bzr: ERROR: There is no public branch set for "%s/".'
41
 
             % abspath('not-public')],
 
41
            ['bzr: ERROR: not-public is not registered on Launchpad.'],
42
42
            self.run_open('not-public', retcode=3))
43
43
 
44
44
    def test_non_launchpad_branch(self):
46
46
        url = 'http://example.com/non-lp'
47
47
        branch.set_public_branch(url)
48
48
        self.assertEqual(
49
 
            ['bzr: ERROR: %s is not hosted on Launchpad.' % url],
 
49
            ['bzr: ERROR: %s is not registered on Launchpad.' % url],
50
50
            self.run_open('non-lp', retcode=3))
51
51
 
52
 
    def test_launchpad_branch(self):
53
 
        branch = self.make_branch('lp')
54
 
        branch.set_public_branch(
55
 
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
56
 
        self.assertEqual(
57
 
            ['Opening https://code.edge.launchpad.net/~foo/bar/baz in web '
58
 
             'browser'],
59
 
            self.run_open('lp'))
 
52
    def test_launchpad_branch_with_public_location(self):
 
53
        branch = self.make_branch('lp')
 
54
        branch.set_public_branch(
 
55
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
 
56
        self.assertEqual(
 
57
            ['Opening https://code.edge.launchpad.net/~foo/bar/baz in web '
 
58
             'browser'],
 
59
            self.run_open('lp'))
 
60
 
 
61
    def test_launchpad_branch_with_public_and_push_location(self):
 
62
        branch = self.make_branch('lp')
 
63
        branch.set_public_branch(
 
64
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/public')
 
65
        branch.set_push_location(
 
66
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/push')
 
67
        self.assertEqual(
 
68
            ['Opening https://code.edge.launchpad.net/~foo/bar/public in web '
 
69
             'browser'],
 
70
            self.run_open('lp'))
 
71
 
 
72
    def test_launchpad_branch_with_no_public_but_with_push(self):
 
73
        # lp-open falls back to the push location if it cannot find a public
 
74
        # location.
 
75
        branch = self.make_branch('lp')
 
76
        branch.set_push_location(
 
77
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
 
78
        self.assertEqual(
 
79
            ['Opening https://code.edge.launchpad.net/~foo/bar/baz in web '
 
80
             'browser'],
 
81
            self.run_open('lp'))
 
82
 
 
83
    def test_launchpad_branch_with_no_public_no_push(self):
 
84
        # If lp-open is given a branch URL and that branch has no public
 
85
        # location and no push location, then just try to look up the
 
86
        # Launchpad page for that URL.
 
87
        self.assertEqual(
 
88
            ['Opening https://code.edge.launchpad.net/~foo/bar/baz in web '
 
89
             'browser'],
 
90
            self.run_open('bzr+ssh://bazaar.launchpad.net/~foo/bar/baz'))
 
91
 
 
92
    def test_launchpad_branch_subdirectory(self):
 
93
        # lp-open in a subdirectory of a registered branch should work
 
94
        wt = self.make_branch_and_tree('lp')
 
95
        wt.branch.set_push_location(
 
96
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
 
97
        self.build_tree(['lp/a/'])
 
98
        self.assertEqual(
 
99
            ['Opening https://code.edge.launchpad.net/~foo/bar/baz in web '
 
100
             'browser'],
 
101
            self.run_open('.', working_dir='lp/a'))