def test_should_pass_config_path_as_none( self, mock_save_click_preferences, mock_save_config_file_preferences, ): preferences = {"foo": "bar"} settings.save_preferences(**preferences) mock_save_config_file_preferences.assert_called_with(None) mock_save_click_preferences.assert_called_with(**preferences)
def test_should_pass_config_path( self, mock_save_click_preferences, mock_save_config_file_preferences, ): preferences = {"config_path": "foo.yaml"} settings.save_preferences(**preferences) mock_save_config_file_preferences.assert_called_with("foo.yaml") mock_save_click_preferences.assert_called_with(**preferences)
def run( spec_path, output_path, no_report, config_path, template, log_level, open_browser, ): """ Automated Testing and Documentation for your REST API. SPEC_PATH argument is the API specification file path. """ logging.basicConfig(level=log_level, format="%(message)s") logger = logging.getLogger(__name__) click_preferences = { "spec_path": spec_path, "output_path": output_path, "no_report": no_report, "config_path": config_path, "template": template, "open_browser": open_browser, } try: settings.save_preferences(**click_preferences) except yaml.YAMLError as e: error_message = "Error loading configuration file." error_message = "{}\nPyYAML: {}".format(error_message, str(e)) logger.error(error_message) raise SystemExit(ExitCode.USAGE_ERROR) scan()
def run(spec_path, output_path, config_path, template, log_level): """ Automated Testing and Documentation for your REST API. SPEC_PATH argument is the API specification file path. """ logging.basicConfig(level=log_level, format="%(message)s") logger = logging.getLogger(__name__) click_preferences = { "spec_path": spec_path, "output_path": output_path, "config_path": config_path, "template": template, } settings.save_preferences(**click_preferences) scan()
def scan(spec_path, output_path, config_path, reporter, template, log_level): """Automated Testing and Documentation for your REST API.""" logging.basicConfig(level=log_level, format="%(message)s") logger = logging.getLogger(__name__) settings.save_preferences( **{ "spec_path": spec_path, "output_path": output_path, "config_path": config_path, "reporter": reporter, "template": template, }) spec_path = settings["spec_path"] try: api_spec = load_config_file(spec_path) except FileNotFoundError as e: error_message = f"Could not find API spec file: {spec_path}. {str(e)}" logger.error(error_message) return except EmptyConfigFileError as e: error_message = f"API spec file is empty. {str(e)}" logger.error(error_message) return except (yaml.YAMLError, FileFormatNotSupportedError) as e: logger.error(e) return try: if API_KEY not in api_spec: raise MissingMandatoryKeyError({API_KEY}, ROOT_SCOPE) root_node = EndpointNode(api_spec[API_KEY]) Reporter(settings["output_path"], settings["reporter"], settings["template"]).write(root_node.run()) except (InvalidKeyError, MissingMandatoryKeyError, KeyError) as e: error_message = "Error loading API spec." error_message = "{} {}".format(error_message, str(e)) logger.error(error_message) return