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

        root = Root()
        version1 = Version()
        version1.name = "v1"
        version2 = Version()
        version2.name = "v2"
        type1 = Type()
        type1.name = "m1"
        type1.description = "b"
        type1.item = ObjectString()
        type2 = Type()
        type2.name = "m1"
        type2.description = "c"
        type2.item = ObjectString()

        root.versions = {"v1": version1, "v2": version2}
        version1.types = {"m1": type1}
        version2.types = {"m1": type2}

        root_dto = RootDto()

        Hydrator(version1, root.versions,
                 []).hydrate_type(root_dto, root, type1)
        Hydrator(version2, root.versions,
                 []).hydrate_type(root_dto, root, type2)

        self.assertEqual(1, len(root_dto.type_categories))
        self.assertEqual(1, len(root_dto.type_categories[0].types))
        self.assertEqual(2,
                         len(root_dto.type_categories[0].types[0].description))
        self.assertEqual(
            MultiVersion.Changes.updated,
            root_dto.type_categories[0].types[0].changes_status["v2"])
コード例 #2
0
    def test_type_compare__with_name(self):
        type1 = TypeDto(Type())
        type2 = TypeDto(Type())

        type1.name = "a"
        type2.name = "b"

        self.assertEqual(type1, sorted([type2, type1])[0])
コード例 #3
0
ファイル: test_rootDto.py プロジェクト: bismark1221/apidoc
    def test_hydrate_type__with_known_category(self):

        root = Root()
        version = Version()
        version.name = "v"
        type = Type()
        type.category = "c"
        type.item = ObjectString()

        root.versions = {"v": version}
        version.types = {"m": type}
        version.types = {"m": type}

        category = Category("c")
        category.description = "d"

        root.categories = {"c": category}

        root_dto = RootDto()

        hydrator = Hydrator(version, {"v": version}, [])

        hydrator.hydrate_type(root_dto, root, type)

        self.assertEqual("d", root_dto.type_categories[0].description)
コード例 #4
0
ファイル: test_rootDto.py プロジェクト: bismark1221/apidoc
    def test_create_from_root(self):
        root = Root()
        version = Version()
        version.name = "v"
        method = Method()
        method.category = "a"
        type = Type()
        type.category = "b"
        type.item = ObjectString()

        root.versions = {"v": version}
        version.methods = {"m": method}
        version.types = {"m": type}

        response = self.factory.create_from_root(root)

        self.assertIsInstance(response, RootDto)

        self.assertEqual(1, len(response.method_categories))
        self.assertEqual("a", response.method_categories[0].name)
        self.assertEqual(1, len(response.method_categories[0].methods))

        self.assertEqual(1, len(response.type_categories))
        self.assertEqual("b", response.type_categories[0].name)
        self.assertEqual(1, len(response.type_categories[0].types))
コード例 #5
0
    def test_replace_type(self):
        root = Root()

        version1 = Version()

        method1 = Method()

        object_type1 = ObjectType()
        object_type1.type_name = "t1"

        type1 = Type()

        parameter1 = Parameter()
        parameter1.type = "t1"

        parameter2 = Parameter()
        parameter2.type = "t1"

        method1.request_body = object_type1
        method1.request_parameters = {"p1": parameter1}
        method1.request_headers = {"p1": parameter2}

        version1.types = {"t1": type1}
        version1.methods = {"m1": method1}

        root.versions = {"v1": version1}

        self.source.replace_types(root)

        self.assertEqual(type1, method1.request_body.type_object)
        self.assertEqual(type1, method1.request_parameters["p1"].type_object)
        self.assertEqual(type1, method1.request_headers["p1"].type_object)
コード例 #6
0
    def test_replace_references(self):
        root = Root()

        version1 = Version()

        method1 = Method()
        type1 = Type()

        object_reference1 = ObjectReference()
        object_reference1.reference_name = "r1"
        object_reference1.name = "a"

        object_reference2 = ObjectReference()
        object_reference2.reference_name = "r1"
        object_reference2.name = "a"

        object1 = ObjectObject()
        object1.description = "b"

        method1.request_body = object_reference1
        type1.item = object_reference2

        version1.references = {"r1": object1}
        version1.methods = {"m1": method1}
        version1.types = {"t1": type1}

        root.versions = {"v1": version1}

        self.source.replace_references(root)

        self.assertEqual("a", method1.request_body.name)
        self.assertEqual("b", method1.request_body.description)
        self.assertEqual("a", type1.item.name)
        self.assertEqual("b", type1.item.description)
