Example #1
0
    def validate_search(self, query):
        """
            Validate the search query payload

            :query: the search query object
        """
        validator = Validator(Schemas().search, purge_unknown=True)
        query = validator.normalized(query)
        validation = validator.validate(query)
        if not validation:
            raise ValidationError(validator.errors)
        return query
Example #2
0
    def validate_dashboard_query(self, query):
        """
            Validate the dashboard search query

            :query: the search query to get the dashboard data
        """
        validator = Validator(Schemas().dashboard, purge_unknown=True)
        query = validator.normalized(query)
        validation = validator.validate(query)
        if not validation:
            raise ValidationError(validator.errors)
        return query
Example #3
0
    def validate_scenario_add(self, report_id, scenario):
        """
            Validate a scenario object

            :report_id: the report id
            :scenario: the scenario data
        """
        validator = Validator(Schemas().scenario, purge_unknown=True)
        scenario = validator.normalized(scenario)
        validation = validator.validate(scenario)
        if not validation:
            raise ValidationError(validator.errors)
        return scenario
Example #4
0
    def validate_step_add(self, report_id, step):
        """
            Validate a step object

            :report_id: the report id
            :step: the step data
        """
        validator = Validator(Schemas().step, purge_unknown=True)
        step = validator.normalized(step)
        validation = validator.validate(step)
        if not validation:
            raise ValidationError(validator.errors)
        return step
Example #5
0
    def validate_feature_report(self, data, update, normalize):
        """
            Validate a feature report

            :data: the feature data
            :update: should service validate report as an update action
            :normalize: should default values be defined
        """
        validator = Validator(Schemas().feature_report, purge_unknown=True)
        data = self.normalize(normalize, data, validator)
        validation = validator.validate(data, update=update)
        if not validation:
            raise ValidationError(validator.errors)
        return data
Example #6
0
    def validate_report(self, data, update=False, normalize=True):
        """
            Validate a feature/set report

            :data: the request payload
            :update: should service validate report as an update action
            :normalize: should default values be defined
        """
        validator = Validator(Schemas().report, allow_unknown=True)
        data = self.normalize(normalize, data, validator)
        validation = validator.validate(data, update=update)
        if not validation:
            raise ValidationError(validator.errors)
        return self.validate_report_type(data, update, normalize)
Example #7
0
    def validate_add(self, report_id, data):
        """
            Validate add type

            :report_id: the report id we are modifying
            :data: the data we want to add to the report
        """
        validator = Validator(Schemas().add, allow_unknown=True)
        validation = validator.validate(data)
        if not validation:
            raise ValidationError(validator.errors)
        if data["type"] == "test":
            data = self.validate_step_add(report_id, data)
        elif data["type"] == "scenario":
            data = self.validate_scenario_add(report_id, data)
        return data
Example #8
0
    def validate_report_type(self, data, update, normalize):
        """
            Validate report type

            :data: the report
            :update: should service validate report as an update action
            :normalize: should default values be defined
        """
        validator = Validator(Schemas().kind, allow_unknown=True)
        data = self.normalize(normalize, data, validator)
        validation = validator.validate(data)
        if not validation:
            raise ValidationError(validator.errors)
        if data["kind"] == "set":
            data = self.validate_set_report(data, update, normalize)
        elif data["kind"] == "feature":
            data = self.validate_feature_report(data, update, normalize)
        return data