~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

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