yellow team mailing list archive
-
yellow team
-
Mailing list archive
-
Message #01071
[Merge] lp:~frankban/lpsetup/remove-smoke-tests into lp:lpsetup
Francesco Banconi has proposed merging lp:~frankban/lpsetup/remove-smoke-tests into lp:lpsetup.
Requested reviews:
Yellow Squad (yellow)
For more details, see:
https://code.launchpad.net/~frankban/lpsetup/remove-smoke-tests/+merge/119367
== 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.
--
https://code.launchpad.net/~frankban/lpsetup/remove-smoke-tests/+merge/119367
Your team Yellow Squad is requested to review the proposed merge of lp:~frankban/lpsetup/remove-smoke-tests into lp:lpsetup.
=== 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 @@
-#!/usr/bin/env python
-# Copyright 2012 Canonical Ltd. This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""Tests for the finish-init-host subcommand."""
-
-import unittest
-
-from lpsetup import handlers
-from lpsetup.subcommands import finish_inithost
-from lpsetup.tests.utils import (
- get_random_string,
- StepsBasedSubCommandTestMixin,
- )
-
-
-setup_launchpad_step = (
- finish_inithost.setup_launchpad, ['user', 'target_dir'])
-
-
-def get_arguments():
- target_dir = '~/' + get_random_string()
- user = get_random_string()
- return (target_dir, '-u', user)
-
-
-class FinishInitHostTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
-
- subcommand_class = finish_inithost.SubCommand
- expected_arguments = get_arguments()
- expected_handlers = (handlers.handle_user, handlers.handle_target_dir)
-
- @property
- def expected_steps(self):
- return (
- setup_launchpad_step,
- )
- needs_root = True
=== 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 @@
import tempfile
import unittest
-from lpsetup import handlers
from lpsetup.subcommands import inithost
-from lpsetup.tests.utils import (
- get_random_string,
- StepsBasedSubCommandTestMixin,
- )
-
-
-initialize_step = (inithost.initialize, ['user'])
-setup_home_step = (
- inithost.setup_home, ['user', 'full_name', 'email', 'lpuser',
- 'valid_ssh_keys', 'ssh_key_path',
- ])
-initialize_lxc_step = (inithost.initialize_lxc, [])
-setup_apt_step = (inithost.setup_apt, [])
-
-
-def get_arguments():
- user = get_random_string()
- email = get_random_string()
- full_name = get_random_string() + '@example.com'
- lpuser = get_random_string()
- ssh_key_name = get_random_string()
- return ('-u', user, '-E', email, '-f', full_name, '-l', lpuser,
- '-S', ssh_key_name)
-
-
-class InithostSmokeTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
-
- subcommand_class = inithost.SubCommand
- expected_arguments = get_arguments()
- expected_handlers = (
- handlers.handle_user,
- handlers.handle_lpuser_as_username,
- handlers.handle_userdata,
- handlers.handle_ssh_keys,
- )
- expected_steps = (initialize_step, setup_home_step, setup_apt_step)
- needs_root = True
+from lpsetup.tests.utils import get_random_string
class WriteFileContentsTestCase(unittest.TestCase):
=== 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 @@
-#!/usr/bin/env python
-# Copyright 2012 Canonical Ltd. This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""Tests for the initlxc subcommand."""
-
-import random
-import unittest
-
-from lpsetup import (
- handlers,
- settings,
- )
-from lpsetup.subcommands import initlxc
-from lpsetup.tests.subcommands import test_inithost
-from lpsetup.tests.utils import (
- get_random_string,
- StepsBasedSubCommandTestMixin,
- )
-
-initialize_step = (initlxc.initialize, ['user', 'install_haveged'])
-create_lxc_step = (
- initlxc.create_lxc,
- ['lxc_name', 'lxc_arch', 'lxc_os', 'user', 'install_subunit'])
-start_lxc_step = (initlxc.start_lxc, ['lxc_name'])
-wait_for_lxc_step = (initlxc.wait_for_lxc, ['lxc_name', 'ssh_key_path'])
-install_lpsetup_in_lxc_step = (
- initlxc.install_lpsetup_in_lxc, ['lxc_name', 'ssh_key_path', 'lxc_os',
- 'user', 'home_dir', 'lpsetup_branch'])
-inithost_in_lxc_step = (
- initlxc.inithost_in_lxc,
- ['lxc_name', 'ssh_key_path', 'user', 'email', 'full_name', 'lpuser',
- 'ssh_key_name', 'home_dir'])
-stop_lxc_step = (initlxc.stop_lxc, ['lxc_name', 'ssh_key_path'])
-
-
-def get_arguments():
- inithost_arguments = test_inithost.get_arguments()
- lxc_name = get_random_string()
- lxc_arch = random.choice(['i386', 'amd64'])
- lxc_os = random.choice(settings.LXC_GUEST_CHOICES)
- return (
- lxc_name, '-A', lxc_arch, '-R', lxc_os, '--stop-lxc',
- '--omit-subunit', '--omit-haveged') + inithost_arguments
-
-
-class InitLxcTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
-
- subcommand_class = initlxc.SubCommand
- expected_arguments = get_arguments()
- expected_handlers = (
- handlers.handle_user,
- handlers.handle_lpuser_as_username,
- handlers.handle_userdata,
- handlers.handle_ssh_keys,
- )
- expected_steps = (
- initialize_step,
- test_inithost.setup_home_step,
- create_lxc_step,
- start_lxc_step,
- wait_for_lxc_step,
- install_lpsetup_in_lxc_step,
- inithost_in_lxc_step,
- stop_lxc_step,
- )
- needs_root = True
=== 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 @@
run,
)
-from lpsetup import (
- cli,
- handlers,
- )
-from lpsetup.subcommands import initrepo
+from lpsetup import cli
from lpsetup.tests.utils import (
create_test_branch,
get_random_string,
lpuser,
skip_if_no_lpuser,
- StepsBasedSubCommandTestMixin,
)
from lpsetup.utils import ConfigParser
-fetch_step = (initrepo.fetch,
- ['source', 'repository', 'branch_name', 'checkout_name', 'no_checkout'])
-setup_bzr_locations_step = (initrepo.setup_bzr_locations,
- ['lpuser', 'repository', 'branch_name'])
-
-
-def get_arguments():
- return (
- '--source', get_random_string(),
- '--repository', get_random_string(),
- '--branch-name', get_random_string(),
- '--checkout-name', get_random_string(),
- '--no-checkout',
- )
-
-
-@skip_if_no_lpuser
-class InitrepoTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
-
- subcommand_class = initrepo.SubCommand
- expected_arguments = get_arguments()
- expected_handlers = (
- handlers.handle_user,
- handlers.handle_lpuser_from_lplogin,
- handlers.handle_directories,
- handlers.handle_branch_and_checkout,
- handlers.handle_source,
- )
- expected_steps = (
- fetch_step,
- setup_bzr_locations_step,
- )
- needs_root = False
-
-
-@skip_if_no_lpuser
-class IntegrationTest(unittest.TestCase):
+@skip_if_no_lpuser
+class InitrepoTest(unittest.TestCase):
def setUp(self):
"""Create a fake source bzr branch under `/tmp/`."""
=== 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 @@
-#!/usr/bin/env python
-# Copyright 2012 Canonical Ltd. This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""Tests for the install-lxc subcommand."""
-
-import unittest
-
-from lpsetup import handlers
-from lpsetup.subcommands import install_lxc
-from lpsetup.tests.subcommands import (
- test_initlxc,
- )
-from lpsetup.tests.utils import (
- get_random_string,
- StepsBasedSubCommandTestMixin,
- )
-
-
-create_scripts_step = (
- install_lxc.create_scripts, ['lxc_name', 'ssh_key_path', 'user'])
-
-init_repo_in_lxc_step = (
- install_lxc.init_repo_in_lxc, [
- 'lxc_name', 'ssh_key_path', 'home_dir', 'user', 'source', 'use_http',
- 'branch_name', 'checkout_name', 'repository', 'no_checkout',
- ])
-
-update_in_lxc_step = (
- install_lxc.update_in_lxc, [
- 'lxc_name', 'ssh_key_path', 'home_dir', 'user', 'external_path',
- 'target_dir', 'lp_source_deps', 'use_http',
- ])
-
-finish_inithost_in_lxc_step = (
- install_lxc.finish_inithost_in_lxc, [
- 'lxc_name', 'ssh_key_path', 'home_dir', 'user', 'target_dir',
- ])
-
-
-def get_arguments():
- repository = '~/' + get_random_string()
- return test_initlxc.get_arguments() + (
- '-r', repository,
- '--create-scripts',
- )
-
-
-class InstallLxcTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
-
- subcommand_class = install_lxc.SubCommand
- expected_arguments = get_arguments()
- expected_handlers = test_initlxc.InitLxcTest.expected_handlers + (
- handlers.handle_testing,
- handlers.handle_directories,
- handlers.handle_branch_and_checkout,
- handlers.handle_source,
- handlers.handle_target_from_repository,
- )
- expected_steps = test_initlxc.InitLxcTest.expected_steps[:-1] + (
- create_scripts_step,
- init_repo_in_lxc_step,
- update_in_lxc_step,
- finish_inithost_in_lxc_step,
- test_initlxc.stop_lxc_step,
- )
- needs_root = True
- maxDiff = None
=== 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 @@
-#!/usr/bin/env python
-# Copyright 2012 Canonical Ltd. This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""Tests for the update subcommand."""
-
-import unittest
-
-from lpsetup import handlers
-from lpsetup.subcommands import update
-from lpsetup.tests.utils import (
- get_random_string,
- StepsBasedSubCommandTestMixin,
- )
-
-
-def get_arguments():
- target_dir = '~/' + get_random_string()
- external_path = get_random_string()
- return (
- target_dir,
- '--external-path', external_path,
- '--use-http',
- )
-
-init_dir_step = (
- update.initialize_directories, ['target_dir', 'external_path'])
-update_dep_step = (
- update.update_dependencies, ['target_dir', 'external_path', 'use_http',
- 'lp_source_deps'])
-update_tree_step = (update.update_tree, ['target_dir'])
-
-
-class UpdateTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
-
- subcommand_class = update.SubCommand
- expected_arguments = get_arguments()
- expected_handlers = (handlers.handle_user, handlers.handle_target_dir)
- expected_steps = (
- init_dir_step,
- update_dep_step,
- update_tree_step,
- )
- needs_root = False
=== 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 @@
run,
)
-from lpsetup import (
- argparser,
- cli,
- )
+from lpsetup import argparser
from lpsetup.utils import call
@@ -266,48 +263,3 @@
'StepsBasedSubCommand',
(argparser.StepsBasedSubCommand,),
kwargs)()
-
-
-class StepsBasedSubCommandTestMixin(ParserTestMixin):
- """This mixin can be used to test subcommands steps and handlers.
-
- Real TestCases subclassing this mixin must define:
-
- - subcommand_class: the steps based subcommand class
- - expected_arguments: a sequence of command line arguments
- used by the current tested subcommand
- - expected_handlers: a sequence of expected handler callables
- - expected_steps: a sequence of expected *(step_callable, arg_names)*
- - needs_root: True if this subcommand must be run as root
-
- At this point steps and handlers are automatically tested, and the test
- case also checks if root is required by the subcommand.
- """
- def setUp(self):
- """Set up a namespace using *self.expected_arguments*."""
- super(StepsBasedSubCommandTestMixin, self).setUp()
- self.subcommand = self.subcommand_class()
- cli.prepare_parser(self.parser, self.subcommand)
- self.namespace = self.parser.parse_args(self.expected_arguments)
- argparser.init_namespace(self.namespace)
-
- def test_handlers(self):
- # Ensure this subcommand uses the expected handlers.
- handlers = self.subcommand.get_handlers(self.namespace)
- self.assertSequenceEqual(self.expected_handlers, handlers)
-
- def test_steps(self):
- # Ensure this subcommand wants to run the expected steps.
- self.subcommand.prepare_namespace(self.namespace)
- steps = argparser.resolve_steps(self.subcommand.steps, self.namespace)
- real_steps = [[step, list(args)] for step, args in steps]
- expected_steps = []
- for step, arg_names in self.expected_steps:
- args = [getattr(self.namespace, name) for name in arg_names]
- expected_steps.append([step, args])
- self.assertListEqual(expected_steps, real_steps)
-
- def test_needs_root(self):
- # The root user may or may not be required to run this subcommand.
- needs_root = getattr(self.subcommand, 'root_required', False)
- self.assertEqual(self.needs_root, needs_root)
=== 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 @@
return True
if response in ('n', 'no'):
return False
- print("I didn't understand you. Please specify '(y)es' or'(n)o'.")
+ print("I didn't understand you. Please specify '(y)es' or '(n)o'.")
def get_container_path(lxc_name, path='', base_path=LXC_PATH):