def test_success_with_configuration(self): tmpdir, config_file = create_temp_bundle_with_contents({ 'bundle.conf': '{name="overlaid-name"}', 'config.sh': 'echo configuring' }) urlretrieve_mock = MagicMock(side_effect=[(self.bundle_file, ()), (config_file, ())]) http_method = self.respond_with(200, self.default_response) stdout = MagicMock() open_mock = MagicMock(return_value=1) with patch('conductr_cli.conduct_load.urlretrieve', urlretrieve_mock), \ patch('requests.post', http_method), \ patch('sys.stdout', stdout), \ patch('builtins.open', open_mock): args = self.default_args.copy() args.update({'configuration': config_file}) conduct_load.load(MagicMock(**args)) self.assertEqual( open_mock.call_args_list, [call(self.bundle_file, 'rb'), call(config_file, 'rb')] ) expected_files = self.default_files + [('configuration', ('bundle.zip', 1))] expected_files[4] = ('bundleName', 'overlaid-name') http_method.assert_called_with(self.default_url, files=expected_files) self.assertEqual(self.default_output(downloading_configuration='Retrieving configuration...\n'), self.output(stdout))
def test_success_with_configuration(self): tmpdir, config_file = create_temp_bundle_with_contents({ 'bundle.conf': '{name="overlaid-name"}', 'config.sh': 'echo configuring' }) request_headers_mock = MagicMock(return_value=self.mock_headers) resolve_bundle_mock = MagicMock(side_effect=[(self.bundle_name, self.bundle_file), ('config.zip', config_file)]) zip_entry_mock = MagicMock(side_effect=['mock bundle.conf', 'mock bundle.conf overlay']) http_method = self.respond_with(200, self.default_response) stdout = MagicMock() open_mock = MagicMock(return_value=1) wait_for_installation_mock = MagicMock() args = self.default_args.copy() args.update({'configuration': config_file}) input_args = MagicMock(**args) with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \ patch('conductr_cli.bundle_utils.zip_entry', zip_entry_mock), \ patch('conductr_cli.conduct_url.request_headers', request_headers_mock), \ patch('requests.post', http_method), \ patch('builtins.open', open_mock), \ patch('conductr_cli.bundle_installation.wait_for_installation', wait_for_installation_mock): logging_setup.configure_logging(input_args, stdout) result = conduct_load.load(input_args) self.assertTrue(result) self.assertEqual( resolve_bundle_mock.call_args_list, [ call(self.custom_settings, self.bundle_resolve_cache_dir, self.bundle_file), call(self.custom_settings, self.bundle_resolve_cache_dir, config_file) ] ) self.assertEqual( open_mock.call_args_list, [call(self.bundle_file, 'rb'), call(config_file, 'rb')] ) request_headers_mock.assert_called_with(input_args) expected_files = [ ('bundleConf', ('bundle.conf', 'mock bundle.conf')), ('bundleConfOverlay', ('bundle.conf', 'mock bundle.conf overlay')), ('bundle', ('bundle.zip', 1)), ('configuration', ('config.zip', 1)) ] http_method.assert_called_with(self.default_url, files=expected_files, timeout=LOAD_HTTP_TIMEOUT, headers=self.mock_headers) wait_for_installation_mock.assert_called_with(self.bundle_id, input_args) self.assertEqual(self.default_output(downloading_configuration='Retrieving configuration...\n'), self.output(stdout)) self.assertEqual( zip_entry_mock.call_args_list, [call('bundle.conf', self.bundle_file), call('bundle.conf', config_file)] )
def test_success_with_configuration(self): tmpdir, config_file = create_temp_bundle_with_contents({ 'bundle.conf': '{name="overlaid-name"}', 'config.sh': 'echo configuring' }) request_headers_mock = MagicMock(return_value=self.mock_headers) resolve_bundle_mock = MagicMock( side_effect=[(self.bundle_name, self.bundle_file), ('config.zip', config_file)]) http_method = self.respond_with(200, self.default_response) stdout = MagicMock() open_mock = MagicMock(return_value=1) wait_for_installation_mock = MagicMock() args = self.default_args.copy() args.update({'configuration': config_file}) input_args = MagicMock(**args) with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \ patch('conductr_cli.conduct_url.request_headers', request_headers_mock), \ patch('requests.post', http_method), \ patch('builtins.open', open_mock), \ patch('conductr_cli.bundle_installation.wait_for_installation', wait_for_installation_mock): logging_setup.configure_logging(input_args, stdout) result = conduct_load.load(input_args) self.assertTrue(result) self.assertEqual( open_mock.call_args_list, [call(self.bundle_file, 'rb'), call(config_file, 'rb')]) self.assertEqual(resolve_bundle_mock.call_args_list, [ call(self.custom_settings, self.bundle_resolve_cache_dir, self.bundle_file), call(self.custom_settings, self.bundle_resolve_cache_dir, config_file) ]) request_headers_mock.assert_called_with(input_args) expected_files = self.default_files + [('configuration', ('config.zip', 1))] expected_files[4] = ('bundleName', 'overlaid-name') http_method.assert_called_with(self.default_url, files=expected_files, timeout=LOAD_HTTP_TIMEOUT, headers=self.mock_headers) wait_for_installation_mock.assert_called_with(self.bundle_id, input_args) self.assertEqual( self.default_output( downloading_configuration='Retrieving configuration...\n'), self.output(stdout))
def test_success_with_configuration(self): tmpdir, config_file = create_temp_bundle_with_contents( {"bundle.conf": '{name="overlaid-name"}', "config.sh": "echo configuring"} ) resolve_bundle_mock = MagicMock(return_value=(self.bundle_file_name, self.bundle_file)) resolve_bundle_configuration_mock = MagicMock(return_value=("config.zip", config_file)) create_multipart_mock = MagicMock(return_value=self.multipart_mock) http_method = self.respond_with(200, self.default_response) stdout = MagicMock() open_mock = MagicMock(return_value=1) wait_for_installation_mock = MagicMock() args = self.default_args.copy() args.update({"configuration": config_file}) input_args = MagicMock(**args) with patch("conductr_cli.resolver.resolve_bundle", resolve_bundle_mock), patch( "conductr_cli.resolver.resolve_bundle_configuration", resolve_bundle_configuration_mock ), patch("conductr_cli.conduct_load.create_multipart", create_multipart_mock), patch( "requests.post", http_method ), patch( "builtins.open", open_mock ), patch( "conductr_cli.bundle_installation.wait_for_installation", wait_for_installation_mock ): logging_setup.configure_logging(input_args, stdout) result = conduct_load.load(input_args) self.assertTrue(result) self.assertEqual(open_mock.call_args_list, [call(self.bundle_file, "rb"), call(config_file, "rb")]) resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir, self.bundle_file) resolve_bundle_configuration_mock.assert_called_with( self.custom_settings, self.bundle_resolve_cache_dir, config_file ) expected_files = self.default_files + [("configuration", ("config.zip", 1))] expected_files[4] = ("bundleName", "overlaid-name") create_multipart_mock.assert_called_with(self.conduct_load_logger, expected_files) http_method.assert_called_with( self.default_url, data=self.multipart_mock, auth=self.conductr_auth, verify=self.server_verification_file, headers={"Content-Type": self.multipart_content_type, "Host": "127.0.0.1"}, ) wait_for_installation_mock.assert_called_with(self.bundle_id, input_args) self.assertEqual( self.default_output(downloading_configuration="Retrieving configuration..\n"), self.output(stdout) )
def test_success_with_configuration(self): tmpdir, config_file = create_temp_bundle_with_contents({ 'bundle.conf': '{name="overlaid-name"}', 'config.sh': 'echo configuring' }) resolve_bundle_mock = MagicMock(return_value=(self.bundle_file_name, self.bundle_file)) resolve_bundle_configuration_mock = MagicMock(return_value=('config.zip', config_file)) create_multipart_mock = MagicMock(return_value=self.multipart_mock) http_method = self.respond_with(200, self.default_response) stdout = MagicMock() open_mock = MagicMock(return_value=1) wait_for_installation_mock = MagicMock() args = self.default_args.copy() args.update({'configuration': config_file}) input_args = MagicMock(**args) with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \ patch('conductr_cli.resolver.resolve_bundle_configuration', resolve_bundle_configuration_mock), \ patch('conductr_cli.conduct_load.create_multipart', create_multipart_mock), \ patch('requests.post', http_method), \ patch('builtins.open', open_mock), \ patch('conductr_cli.bundle_installation.wait_for_installation', wait_for_installation_mock): logging_setup.configure_logging(input_args, stdout) result = conduct_load.load(input_args) self.assertTrue(result) self.assertEqual( open_mock.call_args_list, [call(self.bundle_file, 'rb'), call(config_file, 'rb')] ) resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir, self.bundle_file, self.offline_mode) resolve_bundle_configuration_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir, config_file, self.offline_mode) expected_files = self.default_files + [('configuration', ('config.zip', 1))] expected_files[4] = ('bundleName', 'overlaid-name') create_multipart_mock.assert_called_with(self.conduct_load_logger, expected_files) http_method.assert_called_with(self.default_url, data=self.multipart_mock, auth=self.conductr_auth, verify=self.server_verification_file, headers={'Content-Type': self.multipart_content_type, 'Host': '127.0.0.1'}) wait_for_installation_mock.assert_called_with(self.bundle_id, input_args) self.assertEqual(self.default_output(downloading_configuration='Retrieving configuration..\n'), self.output(stdout))
def test_success_with_configuration_no_bundle_conf(self): tmpdir, config_file = create_temp_bundle_with_contents( {'config.sh': 'echo configuring'}) resolve_bundle_mock = MagicMock(return_value=(self.bundle_file_name, self.bundle_file)) resolve_bundle_configuration_mock = MagicMock( return_value=('config.zip', config_file)) conf_mock = MagicMock(side_effect=['mock bundle.conf', None]) string_io_mock = MagicMock( return_value='mock bundle.conf - string i/o') create_multipart_mock = MagicMock(return_value=self.multipart_mock) http_method = self.respond_with(200, self.default_response) stdout = MagicMock() open_mock = MagicMock(return_value=(1, None)) bundle_open_mock = MagicMock(side_effect=lambda p1, p2, p3: (p1, 1)) wait_for_installation_mock = MagicMock() args = self.default_args.copy() args.update({'configuration': config_file}) input_args = MagicMock(**args) with patch('conductr_cli.resolver.resolve_bundle', resolve_bundle_mock), \ patch('conductr_cli.resolver.resolve_bundle_configuration', resolve_bundle_configuration_mock), \ patch('conductr_cli.bundle_utils.conf', conf_mock), \ patch('conductr_cli.conduct_load.string_io', string_io_mock), \ patch('conductr_cli.conduct_load.create_multipart', create_multipart_mock), \ patch('requests.post', http_method), \ patch('conductr_cli.bundle_utils.digest_extract_and_open', open_mock), \ patch('conductr_cli.conduct_load.open_bundle', bundle_open_mock), \ patch('conductr_cli.bundle_installation.wait_for_installation', wait_for_installation_mock): logging_setup.configure_logging(input_args, stdout) result = conduct_load.load(input_args) self.assertTrue(result) resolve_bundle_mock.assert_called_with(self.custom_settings, self.bundle_resolve_cache_dir, self.bundle_file, self.offline_mode) resolve_bundle_configuration_mock.assert_called_with( self.custom_settings, self.configuration_resolve_cache_dir, config_file, self.offline_mode) self.assertEqual( conf_mock.call_args_list, [call(self.bundle_file), call(config_file)]) string_io_mock.assert_called_with('mock bundle.conf') self.assertEqual(bundle_open_mock.call_args_list, [ call(self.bundle_file_name, self.bundle_file, 'mock bundle.conf') ]) self.assertEqual(open_mock.call_args_list, [call(config_file)]) expected_files = [('bundleConf', ('bundle.conf', 'mock bundle.conf - string i/o')), ('bundle', ('bundle.zip', 1)), ('configuration', ('config.zip', 1))] create_multipart_mock.assert_called_with(self.conduct_load_logger, expected_files) http_method.assert_called_with(self.default_url, data=self.multipart_mock, auth=self.conductr_auth, verify=self.server_verification_file, headers={ 'Content-Type': self.multipart_content_type, 'Host': '127.0.0.1' }) wait_for_installation_mock.assert_called_with(self.bundle_id, input_args) self.assertEqual( self.default_output( downloading_configuration='Retrieving configuration..\n'), self.output(stdout))