コード例 #1
0
ファイル: test_rootDto.py プロジェクト: bahamut1221/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))
コード例 #2
0
    def test_get_uri_with_missing_parameters(self):
        root = Root()
        version = Version()
        version.name = "v"
        method = Method()
        method.name = "m"
        method.category = "a"
        method.full_uri = "/{foo}/{p}"

        parameter = Parameter()
        parameter.name = "p"
        parameter.type = "string"
        method.request_parameters = {"p": parameter}

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

        root_dto = RootDto()

        hydrator = Hydrator(version, {"v": version}, [])
        hydrator.hydrate_method(root_dto, root, method)

        parameters = self.source.validate(root_dto)
        parameters = self.source.get_uri_with_missing_parameters(root_dto)

        self.assertEqual([
            {
                "name": "foo",
                "uri": "/{foo}/{p}",
                "method": "m",
                "version": "v"
            },
        ], parameters)
コード例 #3
0
ファイル: test_source.py プロジェクト: MartinThoma/apidoc
    def test_get_uri_with_missing_parameters(self):
        root = Root()
        version = Version()
        version.name = "v"
        method = Method()
        method.name = "m"
        method.category = "a"
        method.full_uri = "/{foo}/{p}"

        parameter = Parameter()
        parameter.name = "p"
        parameter.type = "string"
        method.request_parameters = {"p": parameter}

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

        root_dto = RootDto()

        hydrator = Hydrator(version, {"v": version}, [])
        hydrator.hydrate_method(root_dto, root, method)

        parameters = self.source.validate(root_dto)
        parameters = self.source.get_uri_with_missing_parameters(root_dto)

        self.assertEqual([
            {"name": "foo", "uri": "/{foo}/{p}", "method": "m", "version": "v"},
        ], parameters)
コード例 #4
0
ファイル: test_rootDto.py プロジェクト: bahamut1221/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"])
コード例 #5
0
ファイル: root.py プロジェクト: lampard1010/mock
    def create_from_dictionary(self, datas):
        """Return a populated Object Root from dictionnary datas
        """
        root = ObjectRoot()

        if "configuration" in datas and datas["configuration"] is not None:
            root.configuration = self.configuration_factory.create_from_dictionary(
                datas["configuration"])

        if "categories" in datas and datas["categories"] is not None:
            root.categories = self.category_factory.create_dictionary_of_element_from_dictionary(
                "categories", datas)

        root.versions = self.version_factory.create_dictionary_of_element_from_dictionary(
            "versions", datas)

        for version in root.versions.values():
            version.full_uri = "%s%s" % (root.configuration.uri
                                         or "", version.uri or "")
            for method in version.methods.values():
                method.absolute_uri = "%s%s" % (version.uri or "", method.uri
                                                or "")
                method.full_uri = "%s%s" % (version.full_uri or "", method.uri
                                            or "")

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

        root = Root()
        version = Version()
        version.name = "v"
        method = Method()
        method.category = "a"
        method.full_uri = "/{p}/"

        parameter = Parameter()
        parameter.name = "p"
        parameter.type = "string"
        method.request_parameters = {"p": parameter}

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

        root_dto = RootDto()

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

        hydrator.hydrate_method(root_dto, root, method)

        self.assertEqual(1, len(root_dto.method_categories))
        self.assertEqual(0, len(root_dto.type_categories))
        self.assertEqual(1, len(root_dto.method_categories[0].methods))
        self.assertEqual(1, len(root_dto.method_categories[0].methods[0].request_parameters))
        self.assertIsInstance(root_dto.method_categories[0].methods[0].request_parameters[0].value, RequestParameter)
        self.assertEqual(1, root_dto.method_categories[0].methods[0].request_parameters[0].value.position)
コード例 #7
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)
コード例 #8
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"])
コード例 #9
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)
コード例 #10
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)
コード例 #11
0
ファイル: test_rootDto.py プロジェクト: bismark1221/apidoc
    def test_hydrate_method_changed(self):

        root = Root()
        version1 = Version()
        version1.name = "v1"
        version2 = Version()
        version2.name = "v2"
        method1 = Method()
        method1.name = "m1"
        method1.description = "b"
        method2 = Method()
        method2.name = "m1"
        method2.description = "c"

        root.versions = {"v1": version1, "v2": version2}
        version1.methods = {"m1": method1}
        version2.methods = {"m1": method2}

        root_dto = RootDto()

        Hydrator(version1, root.versions,
                 []).hydrate_method(root_dto, root, method1)
        Hydrator(version2, root.versions,
                 []).hydrate_method(root_dto, root, method2)

        self.assertEqual(1, len(root_dto.method_categories))
        self.assertEqual(1, len(root_dto.method_categories[0].methods))
        self.assertEqual(
            2, len(root_dto.method_categories[0].methods[0].description))
        self.assertEqual(
            MultiVersion.Changes.updated,
            root_dto.method_categories[0].methods[0].changes_status["v2"])
