def test_find_values_with_key__return_values__when_found_many_non_unique_in_nested_obj_4_levels(
            self):
        # given
        dikt = {
            'key': {
                'key': {
                    'key': {
                        'key': {
                            'ref': 'value'
                        },
                        'ref': 'value3'
                    },
                    'ref': 'value3'
                },
                'ref': 'value3'
            },
            'ref': 'value2'
        }

        # when
        result = find_values_with_key('ref', dikt)

        # then
        self.assertEqual(
            sorted(list(result)),
            sorted(['value', 'value2', 'value3', 'value3', 'value3']))
    def test_find_values_with_key__return_values__when_in_obj(self):
        # given
        dikt = {'ref': 'value'}

        # when
        result = find_values_with_key('ref', dikt)

        # then
        self.assertEqual(list(result), ['value'])
    def test_find_values_with_key__return_empty_generator__when_not_in_obj(
            self):
        # given
        dikt = {'key': 'value'}

        # when
        result = find_values_with_key('ref', dikt)

        # then
        self.assertEqual(list(result), [])
    def test_find_values_with_key__return_values__when_obj_in_many_nested_list(
            self):
        # given
        dikt = {
            'key': [{
                'key': [{
                    'key': [{
                        'ref': 'value0'
                    }]
                }]
            }, {
                'key': [{
                    'key': [{
                        'ref': 'value1'
                    }]
                }]
            }, {
                'key': [{
                    'key': [{
                        'ref': 'value2'
                    }]
                }]
            }, {
                'key': [{
                    'key': [{
                        'ref': 'value3'
                    }]
                }]
            }, {
                'key': [{
                    'key': [{
                        'ref': 'value3'
                    }]
                }]
            }, {
                'key': [{
                    'key': [{
                        'ref': 'value3'
                    }]
                }]
            }]
        }

        # when
        result = find_values_with_key('ref', dikt)

        # then
        self.assertEqual(
            list(result),
            ['value0', 'value1', 'value2', 'value3', 'value3', 'value3'])
    def update_refs_urls(self, version_map, schema_base_url) -> dict:
        ref_changes = {}
        entity_version = get_version(self.schema_path, version_map)
        for schema_ref in find_values_with_key("$ref", self.json):
            if schema_base_url not in schema_ref:
                ref_path = schema_ref.replace(".json", "")
                ref_path_parts = ref_path.split("/")
                ref_path_parts_len = len(ref_path_parts)

                if "#" in ref_path:
                    for i in range(0, ref_path_parts_len):
                        if "#" in ref_path_parts[i]:
                            ref_path_parts.insert(i, entity_version)
                            break
                else:
                    ref_version = get_version(ref_path, version_map)
                    ref_path_parts.insert(ref_path_parts_len - 1, ref_version)

                new_schema_ref = schema_base_url + "/".join(ref_path_parts)
                ref_changes[schema_ref] = new_schema_ref

        immutable_schema = ImmutableDict(self.json)
        self.json = immutable_schema.replace_values_with_key("$ref", ref_changes)
        return self.json