~bzr-pqm/bzr/bzr.dev

4505.6.25 by Jonathan Lange
Add a test to check what happens if launchpadlib not available.
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
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
18
from bzrlib import errors
4505.6.27 by Jonathan Lange
Add some tests to check for version compatibility. Drop tests for
19
from bzrlib.tests import ModuleAvailableFeature, TestCase
20
21
22
launchpadlib_feature = ModuleAvailableFeature('launchpadlib')
4505.6.25 by Jonathan Lange
Add a test to check what happens if launchpadlib not available.
23
24
25
class TestDependencyManagement(TestCase):
26
    """Tests for managing the dependency on launchpadlib."""
27
4505.6.27 by Jonathan Lange
Add some tests to check for version compatibility. Drop tests for
28
    _test_needs_features = [launchpadlib_feature]
29
30
    def setUp(self):
31
        TestCase.setUp(self)
32
        from bzrlib.plugins.launchpad import lp_api
33
        self.lp_api = lp_api
34
35
    def patch(self, obj, name, value):
36
        """Temporarily set the 'name' attribute of 'obj' to 'value'."""
37
        real_value = getattr(obj, name)
38
        setattr(obj, name, value)
39
        self.addCleanup(setattr, obj, name, real_value)
40
41
    def test_get_launchpadlib_version(self):
42
        # parse_launchpadlib_version returns a tuple of a version number of
43
        # the style used by launchpadlib.
44
        version_info = self.lp_api.parse_launchpadlib_version('1.5.1')
45
        self.assertEqual((1, 5, 1), version_info)
46
47
    def test_supported_launchpadlib_version(self):
48
        launchpadlib = launchpadlib_feature.module
49
        self.patch(launchpadlib, '__version__', '1.5.1')
50
        self.lp_api.MINIMUM_LAUNCHPADLIB_VERSION = (1, 5, 1)
51
        # Doesn't raise an exception.
52
        self.lp_api.check_launchpadlib_compatibility()
53
54
    def test_unsupported_launchpadlib_version(self):
55
        launchpadlib = launchpadlib_feature.module
56
        self.patch(launchpadlib, '__version__', '1.5.0')
57
        self.lp_api.MINIMUM_LAUNCHPADLIB_VERSION = (1, 5, 1)
4505.6.25 by Jonathan Lange
Add a test to check what happens if launchpadlib not available.
58
        self.assertRaises(
4505.6.27 by Jonathan Lange
Add some tests to check for version compatibility. Drop tests for
59
            errors.IncompatibleAPI,
60
            self.lp_api.check_launchpadlib_compatibility)