コード例 #12
0
    def test_remove_hidden_elements(self):
        root = Root()
        version1 = Version()
        version2 = Version()
        category1 = Category("c1")
        category2 = Category("c2")
        method1 = Method()
        method2 = Method()

        root.versions = {"v1": version1, "v2": version2}
        root.categories = {"c1": category1, "c2": category2}

        version1.methods = {"m1": method1, "m2": method2}
        version2.methods = {"m1": method1, "m2": method2}

        method1.category = "c1"
        method2.category = "c2"

        version1.display = False
        category2.display = False

        self.source.remove_hidden_elements(root)

        self.assertEqual(1, len(root.versions))
        self.assertEqual(version2, root.versions["v2"])
        self.assertEqual(1, len(root.versions["v2"].methods))
        self.assertEqual(method1, root.versions["v2"].methods["m1"])
コード例 #13
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))
コード例 #14
0
ファイル: test_rootDto.py プロジェクト: bahamut1221/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)
コード例 #15
0
ファイル: test_rootDto.py プロジェクト: bahamut1221/apidoc
    def test_hydrate_method_changed(self):

        root = Root()
        version1 = Version()
        version1.name = "v1"
        version2 = Version()
        version2.name = "v2"
        method1 = Method()
        method1.name = "m1"
        method1.description = "b"
        method2 = Method()
        method2.name = "m1"
        method2.description = "c"

        root.versions = {"v1": version1, "v2": version2}
        version1.methods = {"m1": method1}
        version2.methods = {"m1": method2}

        root_dto = RootDto()

        Hydrator(version1, root.versions, []).hydrate_method(root_dto, root, method1)
        Hydrator(version2, root.versions, []).hydrate_method(root_dto, root, method2)

        self.assertEqual(1, len(root_dto.method_categories))
        self.assertEqual(1, len(root_dto.method_categories[0].methods))
        self.assertEqual(2, len(root_dto.method_categories[0].methods[0].description))
        self.assertEqual(MultiVersion.Changes.updated, root_dto.method_categories[0].methods[0].changes_status["v2"])
コード例 #16
0
    def test_hide_filtered_elements__category_exclude(self):
        root = Root()

        category1 = Category("c1")
        category2 = Category("c2")
        category3 = Category("c3")

        root.categories = {"c1": category1, "c2": category2, "c3": category3}

        config = ConfigObject()
        config["filter"]["categories"]["excludes"] = ["c1", "c3"]
        self.source.hide_filtered_elements(root, config["filter"])

        self.assertFalse(category1.display)
        self.assertTrue(category2.display)
        self.assertFalse(category3.display)
コード例 #17
0
    def test_hide_filtered_elements__version(self):
        root = Root()
        version1 = Version()
        version2 = Version()
        version3 = Version()
        version1.name = "v1"
        version2.name = "v2"
        version3.name = "v3"

        root.versions = {"v1": version1, "v2": version2, "v3": version3}

        config = ConfigObject()
        self.source.hide_filtered_elements(root, config["filter"])

        self.assertTrue(version1.display)
        self.assertTrue(version2.display)
        self.assertTrue(version3.display)
コード例 #18
0
    def test_add_missing_categories(self):
        root = Root()
        version1 = Version()
        category1 = Category("c1")
        method1 = Method()
        method2 = Method()

        root.versions = {"v1": version1}
        root.categories = {"c1": category1}

        version1.methods = {"m1": method1, "m2": method2}

        method1.category = "c1"
        method2.category = "c2"

        self.source.add_missing_categories(root)

        self.assertEqual(2, len(root.categories))
        self.assertIsInstance(root.categories["c2"], Category)
コード例 #19
0
    def test_hide_filtered_elements__category_include(self):
        root = Root()

        category1 = Category("c")
        category2 = Category("c")
        category3 = Category("c")
        category1.name = "v1"
        category2.name = "v2"
        category3.name = "v3"

        root.categories = {"s1": category1, "s2": category2, "s3": category3}

        config = ConfigObject()
        config["filter"]["categories"]["includes"] = ["v1", "v3"]
        self.source.hide_filtered_elements(root, config["filter"])

        self.assertTrue(category1.display)
        self.assertFalse(category2.display)
        self.assertTrue(category3.display)
