def test_gather_results_on_py27(fx_copy_fn_main_mock_integration, fx_cmd_line_args_codegen_base, fx_get_sub_parser): mock_integration_name = fx_copy_fn_main_mock_integration[0] path_fn_main_mock_integration = fx_copy_fn_main_mock_integration[1] # Replace cmd line arg "fn_main_mock_integration" with path to temp dir location sys.argv[sys.argv.index( mock_integration_name)] = path_fn_main_mock_integration # Add arg to gather-results and a path to a mock export.res file for --reload sys.argv.extend(["--gather-results", mock_paths.MOCK_APP_LOG_PATH]) cmd_codegen = CmdCodegen(fx_get_sub_parser) args = cmd_codegen.parser.parse_known_args()[0] if not sdk_helpers.is_python_min_supported_version(): with pytest.raises(SDKException, match=constants.ERROR_WRONG_PYTHON_VERSION): cmd_codegen.execute_command(args) else: cmd_codegen.execute_command(args)
def test_get_results_from_log_file_specific_function( fx_copy_fn_main_mock_integration, fx_cmd_line_args_codegen_base, fx_get_sub_parser, caplog): mock_integration_name = fx_copy_fn_main_mock_integration[0] path_fn_main_mock_integration = fx_copy_fn_main_mock_integration[1] # Replace cmd line arg "fn_main_mock_integration" with path to temp dir location sys.argv[sys.argv.index( mock_integration_name)] = path_fn_main_mock_integration # Add arg to gather-results sys.argv.extend(["--gather-results", mock_paths.MOCK_APP_LOG_PATH]) sys.argv.extend(["-f", "mock_function_one", "mock_function_not_exist"]) cmd_codegen = CmdCodegen(fx_get_sub_parser) args = cmd_codegen.parser.parse_known_args()[0] cmd_codegen.execute_command(args) path_payload_samples = os.path.join( path_fn_main_mock_integration, package_helpers.BASE_NAME_PAYLOAD_SAMPLES_DIR) # Test output_json_example.json file generated output_json_example_contents = sdk_helpers.read_json_file( os.path.join(path_payload_samples, "mock_function_one", package_helpers.BASE_NAME_PAYLOAD_SAMPLES_EXAMPLE)) assert output_json_example_contents.get("version") == 2.1 # Test output_json_schema.json file generated output_json_example_schema = sdk_helpers.read_json_file( os.path.join(path_payload_samples, "mock_function_one", package_helpers.BASE_NAME_PAYLOAD_SAMPLES_SCHEMA)) output_json_example_schema_props = output_json_example_schema.get( "properties") assert output_json_example_schema_props.get("version") == { "type": "number" } assert output_json_example_schema_props.get("success") == { "type": "boolean" } assert output_json_example_schema_props.get("reason") == {} assert not output_json_example_schema.get("required") # Test WARNING log appears assert "WARNING: No results could be found for 'mock_function_not_exist'" in caplog.text
def test_get_results_from_log_file_no_payload_samples_dir( fx_copy_fn_main_mock_integration, fx_cmd_line_args_codegen_base, fx_get_sub_parser, caplog): mock_integration_name = fx_copy_fn_main_mock_integration[0] path_fn_main_mock_integration = fx_copy_fn_main_mock_integration[1] # Replace cmd line arg "fn_main_mock_integration" with path to temp dir location sys.argv[sys.argv.index( mock_integration_name)] = path_fn_main_mock_integration # Add arg to gather-results and a path to a mock export.res file for --reload sys.argv.extend(["--gather-results", mock_paths.MOCK_APP_LOG_PATH]) sys.argv.extend(["-e", mock_paths.MOCK_RELOAD_EXPORT_RES]) path_payload_samples = os.path.join( path_fn_main_mock_integration, package_helpers.BASE_NAME_PAYLOAD_SAMPLES_DIR) # Remove path_payload_samples shutil.rmtree(path_payload_samples) cmd_codegen = CmdCodegen(fx_get_sub_parser) args = cmd_codegen.parser.parse_known_args()[0] cmd_codegen.execute_command(args) # Test output_json_example.json file generated output_json_example_contents = sdk_helpers.read_json_file( os.path.join(path_payload_samples, "mock_function_one", package_helpers.BASE_NAME_PAYLOAD_SAMPLES_EXAMPLE)) assert output_json_example_contents.get("version") == 2.1 # Test output_json_schema.json file generated output_json_example_schema = sdk_helpers.read_json_file( os.path.join(path_payload_samples, "mock_function_one", package_helpers.BASE_NAME_PAYLOAD_SAMPLES_SCHEMA)) output_json_example_schema_props = output_json_example_schema.get( "properties") assert output_json_example_schema_props.get("version") == { "type": "number" } assert output_json_example_schema_props.get("reason") == {} # Test --reload was ran assert "Running 'codegen --reload' to create the default missing files" in caplog.text
def main(): """ Main entry point for resilient-sdk """ # See if RES_SDK_DEV environment var is set sdk_dev = sdk_helpers.str_to_bool(os.getenv("RES_SDK_DEV")) # Get main parser object parser = get_main_app_parser() # Get sub_parser object, its dest is cmd sub_parser = get_main_app_sub_parser(parser) # Add any subcommands to main app parser here cmd_codegen = CmdCodegen(sub_parser) cmd_clone = CmdClone(sub_parser) cmd_docgen = CmdDocgen(sub_parser) cmd_extract = CmdExtract(sub_parser) cmd_ext_package = CmdExtPackage(sub_parser) if sdk_dev: # Add 'dev' command if environment var set cmd_dev = CmdDev(sub_parser) try: # Parse the arguments args = parser.parse_args() if args.cmd is None: parser.print_help() sys.exit() except SDKException as err: # Get main_cmd (codegen, docgen etc.) main_cmd = sdk_helpers.get_main_cmd() LOG.error(err) LOG.info("\n-----------------\n") # Print specifc usage for that cmd for these errors if "too few arguments" in err.message or "no subcommand provided" in err.message: if main_cmd == cmd_codegen.CMD_NAME: cmd_codegen.parser.print_usage() elif main_cmd == cmd_clone.CMD_NAME: cmd_clone.parser.print_usage() elif main_cmd == cmd_docgen.CMD_NAME: cmd_docgen.parser.print_usage() elif main_cmd == cmd_extract.CMD_NAME: cmd_extract.parser.print_usage() elif main_cmd == cmd_ext_package.CMD_NAME: cmd_ext_package.parser.print_usage() elif sdk_dev and main_cmd == cmd_dev.CMD_NAME: cmd_dev.parser.print_usage() else: parser.print_help() # Exit sys.exit() # If -v was specified, set the log level to DEBUG if args.verbose: LOG.setLevel(logging.DEBUG) LOG.debug("Logging set to DEBUG mode") # Handle what subcommand was called if args.cmd == cmd_docgen.CMD_NAME: cmd_docgen.execute_command(args) elif args.cmd == cmd_codegen.CMD_NAME: cmd_codegen.execute_command(args) elif args.cmd == cmd_clone.CMD_NAME: cmd_clone.execute_command(args) elif args.cmd == cmd_extract.CMD_NAME: cmd_extract.execute_command(args) elif args.cmd == cmd_ext_package.CMD_NAME: cmd_ext_package.execute_command(args) elif sdk_dev and args.cmd == cmd_dev.CMD_NAME: cmd_dev.execute_command(args)
def main(): """ Main entry point for resilient-sdk """ # add color support for WINDOWS os.system("") # See if RES_SDK_DEV environment var is set sdk_dev = sdk_helpers.is_env_var_set(constants.ENV_VAR_DEV) # Get main parser object parser = get_main_app_parser() # Get sub_parser object, its dest is cmd sub_parser = get_main_app_sub_parser(parser) if sdk_dev: # Add 'dev' command if environment var set cmd_dev = CmdDev(sub_parser) LOG.info("{0}Running SDK in Developer Mode{0}".format(constants.LOG_DIVIDER)) # Add any subcommands to main app parser here cmd_validate = CmdValidate(sub_parser) cmd_codegen = CmdCodegen(sub_parser) cmd_clone = CmdClone(sub_parser) cmd_docgen = CmdDocgen(sub_parser) cmd_extract = CmdExtract(sub_parser) cmd_ext_package = CmdExtPackage(sub_parser, cmd_validate=cmd_validate) try: # Parse the arguments args = parser.parse_args() if args.cmd is None: parser.print_help() sys.exit() except SDKException as err: # Get main_cmd (codegen, docgen etc.) main_cmd = sdk_helpers.get_main_cmd() LOG.error(err) LOG.info("{0}".format(constants.LOG_DIVIDER)) # Print specifc usage for that cmd for these errors if "too few arguments" in err.message or "no subcommand provided" in err.message: if main_cmd == cmd_codegen.CMD_NAME: cmd_codegen.parser.print_usage() elif main_cmd == cmd_clone.CMD_NAME: cmd_clone.parser.print_usage() elif main_cmd == cmd_docgen.CMD_NAME: cmd_docgen.parser.print_usage() elif main_cmd == cmd_extract.CMD_NAME: cmd_extract.parser.print_usage() elif main_cmd == cmd_ext_package.CMD_NAME: cmd_ext_package.parser.print_usage() elif main_cmd == cmd_validate.CMD_NAME: cmd_validate.parser.print_usage() elif sdk_dev and main_cmd == cmd_dev.CMD_NAME: cmd_dev.parser.print_usage() else: parser.print_help() # Exit sys.exit() # If -v was specified, set the log level to DEBUG if args.verbose: LOG.setLevel(logging.DEBUG) LOG.debug("Logging set to DEBUG mode") # Handle what subcommand was called if args.cmd == cmd_docgen.CMD_NAME: cmd_docgen.execute_command(args) elif args.cmd == cmd_codegen.CMD_NAME: cmd_codegen.execute_command(args) elif args.cmd == cmd_clone.CMD_NAME: cmd_clone.execute_command(args) elif args.cmd == cmd_extract.CMD_NAME: cmd_extract.execute_command(args) elif args.cmd == cmd_ext_package.CMD_NAME: cmd_ext_package.execute_command(args) elif args.cmd == cmd_validate.CMD_NAME: cmd_validate.execute_command(args) elif sdk_dev and args.cmd == cmd_dev.CMD_NAME: cmd_dev.execute_command(args)