diff --git a/tavern/_core/schema/files.py b/tavern/_core/schema/files.py index a2661c37..2672c1ab 100644 --- a/tavern/_core/schema/files.py +++ b/tavern/_core/schema/files.py @@ -21,7 +21,7 @@ class SchemaCache: """Caches loaded schemas""" def __init__(self) -> None: - self._loaded: Dict[str, dict] = {} + self._loaded: Dict[str, Dict] = {} def _load_base_schema(self, schema_filename): try: @@ -33,37 +33,37 @@ def _load_base_schema(self, schema_filename): return self._loaded[schema_filename] - def _load_schema_with_plugins(self, schema_filename): + def _load_schema_with_plugins(self, schema_filename: str) -> Dict: mangled = f"{schema_filename}-plugins" try: return self._loaded[mangled] except KeyError: - plugins = load_plugins() - base_schema = copy.deepcopy(self._load_base_schema(schema_filename)) - - logger.debug("Adding plugins to schema: %s", plugins) - - for p in plugins: - try: - plugin_schema = p.plugin.schema - except AttributeError: - # Don't require a schema - logger.debug("No schema defined for %s", p.name) - else: - base_schema["properties"].update( - plugin_schema.get("properties", {}) - ) - - self._loaded[mangled] = base_schema - return self._loaded[mangled] + pass + + plugins = load_plugins() + base_schema = copy.deepcopy(self._load_base_schema(schema_filename)) + + logger.debug("Adding plugins to schema: %s", [p.name for p in plugins]) + + for p in plugins: + try: + plugin_schema = p.plugin.schema + except AttributeError: + # Don't require a schema + logger.debug("No schema defined for %s", p.name) + else: + base_schema["properties"].update(plugin_schema.get("properties", {})) + + self._loaded[mangled] = base_schema + return self._loaded[mangled] - def __call__(self, schema_filename, with_plugins): + def __call__(self, schema_filename: str, with_plugins: bool): """Load the schema file and cache it for future use Args: - schema_filename (str): filename of schema - with_plugins (bool): Whether to load plugin schema into this schema as well + schema_filename: filename of schema + with_plugins: Whether to load plugin schema into this schema as well Returns: loaded schema @@ -83,8 +83,8 @@ def __call__(self, schema_filename, with_plugins): def verify_pykwalify(to_verify, schema) -> None: """Verify a generic file against a given pykwalify schema Args: - to_verify (dict): Filename of source tests to check - schema (dict): Schema to verify against + to_verify: Filename of source tests to check + schema: Schema to verify against Raises: BadSchemaError: Schema did not match """ @@ -111,7 +111,7 @@ def wrapfile(to_wrap): """Wrap a dictionary into a temporary yaml file Args: - to_wrap (dict): Dictionary to write to temporary file + to_wrap: Dictionary to write to temporary file Yields: filename: name of temporary file object that will be destroyed at the end of the @@ -136,7 +136,8 @@ def verify_tests(test_spec: Mapping, with_plugins: bool = True) -> None: Load schema file once. Requires some caching of the file Args: - test_spec (dict): Test in dictionary form + test_spec: Test in dictionary form + with_plugins: Whether to load plugin schema into this schema as well Raises: BadSchemaError: Schema did not match diff --git a/tavern/_plugins/rest/request.py b/tavern/_plugins/rest/request.py index 06e40fbe..1c1a2861 100644 --- a/tavern/_plugins/rest/request.py +++ b/tavern/_plugins/rest/request.py @@ -24,7 +24,7 @@ logger: logging.Logger = logging.getLogger(__name__) -def get_request_args(rspec: Dict, test_block_config: TestConfig) -> dict: +def get_request_args(rspec: Dict, test_block_config: TestConfig) -> Dict: """Format the test spec given values inthe global config Todo: @@ -150,8 +150,6 @@ def add_request_args(keys, optional): # Ones that are required and are enforced to be present by the schema required_in_file = ["method", "url"] - optional_with_default = {"verify": True, "stream": False} - add_request_args(["file_body"], True) add_request_args(required_in_file, False) add_request_args(RestRequest.optional_in_file, True) @@ -184,8 +182,11 @@ def add_request_args(keys, optional): if isinstance(value, dict): request_args["params"][key] = quote_plus(json.dumps(value)) - for key, val in optional_with_default.items(): - request_args[key] = fspec.get(key, val) + optional = {"verify", "stream"} + + for key in optional: + if key in fspec: + request_args[key] = fspec[key] # TODO # requests takes all of these - we need to parse the input to get them