~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2012-01-05 14:26:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120105142658-vek3v6pzlxb751s2
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made. 

@only_raises is evil and gave a hard time since any exception during
save_changes() was swallowed.

Possible improvements: 

- add some needs_write_lock decorators to crucial
  methods (_set_config_location ?) but keep locking the branch at higher levels

- decorate branch.unlock to call stack.save if last_lock() it True
  outside of @only_raises scope (evil decorator)

- add @needs_write_lock to stack.set and stack.remove (will probably get
  rid of most testing issues) we probably need a specialized decorator
  that can relay to the store and from there to the branch or whatever is
  needed. This will also helps bzr config to get it right. The
  get_mutable_section trick should not be needed anymore either.

- decorate branch.unlock to call stack.save if last_lock() it True outside
  of @only_raises scope (evil decorator)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009, 2010, 2012 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
44
44
    def test_non_launchpad_branch(self):
45
45
        branch = self.make_branch('non-lp')
46
46
        url = 'http://example.com/non-lp'
 
47
        branch.lock_write()
47
48
        branch.set_public_branch(url)
 
49
        branch.unlock()
48
50
        self.assertEqual(
49
51
            ['bzr: ERROR: %s is not registered on Launchpad.' % url],
50
52
            self.run_open('non-lp', retcode=3))
51
53
 
52
54
    def test_launchpad_branch_with_public_location(self):
53
55
        branch = self.make_branch('lp')
 
56
        branch.lock_write()
54
57
        branch.set_public_branch(
55
58
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
 
59
        branch.unlock()
56
60
        self.assertEqual(
57
61
            ['Opening https://code.launchpad.net/~foo/bar/baz in web '
58
62
             'browser'],
60
64
 
61
65
    def test_launchpad_branch_with_public_and_push_location(self):
62
66
        branch = self.make_branch('lp')
 
67
        branch.lock_write()
63
68
        branch.set_public_branch(
64
69
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/public')
65
70
        branch.set_push_location(
66
71
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/push')
 
72
        branch.unlock()
67
73
        self.assertEqual(
68
74
            ['Opening https://code.launchpad.net/~foo/bar/public in web '
69
75
             'browser'],
73
79
        # lp-open falls back to the push location if it cannot find a public
74
80
        # location.
75
81
        branch = self.make_branch('lp')
 
82
        branch.lock_write()
76
83
        branch.set_push_location(
77
84
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
 
85
        branch.unlock()
78
86
        self.assertEqual(
79
87
            ['Opening https://code.launchpad.net/~foo/bar/baz in web '
80
88
             'browser'],
92
100
    def test_launchpad_branch_subdirectory(self):
93
101
        # lp-open in a subdirectory of a registered branch should work
94
102
        wt = self.make_branch_and_tree('lp')
 
103
        wt.branch.lock_write()
95
104
        wt.branch.set_push_location(
96
105
            'bzr+ssh://bazaar.launchpad.net/~foo/bar/baz')
 
106
        wt.branch.unlock()
97
107
        self.build_tree(['lp/a/'])
98
108
        self.assertEqual(
99
109
            ['Opening https://code.launchpad.net/~foo/bar/baz in web '