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