/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4797.32.2 by John Arbash Meinel
merge 2.1, resolving NEWS conflict.
1
# Copyright (C) 2009, 2010 Canonical Ltd
4505.6.25 by Jonathan Lange
Add a test to check what happens if launchpadlib not available.
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
7336.2.1 by Martin
Split non-ini config methods to bedding
18
from ... import (
19
    bedding,
20
    errors,
21
    osutils,
22
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
23
from ...tests import (
4505.6.30 by Jonathan Lange
Add basic smoke tests to show that the command exists.
24
    TestCase,
25
    TestCaseWithTransport,
26
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
27
from ...tests.features import (
5967.12.5 by Martin Pool
Update launchpad plugin for features under tests.features
28
    ModuleAvailableFeature,
29
    )
4505.6.27 by Jonathan Lange
Add some tests to check for version compatibility. Drop tests for
30
31
32
launchpadlib_feature = ModuleAvailableFeature('launchpadlib')
4505.6.25 by Jonathan Lange
Add a test to check what happens if launchpadlib not available.
33
34
35
class TestDependencyManagement(TestCase):
36
    """Tests for managing the dependency on launchpadlib."""
37
4505.6.27 by Jonathan Lange
Add some tests to check for version compatibility. Drop tests for
38
    _test_needs_features = [launchpadlib_feature]
39
40
    def setUp(self):
6552.1.4 by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super().
41
        super(TestDependencyManagement, self).setUp()
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
42
        from . import lp_api
4505.6.27 by Jonathan Lange
Add some tests to check for version compatibility. Drop tests for
43
        self.lp_api = lp_api
44
45
    def patch(self, obj, name, value):
46
        """Temporarily set the 'name' attribute of 'obj' to 'value'."""
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
47
        self.overrideAttr(obj, name, value)
4505.6.27 by Jonathan Lange
Add some tests to check for version compatibility. Drop tests for
48
49
    def test_get_launchpadlib_version(self):
50
        # parse_launchpadlib_version returns a tuple of a version number of
51
        # the style used by launchpadlib.
52
        version_info = self.lp_api.parse_launchpadlib_version('1.5.1')
53
        self.assertEqual((1, 5, 1), version_info)
54
55
    def test_supported_launchpadlib_version(self):
4505.6.28 by Jonathan Lange
Comments
56
        # If the installed version of launchpadlib is greater than the minimum
57
        # required version of launchpadlib, check_launchpadlib_compatibility
58
        # doesn't raise an error.
4505.6.27 by Jonathan Lange
Add some tests to check for version compatibility. Drop tests for
59
        launchpadlib = launchpadlib_feature.module
60
        self.patch(launchpadlib, '__version__', '1.5.1')
61
        self.lp_api.MINIMUM_LAUNCHPADLIB_VERSION = (1, 5, 1)
62
        # Doesn't raise an exception.
63
        self.lp_api.check_launchpadlib_compatibility()
64
65
    def test_unsupported_launchpadlib_version(self):
4505.6.28 by Jonathan Lange
Comments
66
        # If the installed version of launchpadlib is less than the minimum
67
        # required version of launchpadlib, check_launchpadlib_compatibility
6672.1.2 by Jelmer Vernooij
Remove breezy.api.
68
        # raises an DependencyNotPresent error.
4505.6.27 by Jonathan Lange
Add some tests to check for version compatibility. Drop tests for
69
        launchpadlib = launchpadlib_feature.module
70
        self.patch(launchpadlib, '__version__', '1.5.0')
71
        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.
72
        self.assertRaises(
6672.1.2 by Jelmer Vernooij
Remove breezy.api.
73
            errors.DependencyNotPresent,
4505.6.27 by Jonathan Lange
Add some tests to check for version compatibility. Drop tests for
74
            self.lp_api.check_launchpadlib_compatibility)
4505.6.29 by Jonathan Lange
More tests.
75
76
77
class TestCacheDirectory(TestCase):
78
    """Tests for get_cache_directory."""
79
80
    _test_needs_features = [launchpadlib_feature]
81
82
    def test_get_cache_directory(self):
83
        # get_cache_directory returns the path to a directory inside the
6060.9.9 by Jelmer Vernooij
Fix tests.
84
        # Breezy cache directory.
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
85
        from . import lp_api
7371.1.2 by Jelmer Vernooij
Fix Launchpad cache directory test as well.
86
        try:
87
            expected_path = osutils.pathjoin(bedding.cache_dir(), 'launchpad')
88
        except EnvironmentError:
89
            self.assertRaises(EnvironmentError, lp_api.get_cache_directory)
90
        else:
91
            self.assertEqual(expected_path, lp_api.get_cache_directory())