コード例 #1
0
ファイル: test_rootDto.py プロジェクト: bahamut1221/apidoc
    def test_hydrate_object(self):

        version1 = Version()
        version1.name = "v1"
        version2 = Version()
        version2.name = "v2"

        versions = {"v1": version1, "v2": version2}

        object_dto = []

        object1 = ObjectObject()
        object2 = ObjectObject()
        object3 = ObjectObject()
        object1.name = "a"
        object2.name = "a"
        object3.name = "b"
        array = ObjectArray()
        array.name = "b"
        dynamic = ObjectDynamic()
        dynamic.name = "c"
        string = ObjectString()
        string.name = "d"
        type = ObjectType()
        type.name = "e"
        type.type_object = "f"
        const = ObjectConst()
        const.value = "g"
        enum = ObjectEnum()
        enum.name = "h"
        enum.values = ["h"]

        object1.properties = {"p1": array, "p3": const, "p4": enum}
        object2.properties = {"p1": array, "p3": const, "p4": enum, "p2": type}
        array.items = dynamic
        dynamic.items = string

        response = Hydrator(version1, versions, []).hydrate_object(object_dto, object1)
        response = Hydrator(version2, versions, []).hydrate_object(object_dto, object2)
        response = Hydrator(version1, versions, []).hydrate_object(object_dto, object3)

        self.assertEqual(1, response)
        self.assertEqual(2, len(object_dto))
        self.assertIn(version1.name, object_dto[0].versions)
        self.assertIn(version1.name, object_dto[0].versions)
        self.assertNotIn(version2.name, object_dto[1].versions)
        self.assertEqual("a", object_dto[0].value.name)
        self.assertEqual("b", object_dto[0].value.properties["p1"][0].value.name)
        self.assertEqual("c", object_dto[0].value.properties["p1"][0].value.items[0].value.name)
        self.assertEqual("d", object_dto[0].value.properties["p1"][0].value.items[0].value.items[0].value.name)
        self.assertEqual("e", object_dto[0].value.properties["p2"][0].value.name)
        self.assertEqual("f", object_dto[0].value.properties["p2"][0].value.type_object)
        self.assertEqual("g", object_dto[0].value.properties["p3"][0].value.value)
        self.assertEqual("h", object_dto[0].value.properties["p4"][0].value.values[0].value)
コード例 #2
0
    def test_get_used_types_in_object__additional_properties(self):
        object = ObjectObject()
        array = ObjectArray()
        dynamic = ObjectDynamic()
        reference = ObjectType()
        reference.type_name = "t1"

        object.additional_properties = array
        array.items = dynamic
        dynamic.items = reference

        response = self.source.get_used_types_in_object(object)

        self.assertEqual(["t1"], response)
コード例 #3
0
    def test_replace_types_in_object__unknwon(self):
        object = ObjectObject()
        array = ObjectArray()
        dynamic = ObjectDynamic()
        reference = ObjectType()
        reference.type_name = "t2"

        type1 = Type()

        object.properties = {"p1": array}
        array.items = dynamic
        dynamic.items = reference

        with self.assertRaises(ValueError):
            self.source.replace_types_in_object(object, {"t1": type1})
コード例 #4
0
    def test_objectDynamic(self):
        object = ObjectDynamic()
        object.name = "a"
        object.type = Object.Types.dynamic

        object2 = ObjectDynamic()
        object2.name = "b"
        object2.type = Object.Types.dynamic

        object.items = object2

        object_sample = ObjectDynamicSample(object)

        self.assertEqual("a", object_sample.name)
        self.assertIsInstance(object_sample.items, ObjectDynamicSample)
コード例 #5
0
    def test_objectDynamic(self):
        object = ObjectDynamic()
        object.name = "a"
        object.type = Object.Types.dynamic

        object2 = ObjectDynamic()
        object2.name = "b"
        object2.type = Object.Types.dynamic

        object.items = object2

        object_sample = ObjectDynamicSample(object)

        self.assertEqual("a", object_sample.name)
        self.assertIsInstance(object_sample.items, ObjectDynamicSample)
コード例 #6
0
    def test_replace_types_in_object__additional_properties(self):
        object = ObjectObject()
        array = ObjectArray()
        dynamic = ObjectDynamic()
        reference = ObjectType()
        reference.type_name = "t1"

        type1 = Type()

        object.additional_properties = array
        array.items = dynamic
        dynamic.items = reference

        self.source.replace_types_in_object(object, {"t1": type1})

        self.assertEqual(type1, reference.type_object)
コード例 #7
0
    def test_replace_references_in_object__additional_properties(self):
        object = ObjectObject()
        array = ObjectArray()
        dynamic = ObjectDynamic()
        reference = ObjectReference()
        reference.reference_name = "r1"

        string1 = ObjectString()

        object.additional_properties = array
        array.items = dynamic
        dynamic.items = reference

        self.source.replace_references_in_object(object, {"r1": string1})

        self.assertEqual(Object.Types.string, dynamic.items.type)
コード例 #8
0
ファイル: test_rootDto.py プロジェクト: bismark1221/apidoc
    def test_hydrate_object(self):

        version1 = Version()
        version1.name = "v1"
        version2 = Version()
        version2.name = "v2"

        versions = {"v1": version1, "v2": version2}

        object_dto = []

        object1 = ObjectObject()
        object2 = ObjectObject()
        object3 = ObjectObject()
        object1.name = "a"
        object2.name = "a"
        object3.name = "b"
        array = ObjectArray()
        array.name = "b"
        dynamic = ObjectDynamic()
        dynamic.name = "c"
        string = ObjectString()
        string.name = "d"
        type = ObjectType()
        type.name = "e"
        type.type_object = "f"
        const = ObjectConst()
        const.value = "g"
        enum = ObjectEnum()
        enum.name = "h"
        enum.values = ["h"]

        object1.properties = {"p1": array, "p3": const, "p4": enum}
        object2.properties = {"p1": array, "p3": const, "p4": enum, "p2": type}
        array.items = dynamic
        dynamic.items = string

        response = Hydrator(version1, versions,
                            []).hydrate_object(object_dto, object1)
        response = Hydrator(version2, versions,
                            []).hydrate_object(object_dto, object2)
        response = Hydrator(version1, versions,
                            []).hydrate_object(object_dto, object3)

        self.assertEqual(1, response)
        self.assertEqual(2, len(object_dto))
        self.assertIn(version1.name, object_dto[0].versions)
        self.assertIn(version1.name, object_dto[0].versions)
        self.assertNotIn(version2.name, object_dto[1].versions)
        self.assertEqual("a", object_dto[0].value.name)
        self.assertEqual("b",
                         object_dto[0].value.properties["p1"][0].value.name)
        self.assertEqual(
            "c",
            object_dto[0].value.properties["p1"][0].value.items[0].value.name)
        self.assertEqual(
            "d", object_dto[0].value.properties["p1"]
            [0].value.items[0].value.items[0].value.name)
        self.assertEqual("e",
                         object_dto[0].value.properties["p2"][0].value.name)
        self.assertEqual(
            "f", object_dto[0].value.properties["p2"][0].value.type_object)
        self.assertEqual("g",
                         object_dto[0].value.properties["p3"][0].value.value)
        self.assertEqual(
            "h", object_dto[0].value.properties["p4"][0].value.values[0].value)