Merge lp:~frankban/lpsetup/remove-smoke-tests into lp:lpsetup

Proposed by Francesco Banconi
Status: Merged
Approved by: Francesco Banconi
Approved revision: 90
Merged at revision: 72
Proposed branch: lp:~frankban/lpsetup/remove-smoke-tests
Merge into: lp:lpsetup
Diff against target: 431 lines (+6/-348)
8 files modified
lpsetup/tests/subcommands/test_finish_inithost.py (+0/-38)
lpsetup/tests/subcommands/test_inithost.py (+1/-38)
lpsetup/tests/subcommands/test_initlxc.py (+0/-67)
lpsetup/tests/subcommands/test_initrepo.py (+3/-43)
lpsetup/tests/subcommands/test_install_lxc.py (+0/-68)
lpsetup/tests/subcommands/test_update.py (+0/-44)
lpsetup/tests/utils.py (+1/-49)
lpsetup/utils.py (+1/-1)
To merge this branch: bzr merge lp:~frankban/lpsetup/remove-smoke-tests
Reviewer Review Type Date Requested Status
Benji York (community) code Approve
Review via email: mp+119367@code.launchpad.net

Commit message

Removed no longer useful smoke tests.

Description of the change

== Changes ==

Now we have integration tests for the subcommands, so we can remove the "copy/paste" smoke tests exercising steps, handlers and root_required.

Fixed a typo in confirm, found while working on the main task.

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

