示例#1
0
    def validate_schema(self):
        """
        Validates that the verification step is obeying the required
        schema

        Returns True if backend schema is valid
        """
        try:
            jsonschema.validate(instance=self.step, schema=self.schema)
        except jsonschema.exceptions.ValidationError as e:
            raise exceptions.bzafInvalidSpecException(e)
        return True
示例#2
0
def validate_initial_bzaf_yaml(bzaf_text):
    """
    Performs initial validation of supplied text, checks if text is a valid
    bzaf spec

    Parameters:
        bzaf_text - Text parsed from comment

    Returns a JSON object if initial spec has passed schema validation
    """
    # Attempt to parse YAML from comment
    try:
        bzaf_json = yaml.safe_load(bzaf_text)
    except yaml.scanner.ScannerError as e:
        raise exceptions.bzafInvalidSpecException(e)
    except yaml.parser.ParserError as e:
        raise exceptions.bzafInvalidSpecException(e)
    # Attempt to validate YAML according to schema
    try:
        jsonschema.validate(instance=bzaf_json, schema=bzaf_schema)
    except jsonschema.exceptions.ValidationError as e:
        raise exceptions.bzafInvalidSpecException(e)
    return bzaf_json['bzaf']
示例#3
0
def validate_verifications_steps(bzaf_api_request):
    """
    Validates verification_steps from bzaf spec

    Parameters:
        bzaf_api_request - bzaf API request object
    """
    steps = bzaf_api_request.verification_steps
    # Iterate over steps in bzaf spec
    for step in steps:
        step_backend = step['backend']
        # Attempt to validate step according to schema
        try:
            jsonschema.validate(instance=step, schema=step_schema)
        except jsonschema.exceptions.ValidationError as e:
            raise exceptions.bzafInvalidSpecException(e)

        if not bzaf_api_request.backend_is_valid(step_backend):
            raise exceptions.bzafInvalidBackend(step_backend)
        bzaf_api_request.validate_verification_step(step)