コード例 #1
0
def _validate_and_normalize(batch_data, filepath="unknown file"):
    status, message = validator.validate(batch_data)
    if status is not "OK":
        logging.warn(
            "Could not validate batch data from {filepath} ({status}: {message})"
            .format(filepath=filepath, status=status, message=message))
        return

    normalized = normalizer.normalize_batch(batch_data)
    return normalized
コード例 #2
0
def dump_data_for_command_line(data, normalize=True):
    if normalize:
        status, message = validator.validate(data)
        if status is not OK:
            logging.warn(
                "Could not validate data for dumping (status={status})".format(
                    status=status))
            return
        data = normalizer.normalize_batch(data)

    dumped = json.dumps(data)
    escaped = json.dumps(dumped)
    escaped_less = escaped.replace("\\\\\\\\", "\\\\")

    return escaped_less
コード例 #3
0
def from_json(json_content, already_normalized=True):
    batch_data = parser.from_json(json_content)

    if not already_normalized:
        status, message = validator.validate(batch_data)
        if status is not OK:
            logging.warn(
                "Could not validate JSON data (status:{status})".format(
                    status=status))
            return status, None

        batch = normalizer.normalize_batch(batch_data)
        return OK, batch

    else:
        return OK, batch_data
コード例 #4
0
    def test_whole_batch_without_environment(self):
        batch_data = _batch_data(environment_present=False)
        normalized = normalizer.normalize_batch(batch_data)

        self.assertDictEqual(
            normalized, _expected_normalized_batch(environment_present=False))
コード例 #5
0
    def test_whole_batch_no_plugins(self):
        self.mock_plugin_module.loaded_plugins.plugin_missing = True
        batch_data = _batch_data()
        normalized = normalizer.normalize_batch(batch_data)

        self.assertDictEqual(normalized, _expected_normalized_batch())
コード例 #6
0
    def test_whole_batch(self):
        batch_data = _batch_data()
        normalized = normalizer.normalize_batch(batch_data)

        self.assertDictEqual(normalized, _expected_normalized_batch())