コード例 #7
0
    def test_objectType(self):
        object = ObjectType()
        object.name = "a"
        object.type = Object.Types.type
        object.type_object = Type()
        object.type_object.item = ObjectString()

        object_sample = ObjectTypeSample(object)

        self.assertEqual("a", object_sample.name)
コード例 #8
0
    def test_parameter_get_default_sample__for_type(self):
        test = Parameter()

        type = Type()
        type.item = ObjectString()
        type.item.name = "a"

        test.type = "b"
        test.type_object = type

        self.assertEqual("my_a", test.get_default_sample())
コード例 #9
0
    def test_type(self):
        type = Type()
        type.name = "a"
        type.format.pretty = "c"
        type.format.advanced = "d"

        type_sample = TypeSample(type)

        self.assertEqual("a", type_sample.name)
        self.assertEqual("my_a", type_sample.sample)
        self.assertEqual("c", type_sample.pretty)
        self.assertEqual("d", type_sample.advanced)
コード例 #10
0
    def test_remove_unused_types(self):
        root = Root()

        version1 = Version()

        type1 = Type()
        type2 = Type()

        method1 = Method()

        parameter1 = Parameter()
        parameter1.type = "t1"

        method1.request_parameters = {"p1": parameter1}

        version1.types = {"t1": type1, "t2": type2}
        version1.methods = {"m1": method1}

        root.versions = {"v1": version1}

        self.source.remove_unused_types(root)

        self.assertEqual({"t1": type1}, version1.types)
コード例 #11
0
ファイル: type.py プロジェクト: lampard1010/mock
    def create_from_name_and_dictionary(self, name, datas):
        """Return a populated object Type from dictionary datas
        """
        if "item" not in datas:
            raise ValueError("An item must be set in type \"%s\"." % name)

        type = ObjectType()
        self.set_common_datas(type, name, datas)

        type.item = self.object_factory.create_from_name_and_dictionary(type.name, datas["item"])

        if "category" in datas:
            type.category = str(datas["category"])
        else:
            type.category = None

        if "format" in datas and datas["format"] is not None:
            if "pretty" in datas["format"]:
                type.format.pretty = str(datas["format"]["pretty"])
            if "advanced" in datas["format"]:
                type.format.advanced = str(datas["format"]["advanced"])

        return type
コード例 #12
0
    def test_type(self):
        type = Type()
        type.name = "a"
        type.description = "b"

        type_dto = TypeDto(type)

        self.assertEqual("a", type_dto.name)
        self.assertEqual([], type_dto.description)
        self.assertIsInstance(type_dto.format, TypeFormatDto)

        self.assertEqual([], type_dto.item)
        self.assertEqual([], type_dto.versions)
        self.assertEqual({}, type_dto.changes_status)
        self.assertEqual({}, type_dto.samples)
コード例 #13
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})
コード例 #14
0
    def test_objecttype_get_default_sample(self):
        test = ObjectType()
        test.version = "v1"
        test.type_name = "baz"

        object = ObjectString()
        object.sample = "foo"

        type = Type()
        type.format = TypeFormat()
        type.item = object

        test.type_object = type

        self.assertEqual("foo", test.get_default_sample())
コード例 #15
0
ファイル: test_rootDto.py プロジェクト: bismark1221/apidoc
    def test_hydrate_type__with_multiple_methds(self):

        root = Root()
        version = Version()
        version.name = "v"
        type1 = Type()
        type1.category = "c"
        type1.item = ObjectString()
        type2 = Type()
        type2.category = "c"
        type2.item = ObjectString()

        root.versions = {"v": version}
        version.types = {"m1": type1, "m2": type2}
        version.types = {"m": type}

        root_dto = RootDto()

        hydrator = Hydrator(version, {"v": version}, [])

        hydrator.hydrate_type(root_dto, root, type1)
        hydrator.hydrate_type(root_dto, root, type2)

        self.assertEqual(1, len(root_dto.type_categories))
コード例 #16
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)
コード例 #17
0
ファイル: test_rootDto.py プロジェクト: bismark1221/apidoc
    def test_hydrate_type(self):

        root = Root()
        version = Version()
        version.name = "v"
        type = Type()
        type.category = "a"
        type.item = ObjectString()

        root.versions = {"v": version}
        version.types = {"m": type}

        root_dto = RootDto()

        hydrator = Hydrator(version, {"v": version}, [])

        hydrator.hydrate_type(root_dto, root, type)

        self.assertEqual(0, len(root_dto.method_categories))
        self.assertEqual(1, len(root_dto.type_categories))
        self.assertEqual(1, len(root_dto.type_categories[0].types))
コード例 #18
0
    def test_type_get_sample(self):
        type = Type()
        type.item = ObjectString()
        type.item.name = "a"

        self.assertEqual("my_a", type.get_sample())