def setup_and_execute_app(self, argv, configuration): with self.a_temp_file() as config_location: with self.modified_env(HARPOON_CONFIG=config_location): app = App() args_obj, args_dict, extra_args = app.make_cli_parser().interpret_args(argv, app.cli_categories) collector = mock.Mock(name="collector") collector.configuration = configuration FakeCollector = mock.Mock(name="Collector", return_value=collector) docker_context = mock.Mock(name="docker_context") logging_handler = mock.Mock(name="logging_handler") setup_logging_theme = mock.Mock(name="setup_logging_theme") docker_context_maker = mock.Mock(name="docker_context_maker", return_value=docker_context) with mock.patch("harpoon.executor.Collector", FakeCollector): with mock.patch("harpoon.executor.docker_context", docker_context_maker): with mock.patch.object(app, "setup_logging_theme", setup_logging_theme): yield collector, docker_context_maker, docker_context, app, setup_logging_theme, args_dict app.execute(args_obj, args_dict, extra_args, logging_handler) FakeCollector.assert_called_once()
from input_algorithms.spec_base import NotSpecified from contextlib import contextmanager from tests.helpers import HarpoonCase from six import StringIO import mock import six import sys import os describe HarpoonCase, "App": describe "Cli parsing": it "replaces task and image with positional arguments": with self.a_temp_file() as config_location: argv = ["list_tasks", "blah", "--harpoon-config", config_location] app = App() args_obj, args_dict, extra_args = app.make_cli_parser().interpret_args(argv, app.cli_categories) self.assertEqual(args_obj.harpoon_chosen_task, "list_tasks") self.assertEqual(args_obj.harpoon_chosen_image, "blah") self.assertEqual(args_dict["harpoon"]["chosen_task"], "list_tasks") self.assertEqual(args_dict["harpoon"]["chosen_image"], "blah") it "takes in HARPOON_CONFIG as the configuration file": with self.a_temp_file() as config_location: with self.modified_env(HARPOON_CONFIG=config_location): argv = ["list_tasks", "blah"] app = App() args_obj, args_dict, extra_args = app.make_cli_parser().interpret_args(argv, app.cli_categories) self.assertEqual(args_obj.harpoon_config().name, config_location) self.assertEqual(args_dict["harpoon"]["config"]().name, config_location)