Looks good.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== removed file 'lpsetup/tests/subcommands/test_finish_inithost.py'
--- lpsetup/tests/subcommands/test_finish_inithost.py 2012-08-10 08:34:16 +0000
+++ lpsetup/tests/subcommands/test_finish_inithost.py 1970-01-01 00:00:00 +0000
@@ -1,38 +0,0 @@
1#!/usr/bin/env python
2# Copyright 2012 Canonical Ltd. This software is licensed under the
3# GNU Affero General Public License version 3 (see the file LICENSE).
4
5"""Tests for the finish-init-host subcommand."""
6
7import unittest
8
9from lpsetup import handlers
10from lpsetup.subcommands import finish_inithost
11from lpsetup.tests.utils import (
12 get_random_string,
13 StepsBasedSubCommandTestMixin,
14 )
15
16
17setup_launchpad_step = (
18 finish_inithost.setup_launchpad, ['user', 'target_dir'])
19
20
21def get_arguments():
22 target_dir = '~/' + get_random_string()
23 user = get_random_string()
24 return (target_dir, '-u', user)
25
26
27class FinishInitHostTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
28
29 subcommand_class = finish_inithost.SubCommand
30 expected_arguments = get_arguments()
31 expected_handlers = (handlers.handle_user, handlers.handle_target_dir)
32
33 @property
34 def expected_steps(self):
35 return (
36 setup_launchpad_step,
37 )
38 needs_root = True
390
=== modified file 'lpsetup/tests/subcommands/test_inithost.py'
--- lpsetup/tests/subcommands/test_inithost.py 2012-08-10 08:34:16 +0000
+++ lpsetup/tests/subcommands/test_inithost.py 2012-08-13 15:03:21 +0000
@@ -10,45 +10,8 @@
10import tempfile10import tempfile
11import unittest11import unittest
1212
13from lpsetup import handlers
14from lpsetup.subcommands import inithost13from lpsetup.subcommands import inithost
15from lpsetup.tests.utils import (14from lpsetup.tests.utils import get_random_string
16 get_random_string,
17 StepsBasedSubCommandTestMixin,
18 )
19
20
21initialize_step = (inithost.initialize, ['user'])
22setup_home_step = (
23 inithost.setup_home, ['user', 'full_name', 'email', 'lpuser',
24 'valid_ssh_keys', 'ssh_key_path',
25 ])
26initialize_lxc_step = (inithost.initialize_lxc, [])
27setup_apt_step = (inithost.setup_apt, [])
28
29
30def get_arguments():
31 user = get_random_string()
32 email = get_random_string()
33 full_name = get_random_string() + '@example.com'
34 lpuser = get_random_string()
35 ssh_key_name = get_random_string()
36 return ('-u', user, '-E', email, '-f', full_name, '-l', lpuser,
37 '-S', ssh_key_name)
38
39
40class InithostSmokeTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
41
42 subcommand_class = inithost.SubCommand
43 expected_arguments = get_arguments()
44 expected_handlers = (
45 handlers.handle_user,
46 handlers.handle_lpuser_as_username,
47 handlers.handle_userdata,
48 handlers.handle_ssh_keys,
49 )
50 expected_steps = (initialize_step, setup_home_step, setup_apt_step)
51 needs_root = True
5215
5316
54class WriteFileContentsTestCase(unittest.TestCase):17class WriteFileContentsTestCase(unittest.TestCase):
5518
=== removed file 'lpsetup/tests/subcommands/test_initlxc.py'
--- lpsetup/tests/subcommands/test_initlxc.py 2012-08-10 08:34:16 +0000
+++ lpsetup/tests/subcommands/test_initlxc.py 1970-01-01 00:00:00 +0000
@@ -1,67 +0,0 @@
1#!/usr/bin/env python
2# Copyright 2012 Canonical Ltd. This software is licensed under the
3# GNU Affero General Public License version 3 (see the file LICENSE).
4
5"""Tests for the initlxc subcommand."""
6
7import random
8import unittest
9
10from lpsetup import (
11 handlers,
12 settings,
13 )
14from lpsetup.subcommands import initlxc
15from lpsetup.tests.subcommands import test_inithost
16from lpsetup.tests.utils import (
17 get_random_string,
18 StepsBasedSubCommandTestMixin,
19 )
20
21initialize_step = (initlxc.initialize, ['user', 'install_haveged'])
22create_lxc_step = (
23 initlxc.create_lxc,
24 ['lxc_name', 'lxc_arch', 'lxc_os', 'user', 'install_subunit'])
25start_lxc_step = (initlxc.start_lxc, ['lxc_name'])
26wait_for_lxc_step = (initlxc.wait_for_lxc, ['lxc_name', 'ssh_key_path'])
27install_lpsetup_in_lxc_step = (
28 initlxc.install_lpsetup_in_lxc, ['lxc_name', 'ssh_key_path', 'lxc_os',
29 'user', 'home_dir', 'lpsetup_branch'])
30inithost_in_lxc_step = (
31 initlxc.inithost_in_lxc,
32 ['lxc_name', 'ssh_key_path', 'user', 'email', 'full_name', 'lpuser',
33 'ssh_key_name', 'home_dir'])
34stop_lxc_step = (initlxc.stop_lxc, ['lxc_name', 'ssh_key_path'])
35
36
37def get_arguments():
38 inithost_arguments = test_inithost.get_arguments()
39 lxc_name = get_random_string()
40 lxc_arch = random.choice(['i386', 'amd64'])
41 lxc_os = random.choice(settings.LXC_GUEST_CHOICES)
42 return (
43 lxc_name, '-A', lxc_arch, '-R', lxc_os, '--stop-lxc',
44 '--omit-subunit', '--omit-haveged') + inithost_arguments
45
46
47class InitLxcTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
48
49 subcommand_class = initlxc.SubCommand
50 expected_arguments = get_arguments()
51 expected_handlers = (
52 handlers.handle_user,
53 handlers.handle_lpuser_as_username,
54 handlers.handle_userdata,
55 handlers.handle_ssh_keys,
56 )
57 expected_steps = (
58 initialize_step,
59 test_inithost.setup_home_step,
60 create_lxc_step,
61 start_lxc_step,
62 wait_for_lxc_step,
63 install_lpsetup_in_lxc_step,
64 inithost_in_lxc_step,
65 stop_lxc_step,
66 )
67 needs_root = True
680
=== modified file 'lpsetup/tests/subcommands/test_initrepo.py'
--- lpsetup/tests/subcommands/test_initrepo.py 2012-08-10 08:34:16 +0000
+++ lpsetup/tests/subcommands/test_initrepo.py 2012-08-13 15:03:21 +0000
@@ -14,58 +14,18 @@
14 run,14 run,
15 )15 )
1616
17from lpsetup import (17from lpsetup import cli
18 cli,
19 handlers,
20 )
21from lpsetup.subcommands import initrepo
22from lpsetup.tests.utils import (18from lpsetup.tests.utils import (
23 create_test_branch,19 create_test_branch,
24 get_random_string,20 get_random_string,
25 lpuser,21 lpuser,
26 skip_if_no_lpuser,22 skip_if_no_lpuser,
27 StepsBasedSubCommandTestMixin,
28 )23 )
29from lpsetup.utils import ConfigParser24from lpsetup.utils import ConfigParser
3025
3126
32fetch_step = (initrepo.fetch,27@skip_if_no_lpuser
33 ['source', 'repository', 'branch_name', 'checkout_name', 'no_checkout'])28class InitrepoTest(unittest.TestCase):
34setup_bzr_locations_step = (initrepo.setup_bzr_locations,
35 ['lpuser', 'repository', 'branch_name'])
36
37
38def get_arguments():
39 return (
40 '--source', get_random_string(),
41 '--repository', get_random_string(),
42 '--branch-name', get_random_string(),
43 '--checkout-name', get_random_string(),
44 '--no-checkout',
45 )
46
47
48@skip_if_no_lpuser
49class InitrepoTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
50
51 subcommand_class = initrepo.SubCommand
52 expected_arguments = get_arguments()
53 expected_handlers = (
54 handlers.handle_user,
55 handlers.handle_lpuser_from_lplogin,
56 handlers.handle_directories,
57 handlers.handle_branch_and_checkout,
58 handlers.handle_source,
59 )
60 expected_steps = (
61 fetch_step,
62 setup_bzr_locations_step,
63 )
64 needs_root = False
65
66
67@skip_if_no_lpuser
68class IntegrationTest(unittest.TestCase):
6929
70 def setUp(self):30 def setUp(self):
71 """Create a fake source bzr branch under `/tmp/`."""31 """Create a fake source bzr branch under `/tmp/`."""
7232
=== removed file 'lpsetup/tests/subcommands/test_install_lxc.py'
--- lpsetup/tests/subcommands/test_install_lxc.py 2012-08-10 08:34:16 +0000
+++ lpsetup/tests/subcommands/test_install_lxc.py 1970-01-01 00:00:00 +0000
@@ -1,68 +0,0 @@
1#!/usr/bin/env python
2# Copyright 2012 Canonical Ltd. This software is licensed under the
3# GNU Affero General Public License version 3 (see the file LICENSE).
4
5"""Tests for the install-lxc subcommand."""
6
7import unittest
8
9from lpsetup import handlers
10from lpsetup.subcommands import install_lxc
11from lpsetup.tests.subcommands import (
12 test_initlxc,
13 )
14from lpsetup.tests.utils import (
15 get_random_string,
16 StepsBasedSubCommandTestMixin,
17 )
18
19
20create_scripts_step = (
21 install_lxc.create_scripts, ['lxc_name', 'ssh_key_path', 'user'])
22
23init_repo_in_lxc_step = (
24 install_lxc.init_repo_in_lxc, [
25 'lxc_name', 'ssh_key_path', 'home_dir', 'user', 'source', 'use_http',
26 'branch_name', 'checkout_name', 'repository', 'no_checkout',
27 ])
28
29update_in_lxc_step = (
30 install_lxc.update_in_lxc, [
31 'lxc_name', 'ssh_key_path', 'home_dir', 'user', 'external_path',
32 'target_dir', 'lp_source_deps', 'use_http',
33 ])
34
35finish_inithost_in_lxc_step = (
36 install_lxc.finish_inithost_in_lxc, [
37 'lxc_name', 'ssh_key_path', 'home_dir', 'user', 'target_dir',
38 ])
39
40
41def get_arguments():
42 repository = '~/' + get_random_string()
43 return test_initlxc.get_arguments() + (
44 '-r', repository,
45 '--create-scripts',
46 )
47
48
49class InstallLxcTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
50
51 subcommand_class = install_lxc.SubCommand
52 expected_arguments = get_arguments()
53 expected_handlers = test_initlxc.InitLxcTest.expected_handlers + (
54 handlers.handle_testing,
55 handlers.handle_directories,
56 handlers.handle_branch_and_checkout,
57 handlers.handle_source,
58 handlers.handle_target_from_repository,
59 )
60 expected_steps = test_initlxc.InitLxcTest.expected_steps[:-1] + (
61 create_scripts_step,
62 init_repo_in_lxc_step,
63 update_in_lxc_step,
64 finish_inithost_in_lxc_step,
65 test_initlxc.stop_lxc_step,
66 )
67 needs_root = True
68 maxDiff = None
690
=== removed file 'lpsetup/tests/subcommands/test_update.py'
--- lpsetup/tests/subcommands/test_update.py 2012-08-10 08:34:16 +0000
+++ lpsetup/tests/subcommands/test_update.py 1970-01-01 00:00:00 +0000
@@ -1,44 +0,0 @@
1#!/usr/bin/env python
2# Copyright 2012 Canonical Ltd. This software is licensed under the
3# GNU Affero General Public License version 3 (see the file LICENSE).
4
5"""Tests for the update subcommand."""
6
7import unittest
8
9from lpsetup import handlers
10from lpsetup.subcommands import update
11from lpsetup.tests.utils import (
12 get_random_string,
13 StepsBasedSubCommandTestMixin,
14 )
15
16
17def get_arguments():
18 target_dir = '~/' + get_random_string()
19 external_path = get_random_string()
20 return (
21 target_dir,
22 '--external-path', external_path,
23 '--use-http',
24 )
25
26init_dir_step = (
27 update.initialize_directories, ['target_dir', 'external_path'])
28update_dep_step = (
29 update.update_dependencies, ['target_dir', 'external_path', 'use_http',
30 'lp_source_deps'])
31update_tree_step = (update.update_tree, ['target_dir'])
32
33
34class UpdateTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
35
36 subcommand_class = update.SubCommand
37 expected_arguments = get_arguments()
38 expected_handlers = (handlers.handle_user, handlers.handle_target_dir)
39 expected_steps = (
40 init_dir_step,
41 update_dep_step,
42 update_tree_step,
43 )
44 needs_root = False
450
=== modified file 'lpsetup/tests/utils.py'
--- lpsetup/tests/utils.py 2012-08-13 08:42:08 +0000
+++ lpsetup/tests/utils.py 2012-08-13 15:03:21 +0000
@@ -36,10 +36,7 @@
36 run,36 run,
37 )37 )
3838
39from lpsetup import (39from lpsetup import argparser
40 argparser,
41 cli,
42 )
43from lpsetup.utils import call40from lpsetup.utils import call
4441
4542
@@ -266,48 +263,3 @@
266 'StepsBasedSubCommand',263 'StepsBasedSubCommand',
267 (argparser.StepsBasedSubCommand,),264 (argparser.StepsBasedSubCommand,),
268 kwargs)()265 kwargs)()
269
270
271class StepsBasedSubCommandTestMixin(ParserTestMixin):
272 """This mixin can be used to test subcommands steps and handlers.
273
274 Real TestCases subclassing this mixin must define:
275
276 - subcommand_class: the steps based subcommand class
277 - expected_arguments: a sequence of command line arguments
278 used by the current tested subcommand
279 - expected_handlers: a sequence of expected handler callables
280 - expected_steps: a sequence of expected *(step_callable, arg_names)*
281 - needs_root: True if this subcommand must be run as root
282
283 At this point steps and handlers are automatically tested, and the test
284 case also checks if root is required by the subcommand.
285 """
286 def setUp(self):
287 """Set up a namespace using *self.expected_arguments*."""
288 super(StepsBasedSubCommandTestMixin, self).setUp()
289 self.subcommand = self.subcommand_class()
290 cli.prepare_parser(self.parser, self.subcommand)
291 self.namespace = self.parser.parse_args(self.expected_arguments)
292 argparser.init_namespace(self.namespace)
293
294 def test_handlers(self):
295 # Ensure this subcommand uses the expected handlers.
296 handlers = self.subcommand.get_handlers(self.namespace)
297 self.assertSequenceEqual(self.expected_handlers, handlers)
298
299 def test_steps(self):
300 # Ensure this subcommand wants to run the expected steps.
301 self.subcommand.prepare_namespace(self.namespace)
302 steps = argparser.resolve_steps(self.subcommand.steps, self.namespace)
303 real_steps = [[step, list(args)] for step, args in steps]
304 expected_steps = []
305 for step, arg_names in self.expected_steps:
306 args = [getattr(self.namespace, name) for name in arg_names]
307 expected_steps.append([step, args])
308 self.assertListEqual(expected_steps, real_steps)
309
310 def test_needs_root(self):
311 # The root user may or may not be required to run this subcommand.
312 needs_root = getattr(self.subcommand, 'root_required', False)
313 self.assertEqual(self.needs_root, needs_root)
314266
=== modified file 'lpsetup/utils.py'
--- lpsetup/utils.py 2012-08-13 12:42:27 +0000
+++ lpsetup/utils.py 2012-08-13 15:03:21 +0000
@@ -97,7 +97,7 @@
97 return True97 return True
98 if response in ('n', 'no'):98 if response in ('n', 'no'):
99 return False99 return False
100 print("I didn't understand you. Please specify '(y)es' or'(n)o'.")100 print("I didn't understand you. Please specify '(y)es' or '(n)o'.")
101101
102102
103def get_container_path(lxc_name, path='', base_path=LXC_PATH):103def get_container_path(lxc_name, path='', base_path=LXC_PATH):

Subscribers

People subscribed via source and target branches

to all changes: