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