Esempio n. 1
0
    def test_object_compare__with_name(self):
        object1 = ObjectDto(Object())
        object2 = ObjectDto(Object())

        object1.name = "a"
        object2.name = "b"

        self.assertEqual(object1, sorted([object2, object1])[0])
Esempio n. 2
0
    def test_object_compare__with_name(self):
        object1 = ObjectDto(Object())
        object2 = ObjectDto(Object())

        object1.name = "a"
        object2.name = "b"

        self.assertEqual(object1, sorted([object2, object1])[0])
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
    def test_object_compare__with_optional(self):
        object1 = ObjectDto(Object())
        object2 = ObjectDto(Object())

        object1.name = "a"
        object1.description = "a"
        object1.type = Object.Types.bool
        object1.optional = False
        object2.name = "a"
        object2.description = "a"
        object2.type = Object.Types.bool
        object2.optional = True

        self.assertEqual(object1, sorted([object2, object1])[0])
Esempio n. 6
0
    def test_object_compare__with_optional(self):
        object1 = ObjectDto(Object())
        object2 = ObjectDto(Object())

        object1.name = "a"
        object1.description = "a"
        object1.type = Object.Types.bool
        object1.optional = False
        object2.name = "a"
        object2.description = "a"
        object2.type = Object.Types.bool
        object2.optional = True

        self.assertEqual(object1, sorted([object2, object1])[0])
Esempio n. 7
0
    def test_object_compare__with_type(self):
        object1 = ObjectDto(Object())
        object2 = ObjectDto(Object())

        object1.name = "a"
        object1.description = "a"
        object1.type = Object.Types.bool
        object2.name = "a"
        object2.description = "a"
        object2.type = Object.Types.string

        self.assertEqual(object1, sorted([object2, object1])[0])
Esempio n. 8
0
    def test_object_compare__with_type(self):
        object1 = ObjectDto(Object())
        object2 = ObjectDto(Object())

        object1.name = "a"
        object1.description = "a"
        object1.type = Object.Types.bool
        object2.name = "a"
        object2.description = "a"
        object2.type = Object.Types.string

        self.assertEqual(object1, sorted([object2, object1])[0])
Esempio n. 9
0
    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
Esempio n. 10
0
    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