コード例 #1
0
    def test_mappings(self):
        # This is more of a linter than a test. If it passes, then
        # everything is fine. If it fails, then it means things are
        # not fine. Not fine? Yeah, it means that there are two fields
        # with the same name, but different types in the
        # mappings that share an index. That doesn't work in ES.

        # Doing it as a test seemed like a good idea since
        # it's likely to catch epic problems, but isn't in the runtime
        # code.

        # Verify mappings that share the same index don't conflict
        for index in es_utils.all_read_indexes():
            merged_mapping = {}

            for cls_name, mapping in list(es_utils.get_mappings(index).items()):
                mapping = mapping['properties']

                for key, val in list(mapping.items()):
                    if key not in merged_mapping:
                        merged_mapping[key] = (val, [cls_name])
                        continue

                    # FIXME - We're comparing two dicts here. This might
                    # not work for non-trivial dicts.
                    if merged_mapping[key][0] != val:
                        raise es_utils.MappingMergeError(
                            '%s key different for %s and %s' %
                            (key, cls_name, merged_mapping[key][1]))

                    merged_mapping[key][1].append(cls_name)
コード例 #2
0
ファイル: test_es.py プロジェクト: jayvdb/kitsune
    def test_mappings(self):
        # This is more of a linter than a test. If it passes, then
        # everything is fine. If it fails, then it means things are
        # not fine. Not fine? Yeah, it means that there are two fields
        # with the same name, but different types in the
        # mappings. That doesn't work in ES.

        # Doing it as a test seemed like a good idea since
        # it's likely to catch epic problems, but isn't in the runtime
        # code.

        merged_mapping = {}

        for cls_name, mapping in es_utils.get_mappings().items():
            mapping = mapping['properties']

            for key, val in mapping.items():
                if key not in merged_mapping:
                    merged_mapping[key] = (val, [cls_name])
                    continue

                # FIXME - We're comparing two dicts here. This might
                # not work for non-trivial dicts.
                if merged_mapping[key][0] != val:
                    raise es_utils.MappingMergeError(
                        '%s key different for %s and %s' %
                        (key, cls_name, merged_mapping[key][1]))

                merged_mapping[key][1].append(cls_name)