~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge up through 2.2.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009, 2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
 
 
18
from bzrlib import commands, config, errors, osutils
 
19
from bzrlib.plugins.launchpad import cmd_launchpad_mirror
 
20
from bzrlib.tests import (
 
21
    ModuleAvailableFeature,
 
22
    TestCase,
 
23
    TestCaseWithTransport,
 
24
    )
 
25
 
 
26
 
 
27
launchpadlib_feature = ModuleAvailableFeature('launchpadlib')
 
28
 
 
29
 
 
30
class TestDependencyManagement(TestCase):
 
31
    """Tests for managing the dependency on launchpadlib."""
 
32
 
 
33
    _test_needs_features = [launchpadlib_feature]
 
34
 
 
35
    def setUp(self):
 
36
        TestCase.setUp(self)
 
37
        from bzrlib.plugins.launchpad import lp_api
 
38
        self.lp_api = lp_api
 
39
 
 
40
    def patch(self, obj, name, value):
 
41
        """Temporarily set the 'name' attribute of 'obj' to 'value'."""
 
42
        self.overrideAttr(obj, name, value)
 
43
 
 
44
    def test_get_launchpadlib_version(self):
 
45
        # parse_launchpadlib_version returns a tuple of a version number of
 
46
        # the style used by launchpadlib.
 
47
        version_info = self.lp_api.parse_launchpadlib_version('1.5.1')
 
48
        self.assertEqual((1, 5, 1), version_info)
 
49
 
 
50
    def test_supported_launchpadlib_version(self):
 
51
        # If the installed version of launchpadlib is greater than the minimum
 
52
        # required version of launchpadlib, check_launchpadlib_compatibility
 
53
        # doesn't raise an error.
 
54
        launchpadlib = launchpadlib_feature.module
 
55
        self.patch(launchpadlib, '__version__', '1.5.1')
 
56
        self.lp_api.MINIMUM_LAUNCHPADLIB_VERSION = (1, 5, 1)
 
57
        # Doesn't raise an exception.
 
58
        self.lp_api.check_launchpadlib_compatibility()
 
59
 
 
60
    def test_unsupported_launchpadlib_version(self):
 
61
        # If the installed version of launchpadlib is less than the minimum
 
62
        # required version of launchpadlib, check_launchpadlib_compatibility
 
63
        # raises an IncompatibleAPI error.
 
64
        launchpadlib = launchpadlib_feature.module
 
65
        self.patch(launchpadlib, '__version__', '1.5.0')
 
66
        self.lp_api.MINIMUM_LAUNCHPADLIB_VERSION = (1, 5, 1)
 
67
        self.assertRaises(
 
68
            errors.IncompatibleAPI,
 
69
            self.lp_api.check_launchpadlib_compatibility)
 
70
 
 
71
 
 
72
class TestCacheDirectory(TestCase):
 
73
    """Tests for get_cache_directory."""
 
74
 
 
75
    _test_needs_features = [launchpadlib_feature]
 
76
 
 
77
    def test_get_cache_directory(self):
 
78
        # get_cache_directory returns the path to a directory inside the
 
79
        # Bazaar configuration directory.
 
80
        from bzrlib.plugins.launchpad import lp_api
 
81
        expected_path = osutils.pathjoin(config.config_dir(), 'launchpad')
 
82
        self.assertEqual(expected_path, lp_api.get_cache_directory())
 
83
 
 
84
 
 
85
class TestLaunchpadMirror(TestCaseWithTransport):
 
86
    """Tests for the 'bzr lp-mirror' command."""
 
87
 
 
88
    # Testing the lp-mirror command is quite hard, since it must talk to a
 
89
    # Launchpad server. Here, we just test that the command exists.
 
90
 
 
91
    _test_needs_features = [launchpadlib_feature]
 
92
 
 
93
    def test_command_exists(self):
 
94
        out, err = self.run_bzr(['launchpad-mirror', '--help'], retcode=0)
 
95
        self.assertEqual('', err)
 
96
 
 
97
    def test_alias_exists(self):
 
98
        out, err = self.run_bzr(['lp-mirror', '--help'], retcode=0)
 
99
        self.assertEqual('', err)