コード例 #20
0
    def test_hide_filtered_elements__category(self):
        root = Root()
        version1 = Version()

        category1 = Category("c")
        category2 = Category("c")
        category3 = Category("c")
        category1.name = "v1"
        category2.name = "v2"
        category3.name = "v3"

        root.versions = {"v1": version1}
        version1.categories = {"s1": category1, "s2": category2, "s3": category3}

        config = ConfigObject()
        self.source.hide_filtered_elements(root, config["filter"])

        self.assertTrue(category1.display)
        self.assertTrue(category2.display)
        self.assertTrue(category3.display)
コード例 #21
0
ファイル: root.py プロジェクト: MartinThoma/apidoc
    def create_from_dictionary(self, datas):
        """Return a populated Object Root from dictionnary datas
        """
        root = ObjectRoot()

        if "configuration" in datas and datas["configuration"] is not None:
            root.configuration = self.configuration_factory.create_from_dictionary(datas["configuration"])

        if "categories" in datas and datas["categories"] is not None:
            root.categories = self.category_factory.create_dictionary_of_element_from_dictionary("categories", datas)

        root.versions = self.version_factory.create_dictionary_of_element_from_dictionary("versions", datas)

        for version in root.versions.values():
            version.full_uri = "%s%s" % (root.configuration.uri or "", version.uri or "")
            for method in version.methods.values():
                method.absolute_uri = "%s%s" % (version.uri or "", method.uri or "")
                method.full_uri = "%s%s" % (version.full_uri or "", method.uri or "")

        return root
コード例 #22
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))
コード例 #23
0
ファイル: test_rootDto.py プロジェクト: bahamut1221/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))
コード例 #24
0
ファイル: test_rootDto.py プロジェクト: bismark1221/apidoc
    def test_hydrate_method__with_multiple_methds(self):

        root = Root()
        version = Version()
        version.name = "v"
        method1 = Method()
        method1.category = "c"
        method2 = Method()
        method2.category = "c"

        root.versions = {"v": version}
        version.methods = {"m1": method1, "m2": method2}
        version.types = {"m": type}

        root_dto = RootDto()

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

        hydrator.hydrate_method(root_dto, root, method1)
        hydrator.hydrate_method(root_dto, root, method2)

        self.assertEqual(1, len(root_dto.method_categories))
コード例 #25
0
ファイル: test_rootDto.py プロジェクト: bahamut1221/apidoc
    def test_hydrate_method__with_multiple_methds(self):

        root = Root()
        version = Version()
        version.name = "v"
        method1 = Method()
        method1.category = "c"
        method2 = Method()
        method2.category = "c"

        root.versions = {"v": version}
        version.methods = {"m1": method1, "m2": method2}
        version.types = {"m": type}

        root_dto = RootDto()

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

        hydrator.hydrate_method(root_dto, root, method1)
        hydrator.hydrate_method(root_dto, root, method2)

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

        root = Root()
        version = Version()
        version.name = "v"
        method = Method()
        method.category = "a"
        method.full_uri = "/{p}/"

        parameter = Parameter()
        parameter.name = "p"
        parameter.type = "string"
        method.request_parameters = {"p": parameter}

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

        root_dto = RootDto()

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

        hydrator.hydrate_method(root_dto, root, method)

        self.assertEqual(1, len(root_dto.method_categories))
        self.assertEqual(0, len(root_dto.type_categories))
        self.assertEqual(1, len(root_dto.method_categories[0].methods))
        self.assertEqual(
            1,
            len(root_dto.method_categories[0].methods[0].request_parameters))
        self.assertIsInstance(
            root_dto.method_categories[0].methods[0].request_parameters[0].
            value, RequestParameter)
        self.assertEqual(
            1, root_dto.method_categories[0].methods[0].request_parameters[0].
            value.position)
コード例 #28
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))
コード例 #29
0
ファイル: test_rootDto.py プロジェクト: bahamut1221/apidoc
    def test_hydrate_method__with_known_category(self):

        root = Root()
        version = Version()
        version.name = "v"
        method = Method()
        method.category = "c"

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

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

        root.categories = {"c": category}

        root_dto = RootDto()

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

        hydrator.hydrate_method(root_dto, root, method)

        self.assertEqual("d", root_dto.method_categories[0].description)
コード例 #30
0
ファイル: test_rootDto.py プロジェクト: bismark1221/apidoc
    def test_hydrate_method__with_known_category(self):

        root = Root()
        version = Version()
        version.name = "v"
        method = Method()
        method.category = "c"

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

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

        root.categories = {"c": category}

        root_dto = RootDto()

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

        hydrator.hydrate_method(root_dto, root, method)

        self.assertEqual("d", root_dto.method_categories[0].description)
コード例 #31
0
ファイル: test_rootDto.py プロジェクト: bahamut1221/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))