Ejemplo n.º 1
0
 def check_deprecated_validate(name):
     nfuncs = len(self.validate_functions)
     block = response_block.get(name, {})
     if isinstance(block, dict):
         check_ext_functions(block.get("$ext", None))
         if nfuncs != len(self.validate_functions):
             raise exceptions.InvalidExtBlockException(name, )
Ejemplo n.º 2
0
    def _validate_block(self, blockname, block):
        """Validate a block of the response

        Args:
            blockname (str): which part of the response is being checked
            block (dict): The actual part being checked
        """
        try:
            expected_block = self.expected[blockname] or {}
        except KeyError:
            expected_block = {}

        if isinstance(expected_block, dict):
            if expected_block.pop("$ext", None):
                raise exceptions.InvalidExtBlockException(blockname, )

        if blockname == "headers":
            # Special case for headers. These need to be checked in a case
            # insensitive manner
            block = {i.lower(): j for i, j in block.items()}
            expected_block = {i.lower(): j for i, j in expected_block.items()}

        logger.debug("Validating response %s against %s", blockname,
                     expected_block)

        test_strictness = self.test_block_config["strict"]
        block_strictness = test_strictness.setting_for(blockname).is_on()
        self.recurse_check_key_match(expected_block, block, blockname,
                                     block_strictness)
Ejemplo n.º 3
0
    def _get_payload_vals(self):
        # TODO move this check to initialisation/schema checking
        if "json" in self.expected:
            if "payload" in self.expected:
                raise exceptions.BadSchemaError(
                    "Can only specify one of 'payload' or 'json' in MQTT response"
                )

            payload = self.expected["json"]
            json_payload = True

            if payload.pop("$ext", None):
                raise exceptions.InvalidExtBlockException("json", )
        elif "payload" in self.expected:
            payload = self.expected["payload"]
            json_payload = False
        else:
            payload = None
            json_payload = False

        return payload, json_payload