def test_object_factory(self): self.assertIsInstance(ObjectDto.factory(Object.factory("object", "v1")), ObjectObjectDto) self.assertIsInstance(ObjectDto.factory(Object.factory("array", "v1")), ObjectArrayDto) self.assertIsInstance(ObjectDto.factory(Object.factory("number", "v1")), ObjectDto) self.assertIsInstance(ObjectDto.factory(Object.factory("string", "v1")), ObjectDto) self.assertIsInstance(ObjectDto.factory(Object.factory("bool", "v1")), ObjectDto) self.assertIsInstance(ObjectDto.factory(Object.factory("type", "v1")), ObjectTypeDto) self.assertIsInstance(ObjectDto.factory(Object.factory("none", "v1")), ObjectDto) self.assertIsInstance(ObjectDto.factory(Object.factory("dynamic", "v1")), ObjectDynamicDto) self.assertIsInstance(ObjectDto.factory(Object.factory("const", "v1")), ObjectConstDto) self.assertIsInstance(ObjectDto.factory(Object.factory("enum", "v1")), ObjectEnumDto)
def test_object_factory(self): self.assertIsInstance(ObjectDto.factory(Object.factory("object", "v1")), ObjectObjectDto) self.assertIsInstance(ObjectDto.factory(Object.factory("array", "v1")), ObjectArrayDto) self.assertIsInstance(ObjectDto.factory(Object.factory("number", "v1")), ObjectDto) self.assertIsInstance(ObjectDto.factory(Object.factory("string", "v1")), ObjectDto) self.assertIsInstance(ObjectDto.factory(Object.factory("boolean", "v1")), ObjectDto) self.assertIsInstance(ObjectDto.factory(Object.factory("type", "v1")), ObjectTypeDto) self.assertIsInstance(ObjectDto.factory(Object.factory("none", "v1")), ObjectDto) self.assertIsInstance(ObjectDto.factory(Object.factory("dynamic", "v1")), ObjectDynamicDto) self.assertIsInstance(ObjectDto.factory(Object.factory("const", "v1")), ObjectConstDto) self.assertIsInstance(ObjectDto.factory(Object.factory("enum", "v1")), ObjectEnumDto)
def hydrate_object(self, dto_object, source_object): if source_object is None: return 0 source_dto = Object.factory(source_object) changes = 0 find = None for versioned_value in dto_object: if versioned_value.value == source_dto: versioned_value.versions.append(self.version_name) find = versioned_value changes += 1 if self.has_changed(versioned_value) else 0 if find is None: changes += 1 if source_dto.type is ObjectRaw.Types.object: for (property_name, property_value) in source_object.properties.items(): source_dto.properties[property_name] = [] changes += self.hydrate_object(source_dto.properties[property_name], property_value) elif source_dto.type is ObjectRaw.Types.array: source_dto.items = [] changes += self.hydrate_object(source_dto.items, source_object.items) elif source_dto.type is ObjectRaw.Types.dynamic: source_dto.items = [] changes += self.hydrate_object(source_dto.items, source_object.items) elif source_dto.type is ObjectRaw.Types.enum: source_dto.values = [] source_dto.descriptions = [] self.hydrate_list(source_dto.values, sorted(source_object.values)) self.hydrate_list(source_dto.descriptions, sorted(source_object.descriptions)) elif source_dto.type is ObjectRaw.Types.type: source_dto.type_object = source_object.type_object dto_object.append(MultiVersion(source_dto, self.version_name)) else: if source_dto.type is ObjectRaw.Types.object: for (property_name, property_value) in source_object.properties.items(): if find.value.type is ObjectRaw.Types.object and property_name in find.value.properties.keys(): changes += self.hydrate_object(find.value.properties[property_name], property_value) else: find.value.properties[property_name] = [] changes += self.hydrate_object(find.value.properties[property_name], property_value) elif source_dto.type is ObjectRaw.Types.array: changes += self.hydrate_object(find.value.items, source_object.items) elif source_dto.type is ObjectRaw.Types.dynamic: changes += self.hydrate_object(find.value.items, source_object.items) elif source_dto.type is ObjectRaw.Types.enum: changes += self.hydrate_list(find.value.values, source_object.values) changes += self.hydrate_list(find.value.descriptions, source_object.descriptions) return changes
def hydrate_object(self, dto_object, source_object): if source_object is None: return 0 source_dto = Object.factory(source_object) changes = 0 find = None for versioned_value in dto_object: if versioned_value.value == source_dto: versioned_value.versions.append(self.version_name) find = versioned_value changes += 1 if self.has_changed(versioned_value) else 0 if find is None: changes += 1 if source_dto.type is ObjectRaw.Types.object: for (property_name, property_value) in source_object.properties.items(): source_dto.properties[property_name] = [] changes += self.hydrate_object( source_dto.properties[property_name], property_value) elif source_dto.type is ObjectRaw.Types.array: source_dto.items = [] changes += self.hydrate_object(source_dto.items, source_object.items) elif source_dto.type is ObjectRaw.Types.dynamic: source_dto.items = [] changes += self.hydrate_object(source_dto.items, source_object.items) elif source_dto.type is ObjectRaw.Types.enum: source_dto.values = [] source_dto.descriptions = [] self.hydrate_list(source_dto.values, sorted(source_object.values)) self.hydrate_list(source_dto.descriptions, sorted(source_object.descriptions)) elif source_dto.type is ObjectRaw.Types.type: source_dto.type_object = source_object.type_object dto_object.append(MultiVersion(source_dto, self.version_name)) else: if source_dto.type is ObjectRaw.Types.object: for (property_name, property_value) in source_object.properties.items(): if find.value.type is ObjectRaw.Types.object and property_name in find.value.properties.keys( ): changes += self.hydrate_object( find.value.properties[property_name], property_value) else: find.value.properties[property_name] = [] changes += self.hydrate_object( find.value.properties[property_name], property_value) elif source_dto.type is ObjectRaw.Types.array: changes += self.hydrate_object(find.value.items, source_object.items) elif source_dto.type is ObjectRaw.Types.dynamic: changes += self.hydrate_object(find.value.items, source_object.items) elif source_dto.type is ObjectRaw.Types.enum: changes += self.hydrate_list(find.value.values, source_object.values) changes += self.hydrate_list(find.value.descriptions, source_object.descriptions) return changes